import static java.util.Locale.ENGLISH;
import java.io.File;
-import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.spi.FileSystemProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.cms.CmsException;
import org.argeo.cms.i18n.LocaleUtils;
import org.argeo.node.NodeConstants;
import org.argeo.node.NodeState;
+import org.argeo.transaction.simple.SimpleTransactionManager;
import org.argeo.util.LangUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import bitronix.tm.TransactionManagerServices;
public class CmsState implements NodeState {
- private final Log log = LogFactory.getLog(CmsState.class);
+ private final static Log log = LogFactory.getLog(CmsState.class);
private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
// REFERENCES
private void initServices() {
// JTA
- initTransactionManager();
+ String tmType = KernelUtils.getFrameworkProp(NodeConstants.TRANSACTION_MANAGER,
+ NodeConstants.TRANSACTION_MANAGER_SIMPLE);
+ if (NodeConstants.TRANSACTION_MANAGER_SIMPLE.equals(tmType)) {
+ initSimpleTransactionManager();
+ } else if (NodeConstants.TRANSACTION_MANAGER_BITRONIX.equals(tmType)) {
+ initBitronixTransactionManager();
+ } else {
+ throw new CmsException("Usupported transaction manager type " + tmType);
+ }
+
+ // POI
+// POIXMLTypeLoader.setClassLoader(CTConnection.class.getClassLoader());
+
+ // Tika
+// OpenDocumentParser odfParser = new OpenDocumentParser();
+// bc.registerService(Parser.class, odfParser, new Hashtable());
+// PDFParser pdfParser = new PDFParser();
+// bc.registerService(Parser.class, pdfParser, new Hashtable());
+// OOXMLParser ooxmlParser = new OOXMLParser();
+// bc.registerService(Parser.class, ooxmlParser, new Hashtable());
+// TesseractOCRParser ocrParser = new TesseractOCRParser();
+// ocrParser.setLanguage("ara");
+// bc.registerService(Parser.class, ocrParser, new Hashtable());
// JCR
RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
// 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));
}
- private void initTransactionManager() {
+ private void initSimpleTransactionManager() {
+ SimpleTransactionManager transactionManager = new SimpleTransactionManager();
+ bc.registerService(TransactionManager.class, transactionManager, null);
+ bc.registerService(UserTransaction.class, transactionManager, null);
+ // 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 (kernelThread != null)
kernelThread.destroyAndJoin();
- applyStopHooks();
+ // In a different state in order to avois interruptions
+ new Thread(() -> applyStopHooks(), "Apply Argeo Stop Hooks").start();
+ // applyStopHooks();
long duration = ((System.currentTimeMillis() - availableSince) / 1000) / 60;
log.info("## ARGEO CMS STOPPED after " + (duration / 60) + "h " + (duration % 60) + "min uptime ##");