Skip to content

Commit

Permalink
Refactoring to split conf-core and conf-dicom, infinispan initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
romank-agfa committed May 28, 2015
1 parent 1433f50 commit b9bd91f
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 3 deletions.
21 changes: 21 additions & 0 deletions dcm4chee-conf-cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.dcm4che.conf.api
</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
Expand All @@ -65,9 +79,16 @@
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-conf-dicom</artifactId>
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,8 @@ public class DicomConfigurationExtenderEE {
@Inject
Instance<HL7ApplicationExtension> hl7ApplicationExtensions;

@Inject
Instance<Configuration> customConfigStorage;

@Produces
@ApplicationScoped
Expand All @@ -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());
}

}
};
Expand Down
6 changes: 6 additions & 0 deletions dcm4chee-conf-db/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-conf-dicom</artifactId>
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax</groupId>
Expand Down
97 changes: 97 additions & 0 deletions dcm4chee-conf-infinispan/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!--
~ ***** BEGIN LICENSE BLOCK *****
~ Version: MPL 1.1/GPL 2.0/LGPL 2.1
~
~ The contents of this file are subject to the Mozilla Public License Version
~ 1.1 (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~ http://www.mozilla.org/MPL/
~
~ Software distributed under the License is distributed on an "AS IS" basis,
~ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
~ for the specific language governing rights and limitations under the
~ License.
~
~ The Original Code is part of dcm4che, an implementation of DICOM(TM) in
~ Java(TM), hosted at https://github.com/gunterze/dcm4che.
~
~ The Initial Developer of the Original Code is
~ Agfa Healthcare.
~ Portions created by the Initial Developer are Copyright (C) 2014
~ the Initial Developer. All Rights Reserved.
~
~ Contributor(s):
~ See @authors listed below
~
~ Alternatively, the contents of this file may be used under the terms of
~ either the GNU General Public License Version 2 or later (the "GPL"), or
~ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
~ in which case the provisions of the GPL or the LGPL are applicable instead
~ of those above. If you wish to allow use of your version of this file only
~ under the terms of either the GPL or the LGPL, and not to allow others to
~ use your version of this file under the terms of the MPL, indicate your
~ decision by deleting the provisions above and replace them with the notice
~ and other provisions required by the GPL or the LGPL. If you do not delete
~ the provisions above, a recipient may use your version of this file under
~ the terms of any one of the MPL, the GPL or the LGPL.
~
~ ***** END LICENSE BLOCK *****
-->
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dcm4chee</groupId>
<artifactId>dcm4chee-conf-infinispan</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>org.dcm4che.dcm4chee-conf</groupId>
<artifactId>dcm4chee-conf-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>

<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-conf-core</artifactId>
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>

<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>5.1.2.FINAL</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.dcm4che.conf.core, org.infinispan </Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -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<String, Object> serializedDevicesCache;
private Cache<String, Object> metadataCache;

public CachedDicomConfigurationDecorator(Configuration delegate, Cache<String, Object> serializedDevicesCache, Cache<String, Object> metadataCache) {
super(delegate);
this.serializedDevicesCache = serializedDevicesCache;
this.metadataCache = metadataCache;
}

@Override
public Map<String, Object> getConfigurationRoot() throws ConfigurationException {

// if cache not inited
if (serializedDevicesCache.isEmpty()) {
Map<String, Object> configurationRoot = super.getConfigurationRoot();

Map<String, Object> dicomConfigurationRoot = (Map<String, Object>) configurationRoot.get("dicomConfigurationRoot");
Map<String, Object> dicomDevicesRoot = (Map<String, Object>) dicomConfigurationRoot.get("dicomDevicesRoot");

for (Map.Entry<String, Object> deviceEntry : dicomDevicesRoot.entrySet()) {
serializedDevicesCache.put(deviceEntry.getKey(), deviceEntry.getValue());
}

metadataCache.put("deviceNames", dicomDevicesRoot.keySet());

return configurationRoot;
}

// recreate full tree from cache
HashMap<String, Object> root = new HashMap<>();
HashMap<String, Object> configRoot = new HashMap<>();
HashMap<String, Object> devicesRoot = new HashMap<>();

root.put("dicomConfigurationRoot", configRoot);
configRoot.put("dicomDevicesRoot", devicesRoot);

Set<String> deviceNames = (Set<String>) 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<String, Object> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}

}
6 changes: 6 additions & 0 deletions dcm4chee-conf-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-conf-dicom</artifactId>
<version>${dcm4che.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public Map<String,Object> 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());
}

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<module>dcm4chee-conf-db</module>
<module>dcm4chee-conf-web</module>
<module>dcm4chee-conf-decorators</module>
<module>dcm4chee-conf-infinispan</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down

0 comments on commit b9bd91f

Please sign in to comment.