- bc.registerService(TransactionSynchronizationRegistry.class, transactionSynchronizationRegistry, null);
- if (log.isDebugEnabled())
- log.debug("Initialised default Bitronix transaction manager");
- }
-
- // private void initRepositoryFactory() {
- // // TODO rationalise RepositoryFactory
- // repositoryFactory = new NodeRepositoryFactory();
- // // register
- // bc.registerService(RepositoryFactory.class, repositoryFactory, null);
- // }
-
- // private void initUi() {
- // bc.registerService(ApplicationConfiguration.class, new MaintenanceUi(),
- // LangUtils.init(PROPERTY_CONTEXT_NAME, "system"));
- // bc.registerService(ApplicationConfiguration.class, new UserUi(),
- // LangUtils.init(PROPERTY_CONTEXT_NAME, "user"));
- // }
-
- private void initDeployConfigs(Dictionary<String, ?> stateProps) throws IOException {
- Path deployPath = KernelUtils.getOsgiInstancePath(KernelConstants.DIR_NODE + '/' + KernelConstants.DIR_DEPLOY);
- Files.createDirectories(deployPath);
-
- Path nodeConfigPath = deployPath.resolve(NodeConstants.NODE_REPO_PID + ".properties");
- if (!Files.exists(nodeConfigPath)) {
- Dictionary<String, Object> nodeConfig = getNodeConfig(stateProps);
- nodeConfig.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, ArgeoJcrConstants.ALIAS_NODE);
- nodeConfig.put(RepoConf.labeledUri.name(), nodeRepoUri.toString());
- LangUtils.storeAsProperties(nodeConfig, nodeConfigPath);
- }
-
- if (cleanState) {
- try (DirectoryStream<Path> ds = Files.newDirectoryStream(deployPath)) {
- for (Path path : ds) {
- if (Files.isDirectory(path)) {// managed factories
- try (DirectoryStream<Path> factoryDs = Files.newDirectoryStream(path)) {
- for (Path confPath : factoryDs) {
- Configuration conf = configurationAdmin
- .createFactoryConfiguration(path.getFileName().toString());
- Dictionary<String, Object> props = LangUtils.loadFromProperties(confPath);
- conf.update(props);
- }
- }
- } else {// managed services
- String pid = path.getFileName().toString();
- pid = pid.substring(0, pid.length() - ".properties".length());
- Configuration conf = configurationAdmin.getConfiguration(pid);
- Dictionary<String, Object> props = LangUtils.loadFromProperties(path);
- conf.update(props);
- }
- }
- }
- }
- }
-
- // private void initRepositories(Dictionary<String, ?> stateProps) throws
- // IOException {
- // // register
- // repositoryServiceFactory = new RepositoryServiceFactory();
- // bc.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
- // LangUtils.init(Constants.SERVICE_PID,
- // NodeConstants.JACKRABBIT_FACTORY_PID));
- //
- // repositoryService = new RepositoryService();
- // Dictionary<String, Object> regProps =
- // LangUtils.init(Constants.SERVICE_PID, NodeConstants.NODE_REPO_PID);
- // bc.registerService(LangUtils.names(ManagedService.class,
- // MetaTypeProvider.class), repositoryService, regProps);
- // }
-
- private void initWebServer() {
- String httpPort = getFrameworkProp("org.osgi.service.http.port");
- String httpsPort = getFrameworkProp("org.osgi.service.http.port.secure");
- /// TODO make it more generic
- String httpHost = getFrameworkProp("org.eclipse.equinox.http.jetty.http.host");
- try {
- if (httpPort != null || httpsPort != null) {
- final Hashtable<String, Object> jettyProps = new Hashtable<String, Object>();
- if (httpPort != null) {
- jettyProps.put(JettyConstants.HTTP_PORT, httpPort);
- jettyProps.put(JettyConstants.HTTP_ENABLED, true);
- }
- if (httpsPort != null) {
- jettyProps.put(JettyConstants.HTTPS_PORT, httpsPort);
- jettyProps.put(JettyConstants.HTTPS_ENABLED, true);
- jettyProps.put(JettyConstants.SSL_KEYSTORETYPE, "PKCS12");
- // jettyProps.put(JettyConstants.SSL_KEYSTORE,
- // nodeSecurity.getHttpServerKeyStore().getCanonicalPath());
- jettyProps.put(JettyConstants.SSL_PASSWORD, "changeit");
- jettyProps.put(JettyConstants.SSL_WANTCLIENTAUTH, true);
- }
- if(httpHost!=null){
- jettyProps.put(JettyConstants.HTTP_HOST, httpHost);
- }
- if (configurationAdmin != null) {
- // TODO make filter more generic
- String filter = "(" + JettyConstants.HTTP_PORT + "=" + httpPort + ")";
- if (configurationAdmin.listConfigurations(filter) != null)
- return;
- Configuration jettyConf = configurationAdmin
- .createFactoryConfiguration(KernelConstants.JETTY_FACTORY_PID, null);
- jettyConf.update(jettyProps);
-
- } else {
- JettyConfigurator.startServer("default", jettyProps);
- }
- }
- } catch (Exception e) {
- throw new CmsException("Cannot initialize web server on " + httpPortsMsg(httpPort, httpsPort), e);
- }
- }
-
- private void initNodeDeployment() throws IOException {
- Configuration nodeDeploymentConf = configurationAdmin.getConfiguration(NodeConstants.NODE_DEPLOYMENT_PID);
- nodeDeploymentConf.update(new Hashtable<>());
- }
+ // TODO TransactionSynchronizationRegistry
+ }
+
+// private void initBitronixTransactionManager() {
+// // TODO manage it in a managed service, as startup could be long
+// ServiceReference<TransactionManager> existingTm = bc.getServiceReference(TransactionManager.class);
+// if (existingTm != null) {
+// if (log.isDebugEnabled())
+// log.debug("Using provided transaction manager " + existingTm);
+// return;
+// }
+//
+// if (!TransactionManagerServices.isTransactionManagerRunning()) {
+// bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration();
+// tmConf.setServerId(UUID.randomUUID().toString());
+//
+// Bundle bitronixBundle = FrameworkUtil.getBundle(bitronix.tm.Configuration.class);
+// File tmBaseDir = bitronixBundle.getDataFile(KernelConstants.DIR_TRANSACTIONS);
+// File tmDir1 = new File(tmBaseDir, "btm1");
+// tmDir1.mkdirs();
+// tmConf.setLogPart1Filename(new File(tmDir1, tmDir1.getName() + ".tlog").getAbsolutePath());
+// File tmDir2 = new File(tmBaseDir, "btm2");
+// tmDir2.mkdirs();
+// tmConf.setLogPart2Filename(new File(tmDir2, tmDir2.getName() + ".tlog").getAbsolutePath());
+// }
+// BitronixTransactionManager transactionManager = getTransactionManager();
+// stopHooks.add(() -> transactionManager.shutdown());
+// BitronixTransactionSynchronizationRegistry transactionSynchronizationRegistry = getTransactionSynchronizationRegistry();
+// // register
+// bc.registerService(TransactionManager.class, transactionManager, null);
+// bc.registerService(UserTransaction.class, transactionManager, null);
+// bc.registerService(TransactionSynchronizationRegistry.class, transactionSynchronizationRegistry, null);
+// if (log.isDebugEnabled())
+// log.debug("Initialised default Bitronix transaction manager");
+// }