1 package org
.argeo
.cms
.jcr
.internal
.osgi
;
3 import java
.nio
.file
.spi
.FileSystemProvider
;
4 import java
.util
.ArrayList
;
5 import java
.util
.Dictionary
;
8 import javax
.jcr
.RepositoryFactory
;
10 import org
.argeo
.api
.NodeConstants
;
11 import org
.argeo
.cms
.jcr
.internal
.CmsFsProvider
;
12 import org
.argeo
.cms
.jcr
.internal
.StatisticsThread
;
13 import org
.argeo
.cms
.jcr
.internal
.NodeRepositoryFactory
;
14 import org
.argeo
.cms
.jcr
.internal
.RepositoryServiceFactory
;
15 import org
.argeo
.util
.LangUtils
;
16 import org
.osgi
.framework
.Bundle
;
17 import org
.osgi
.framework
.BundleActivator
;
18 import org
.osgi
.framework
.BundleContext
;
19 import org
.osgi
.framework
.Constants
;
20 import org
.osgi
.framework
.FrameworkUtil
;
21 import org
.osgi
.service
.cm
.ManagedServiceFactory
;
23 public class CmsJcrActivator
implements BundleActivator
{
24 private static BundleContext bundleContext
;
26 Bundle bundle
= FrameworkUtil
.getBundle(CmsJcrActivator
.class);
28 bundleContext
= bundle
.getBundleContext();
32 // private List<Runnable> stopHooks = new ArrayList<>();
33 private StatisticsThread kernelThread
;
35 private RepositoryServiceFactory repositoryServiceFactory
;
36 // private JcrDeployment jcrDeployment;
39 public void start(BundleContext context
) throws Exception
{
41 kernelThread
= new StatisticsThread("Kernel Thread");
42 kernelThread
.setContextClassLoader(getClass().getClassLoader());
46 repositoryServiceFactory
= new RepositoryServiceFactory();
47 // stopHooks.add(() -> repositoryServiceFactory.shutdown());
48 registerService(ManagedServiceFactory
.class, repositoryServiceFactory
,
49 LangUtils
.dict(Constants
.SERVICE_PID
, NodeConstants
.NODE_REPOS_FACTORY_PID
));
51 NodeRepositoryFactory repositoryFactory
= new NodeRepositoryFactory();
52 registerService(RepositoryFactory
.class, repositoryFactory
, null);
55 CmsFsProvider cmsFsProvider
= new CmsFsProvider();
56 // ServiceLoader<FileSystemProvider> fspSl = ServiceLoader.load(FileSystemProvider.class);
57 // for (FileSystemProvider fsp : fspSl) {
58 // log.debug("FileSystemProvider " + fsp);
59 // if (fsp instanceof CmsFsProvider) {
60 // cmsFsProvider = (CmsFsProvider) fsp;
63 // for (FileSystemProvider fsp : FileSystemProvider.installedProviders()) {
64 // log.debug("Installed FileSystemProvider " + fsp);
66 registerService(FileSystemProvider
.class, cmsFsProvider
,
67 LangUtils
.dict(Constants
.SERVICE_PID
, NodeConstants
.NODE_FS_PROVIDER_PID
));
69 // jcrDeployment = new JcrDeployment();
70 // jcrDeployment.init();
74 public void stop(BundleContext context
) throws Exception
{
75 // if (jcrDeployment != null)
76 // jcrDeployment.destroy();
78 if (repositoryServiceFactory
!= null)
79 repositoryServiceFactory
.shutdown();
81 if (kernelThread
!= null)
82 kernelThread
.destroyAndJoin();
87 public static <T
> void registerService(Class
<T
> clss
, T service
, Dictionary
<String
, ?
> properties
) {
88 if (bundleContext
!= null) {
89 bundleContext
.registerService(clss
, service
, properties
);
95 public static BundleContext
getBundleContext() {
100 public static <T
> T
getService(Class
<T
> clss
) {
101 if (bundleContext
!= null) {
102 return bundleContext
.getService(bundleContext
.getServiceReference(clss
));