From b9bd91f9b782bb9b0b35606aee3c616b3e1e62f3 Mon Sep 17 00:00:00 2001 From: romank-agfa Date: Thu, 28 May 2015 17:22:17 +0200 Subject: [PATCH] Refactoring to split conf-core and conf-dicom, infinispan initial commit --- dcm4chee-conf-cdi/pom.xml | 21 ++++ .../cdi/DicomConfigurationExtenderEE.java | 9 +- dcm4chee-conf-db/pom.xml | 6 ++ dcm4chee-conf-infinispan/pom.xml | 97 +++++++++++++++++ .../CachedDicomConfigurationDecorator.java | 102 ++++++++++++++++++ .../InfinispanConfigurationCacheFactory.java | 22 ++++ dcm4chee-conf-web/pom.xml | 6 ++ .../browser/ConfigRESTServicesServlet.java | 2 + pom.xml | 1 + 9 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 dcm4chee-conf-infinispan/pom.xml create mode 100644 dcm4chee-conf-infinispan/src/main/java/infinispan/CachedDicomConfigurationDecorator.java create mode 100644 dcm4chee-conf-infinispan/src/main/java/infinispan/InfinispanConfigurationCacheFactory.java diff --git a/dcm4chee-conf-cdi/pom.xml b/dcm4chee-conf-cdi/pom.xml index 84b0555..4d80395 100644 --- a/dcm4chee-conf-cdi/pom.xml +++ b/dcm4chee-conf-cdi/pom.xml @@ -57,6 +57,20 @@ true + + + maven-jar-plugin + 2.5 + + + + org.dcm4che.conf.api + + + + + + @@ -65,9 +79,16 @@ ${dcm4che.version} provided + + org.dcm4che + dcm4che-conf-dicom + ${dcm4che.version} + provided + javax javaee-api + \ No newline at end of file diff --git a/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java b/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java index cdbc25f..25c4d91 100644 --- a/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java +++ b/dcm4chee-conf-cdi/src/main/java/org/dcm4chee/conf/cdi/DicomConfigurationExtenderEE.java @@ -40,6 +40,7 @@ package org.dcm4chee.conf.cdi; import org.dcm4che3.conf.api.DicomConfigurationCustomizer; +import org.dcm4che3.conf.core.api.Configuration; import org.dcm4che3.conf.core.api.ConfigurationException; import org.dcm4che3.conf.dicom.DicomConfigurationBuilder; import org.dcm4che3.net.AEExtension; @@ -74,6 +75,8 @@ public class DicomConfigurationExtenderEE { @Inject Instance hl7ApplicationExtensions; + @Inject + Instance customConfigStorage; @Produces @ApplicationScoped @@ -90,9 +93,9 @@ public void customize(DicomConfigurationBuilder builder) { builder.registerHL7ApplicationExtension(ext.getClass()); - // TODO register DB storage if corresponding CDI bean is available - // TODO wrap the storage bean in Infinispan decorator when configured - // builder.registerCustomConfigurationStorage(); + if (!customConfigStorage.isUnsatisfied()) { + builder.registerCustomConfigurationStorage(customConfigStorage.get()); + } } }; diff --git a/dcm4chee-conf-db/pom.xml b/dcm4chee-conf-db/pom.xml index 5364b3a..5c21346 100644 --- a/dcm4chee-conf-db/pom.xml +++ b/dcm4chee-conf-db/pom.xml @@ -114,6 +114,12 @@ ${dcm4che.version} provided + + org.dcm4che + dcm4che-conf-dicom + ${dcm4che.version} + provided + javax diff --git a/dcm4chee-conf-infinispan/pom.xml b/dcm4chee-conf-infinispan/pom.xml new file mode 100644 index 0000000..f217056 --- /dev/null +++ b/dcm4chee-conf-infinispan/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + org.dcm4chee + dcm4chee-conf-infinispan + jar + + org.dcm4che.dcm4chee-conf + dcm4chee-conf-parent + 1.0.0-SNAPSHOT + + + + + org.dcm4che + dcm4che-conf-core + ${dcm4che.version} + provided + + + + javax + javaee-api + + + + org.infinispan + infinispan-core + 5.1.2.FINAL + + + + + + + src/main/resources + true + + + + + maven-jar-plugin + 2.5 + + + + org.dcm4che.conf.core, org.infinispan + + + + + + + + + \ No newline at end of file diff --git a/dcm4chee-conf-infinispan/src/main/java/infinispan/CachedDicomConfigurationDecorator.java b/dcm4chee-conf-infinispan/src/main/java/infinispan/CachedDicomConfigurationDecorator.java new file mode 100644 index 0000000..413fa29 --- /dev/null +++ b/dcm4chee-conf-infinispan/src/main/java/infinispan/CachedDicomConfigurationDecorator.java @@ -0,0 +1,102 @@ +package infinispan; + +import org.dcm4che3.conf.core.DelegatingConfiguration; +import org.dcm4che3.conf.core.api.Configuration; +import org.dcm4che3.conf.core.api.ConfigurationException; +import org.dcm4che3.conf.core.util.ConfigNodeUtil; +import org.infinispan.Cache; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +//TODO: convert to CDI decorator +public class CachedDicomConfigurationDecorator extends DelegatingConfiguration { + + + private static Logger log = LoggerFactory + .getLogger(CachedDicomConfigurationDecorator.class); + + + + private Cache serializedDevicesCache; + private Cache metadataCache; + + public CachedDicomConfigurationDecorator(Configuration delegate, Cache serializedDevicesCache, Cache metadataCache) { + super(delegate); + this.serializedDevicesCache = serializedDevicesCache; + this.metadataCache = metadataCache; + } + + @Override + public Map getConfigurationRoot() throws ConfigurationException { + + // if cache not inited + if (serializedDevicesCache.isEmpty()) { + Map configurationRoot = super.getConfigurationRoot(); + + Map dicomConfigurationRoot = (Map) configurationRoot.get("dicomConfigurationRoot"); + Map dicomDevicesRoot = (Map) dicomConfigurationRoot.get("dicomDevicesRoot"); + + for (Map.Entry deviceEntry : dicomDevicesRoot.entrySet()) { + serializedDevicesCache.put(deviceEntry.getKey(), deviceEntry.getValue()); + } + + metadataCache.put("deviceNames", dicomDevicesRoot.keySet()); + + return configurationRoot; + } + + // recreate full tree from cache + HashMap root = new HashMap<>(); + HashMap configRoot = new HashMap<>(); + HashMap devicesRoot = new HashMap<>(); + + root.put("dicomConfigurationRoot", configRoot); + configRoot.put("dicomDevicesRoot", devicesRoot); + + Set deviceNames = (Set) metadataCache.get("deviceNames"); + for (String name : deviceNames) { + devicesRoot.put(name, serializedDevicesCache.get(name)); + } + + return root; + } + + @Override + public Object getConfigurationNode(String path, Class configurableClass) throws ConfigurationException { + return ConfigNodeUtil.getNode(getConfigurationRoot(), path); + } + + + @Override + public boolean nodeExists(String path) throws ConfigurationException { + return false; + } + + @Override + public void persistNode(String path, Map configNode, Class configurableClass) throws ConfigurationException { + metadataCache.clear(); + serializedDevicesCache.clear(); + } + + @Override + public void refreshNode(String path) throws ConfigurationException { + metadataCache.clear(); + serializedDevicesCache.clear(); + } + + @Override + public void removeNode(String path) throws ConfigurationException { + metadataCache.clear(); + serializedDevicesCache.clear(); + } + + @Override + public synchronized Iterator search(String liteXPathExpression) throws IllegalArgumentException, ConfigurationException { + return ConfigNodeUtil.search(getConfigurationRoot(), liteXPathExpression); + } +} diff --git a/dcm4chee-conf-infinispan/src/main/java/infinispan/InfinispanConfigurationCacheFactory.java b/dcm4chee-conf-infinispan/src/main/java/infinispan/InfinispanConfigurationCacheFactory.java new file mode 100644 index 0000000..c77da0f --- /dev/null +++ b/dcm4chee-conf-infinispan/src/main/java/infinispan/InfinispanConfigurationCacheFactory.java @@ -0,0 +1,22 @@ +package infinispan; + +import org.infinispan.Cache; +import org.infinispan.manager.EmbeddedCacheManager; + +import javax.annotation.Resource; +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class InfinispanConfigurationCacheFactory { + + @Resource(lookup="java:jboss/infinispan/dcm4che-config") + private EmbeddedCacheManager defaultCacheManager; + + public Cache getDevicesCache() { + return defaultCacheManager.getCache(); + } + public Cache getMetadataCache() { + return defaultCacheManager.getCache("metadata"); + } + +} diff --git a/dcm4chee-conf-web/pom.xml b/dcm4chee-conf-web/pom.xml index 317b665..388426a 100644 --- a/dcm4chee-conf-web/pom.xml +++ b/dcm4chee-conf-web/pom.xml @@ -169,6 +169,12 @@ ${dcm4che.version} provided + + org.dcm4che + dcm4che-conf-dicom + ${dcm4che.version} + provided + javax diff --git a/dcm4chee-conf-web/src/main/java/org/dcm4chee/conf/browser/ConfigRESTServicesServlet.java b/dcm4chee-conf-web/src/main/java/org/dcm4chee/conf/browser/ConfigRESTServicesServlet.java index 4619bcb..3efad61 100644 --- a/dcm4chee-conf-web/src/main/java/org/dcm4chee/conf/browser/ConfigRESTServicesServlet.java +++ b/dcm4chee-conf-web/src/main/java/org/dcm4chee/conf/browser/ConfigRESTServicesServlet.java @@ -170,6 +170,8 @@ public Map getDeviceConfig(@PathParam(value = "deviceName") Strin @Path("/device/{deviceName}") @Produces(MediaType.APPLICATION_JSON) public void deleteDevice(@PathParam(value = "deviceName") String deviceName) throws ConfigurationException { + if (deviceName.isEmpty()) throw new ConfigurationException("Device name cannot be empty"); + configurationManager.getConfigurationStorage().removeNode(DicomPath.DeviceByName.set("deviceName",deviceName).path()); } diff --git a/pom.xml b/pom.xml index d8610bc..d0f9b35 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,7 @@ dcm4chee-conf-db dcm4chee-conf-web dcm4chee-conf-decorators + dcm4chee-conf-infinispan