Rename remote auth interfaces
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / CmsState.java
index 7ff650254b1149a45801e9623fed7e44c01645f6..219f2d53c059b58f4032ed11c22d3d9dc5c3812d 100644 (file)
@@ -4,31 +4,28 @@ import static java.util.Locale.ENGLISH;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.nio.file.spi.FileSystemProvider;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 
-import javax.jcr.RepositoryFactory;
-import javax.transaction.TransactionManager;
-import javax.transaction.UserTransaction;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.api.NodeConstants;
 import org.argeo.api.NodeState;
-import org.argeo.cms.CmsException;
 import org.argeo.cms.LocaleUtils;
-import org.argeo.transaction.simple.SimpleTransactionManager;
+import org.argeo.osgi.transaction.SimpleTransactionManager;
+import org.argeo.osgi.transaction.WorkControl;
+import org.argeo.osgi.transaction.WorkTransaction;
 import org.argeo.util.LangUtils;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkUtil;
 import org.osgi.service.cm.ManagedServiceFactory;
 
+/**
+ * Implementation of a {@link NodeState}, initialising the required services.
+ */
 public class CmsState implements NodeState {
        private final static Log log = LogFactory.getLog(CmsState.class);
-       private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
+//     private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
 
        // REFERENCES
        private Long availableSince;
@@ -38,7 +35,6 @@ public class CmsState implements NodeState {
        private List<Locale> locales = null;
 
        private ThreadGroup threadGroup = new ThreadGroup("CMS");
-       private KernelThread kernelThread;
        private List<Runnable> stopHooks = new ArrayList<>();
 
        private final String stateUuid;
@@ -64,10 +60,6 @@ public class CmsState implements NodeState {
                initI18n();
                initServices();
 
-               // kernel thread
-               kernelThread = new KernelThread(threadGroup, "Kernel Thread");
-               kernelThread.setContextClassLoader(getClass().getClassLoader());
-               kernelThread.start();
        }
 
        private void initI18n() {
@@ -88,7 +80,7 @@ public class CmsState implements NodeState {
                        throw new UnsupportedOperationException(
                                        "Bitronix is not supported anymore, but could be again if there is enough interest.");
                } else {
-                       throw new CmsException("Usupported transaction manager type " + tmType);
+                       throw new IllegalArgumentException("Usupported transaction manager type " + tmType);
                }
 
                // POI
@@ -105,41 +97,29 @@ public class CmsState implements NodeState {
 //             ocrParser.setLanguage("ara");
 //             bc.registerService(Parser.class, ocrParser, new Hashtable());
 
-               // JCR
-               RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
-               stopHooks.add(() -> repositoryServiceFactory.shutdown());
-               bc.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
-                               LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
-
-               NodeRepositoryFactory repositoryFactory = new NodeRepositoryFactory();
-               bc.registerService(RepositoryFactory.class, repositoryFactory, null);
+//             // JCR
+//             RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
+//             stopHooks.add(() -> repositoryServiceFactory.shutdown());
+//             Activator.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
+//                             LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
+//
+//             NodeRepositoryFactory repositoryFactory = new NodeRepositoryFactory();
+//             Activator.registerService(RepositoryFactory.class, repositoryFactory, null);
 
                // Security
                NodeUserAdmin userAdmin = new NodeUserAdmin(NodeConstants.ROLES_BASEDN, NodeConstants.TOKENS_BASEDN);
                stopHooks.add(() -> userAdmin.destroy());
-               bc.registerService(ManagedServiceFactory.class, userAdmin,
-                               LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_USER_ADMIN_PID));
-
-               // File System
-               CmsFsProvider cmsFsProvider = new CmsFsProvider();
-//             ServiceLoader<FileSystemProvider> fspSl = ServiceLoader.load(FileSystemProvider.class);
-//             for (FileSystemProvider fsp : fspSl) {
-//                     log.debug("FileSystemProvider " + fsp);
-//                     if (fsp instanceof CmsFsProvider) {
-//                             cmsFsProvider = (CmsFsProvider) fsp;
-//                     }
-//             }
-//             for (FileSystemProvider fsp : FileSystemProvider.installedProviders()) {
-//                     log.debug("Installed FileSystemProvider " + fsp);
-//             }
-               bc.registerService(FileSystemProvider.class, cmsFsProvider,
-                               LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_FS_PROVIDER_PID));
+               Activator.registerService(ManagedServiceFactory.class, userAdmin,
+                               LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_USER_ADMIN_PID));
+
        }
 
        private void initSimpleTransactionManager() {
                SimpleTransactionManager transactionManager = new SimpleTransactionManager();
-               bc.registerService(TransactionManager.class, transactionManager, null);
-               bc.registerService(UserTransaction.class, transactionManager, null);
+               Activator.registerService(WorkControl.class, transactionManager, null);
+               Activator.registerService(WorkTransaction.class, transactionManager, null);
+//             Activator.registerService(TransactionManager.class, transactionManager, null);
+//             Activator.registerService(UserTransaction.class, transactionManager, null);
                // TODO TransactionSynchronizationRegistry
        }
 
@@ -180,8 +160,6 @@ public class CmsState implements NodeState {
                if (log.isDebugEnabled())
                        log.debug("CMS stopping...  (" + this.stateUuid + ")");
 
-               if (kernelThread != null)
-                       kernelThread.destroyAndJoin();
                // In a different thread in order to avoid interruptions
                Thread stopHookThread = new Thread(() -> applyStopHooks(), "Apply Argeo Stop Hooks");
                stopHookThread.start();