From 53d713c0e33643bba2f1fc4ae879d221a8650eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20A=2E=20Bastia=CC=83o=20Silva?= Date: Sun, 27 Dec 2015 18:28:19 +0000 Subject: [PATCH 1/3] Removed not used code. --- .../pt/ua/dicoogle/server/RSIStorage.java | 72 ++----------------- 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java index b631c322b..180c9b0b5 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java @@ -232,87 +232,27 @@ protected void onCStoreRQ(Association as, int pcid, DicomObject rq, PDVInputStre { try { - /* - String cuid = rq.getString(Tag.AffectedSOPClassUID); - String iuid = rq.getString(Tag.AffectedSOPInstanceUID); - - DicomObject d = dataStream.readDataset(); - - System.out.println(d.get(Tag.TransferSyntaxUID)); - - String extraPath= getDirectory(d); - new File(extraPath).mkdirs(); - long time = System.currentTimeMillis(); - String fileStr = getFullPathCache(extraPath, d); - if (gzip) - { - fileStr += ".gz"; - } - - //first we write the file to a temporary location - BasicDicomObject fmi = new BasicDicomObject(); - fmi.initFileMetaInformation(cuid, iuid, tsuid); - - File file = new File(fileStr); - FileOutputStream fos = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(fos,fileBufferSize); - DicomOutputStream dos = null; - if (gzip) - { - dos = new DicomOutputStream(new GZIPOutputStream(bos)); - } - else - { - dos = new DicomOutputStream(bos); - } - - //dos.writeFileMetaInformation(fmi); - - d.initFileMetaInformation(cuid, iuid, tsuid); - dos.writeDicomFile(d); - //dataStream.copyTo(dos); - - - dos.close(); - - System.out.println(file.getAbsolutePath()); - - //core.indexQueue(file.getAbsolutePath(), true); - queue.add(file.getAbsolutePath()); - - */ String cuid = rq.getString(Tag.AffectedSOPClassUID); String iuid = rq.getString(Tag.AffectedSOPInstanceUID); - + DicomObject d = dataStream.readDataset(); d.initFileMetaInformation(cuid, iuid, tsuid); Iterable plugins = PluginController.getInstance().getStoragePlugins(true); - if(plugins == null){ - //System.out.println("There is no default plugin..."); - - //System.out.println("Number of StoragePlugins: "+PluginController.getInstance().getStorageInterfaces().size()); - - //System.out.println(PluginController.getInstance().getIndexingPlugins().size()); - } + URI uri = null; for (StorageInterface storage : plugins) { uri = storage.store(d); - if(uri != null) + if(uri != null) { + // queue to index queue.add(uri); + } } - - //System.out.println("Another successfull stored object xD"); - //System.out.println("URI: "+uri); - - //InputStream retrievedFile = plugin.retrieve(uri); - //byte[] byteArr = ByteStreams.toByteArray(retrievedFile); - + } catch (IOException e) { - //System.out.println(e.toString()); throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage()); } } From 1f4b11791edac571b2b983a221ee59e6f46b383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20A=2E=20Bastia=CC=83o=20Silva?= Date: Sun, 27 Dec 2015 21:44:27 +0000 Subject: [PATCH 2/3] Support handler to have Priority Queues in C-STORE. --- .../pt/ua/dicoogle/core/ServerSettings.java | 33 ++- .../java/pt/ua/dicoogle/core/XMLSupport.java | 206 ++++++++++-------- .../pt/ua/dicoogle/server/RSIStorage.java | 65 +++++- .../sdk/core/ServerSettingsReader.java | 3 + 4 files changed, 202 insertions(+), 105 deletions(-) diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/core/ServerSettings.java b/dicoogle/src/main/java/pt/ua/dicoogle/core/ServerSettings.java index 772837b55..d8660126f 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/core/ServerSettings.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/core/ServerSettings.java @@ -20,11 +20,7 @@ import pt.ua.dicoogle.sdk.datastructs.MoveDestination; import java.net.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.HashSet; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import org.dcm4che2.data.UID; import org.slf4j.LoggerFactory; @@ -171,6 +167,8 @@ public class ServerSettings implements ServerSettingsReader ArrayList dest = new ArrayList<>(); + private Set priorityAETitles = new HashSet<>(); + private boolean indexAnonymous = false; private boolean indexZIPFiles = true; @@ -890,6 +888,21 @@ public ArrayList getMoves() { return this.dest ; } + + @Override + public Set getPriorityAETitles() { + return priorityAETitles; + } + + public void addPriorityAETitle(String aet) + { + this.priorityAETitles.add(aet); + } + public void removePriorityAETitle(String aet) + { + this.priorityAETitles.remove(aet); + } + public void setMoves(ArrayList moves) { if(moves != null) @@ -950,8 +963,8 @@ public void setAutoStartPlugin(String name, boolean value) // remove the previous setting, if there is one autoStartPlugin.remove(name); - // insert the new setting - autoStartPlugin.put(name, value); + // insert the new setting + autoStartPlugin.put(name, value); } /** @@ -967,9 +980,9 @@ public boolean getAutoStartPlugin(String name) { Boolean result = autoStartPlugin.get(name); - // if there is not such setting return the default value - if (result == null) return true; // by default start the plugin - return result.booleanValue(); + // if there is not such setting return the default value + if (result == null) return true; // by default start the plugin + return result.booleanValue(); } /** diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/core/XMLSupport.java b/dicoogle/src/main/java/pt/ua/dicoogle/core/XMLSupport.java index 3be4e2492..ffcb76db7 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/core/XMLSupport.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/core/XMLSupport.java @@ -28,6 +28,7 @@ import pt.ua.dicoogle.sdk.datastructs.MoveDestination; +import pt.ua.dicoogle.sdk.settings.types.ServerDirectoryPath; import pt.ua.dicoogle.server.*; import java.io.*; @@ -130,6 +131,8 @@ public class XMLSupport extends DefaultHandler private String description; private String isPublic; + private boolean priorityAET = false; + private String currentService; @@ -366,6 +369,18 @@ else if (destinations && localName.equals("dest")) this.port, this.isPublic.contains("true"), this.description); s.add(tmp); } + + else if(localName.equals("CSTOREPriorities")) + { + this.priorityAET = true ; + } + else if (priorityAET && localName.equals("aetitle")) + { + String aet = this.resolveAttrib("aetitle", attribs, localName); + //ServerSettings.getInstance().addPriorityAETitle(aet); + } + + else if (localName.equals("web")) { this.isWeb = true ; @@ -615,6 +630,13 @@ else if (this.options && localName.equals("destinations")) this.destinations = false ; } + else if (this.options && localName.equals("CSTOREPriorities")) + { + this.priorityAET = false ; + } + + + else if (isWeb && localName.equals("web")) { this.isWeb = false ; @@ -632,25 +654,23 @@ else if(localName.equals("RGUIExtIP")) } @Override - public void characters( char[] data, int start, int length ) - { - if(isIndexEffort){ - String sEffort = new String(data, start, length); - s.setIndexerEffort(Integer.parseInt(sEffort)); - return; - } - if(isPort && !isQRConfigs) - { - String sPort = new String(data, start, length); - s.setStoragePort(Integer.parseInt(sPort)); - return; - } - if(isPort && isQRConfigs){ - String sPort = new String(data, start, length); - s.setWlsPort(Integer.parseInt(sPort)); - return; - } - if(isEncrypt){ + public void characters( char[] data, int start, int length ) { + if (isIndexEffort) { + String sEffort = new String(data, start, length); + s.setIndexerEffort(Integer.parseInt(sEffort)); + return; + } + if (isPort && !isQRConfigs) { + String sPort = new String(data, start, length); + s.setStoragePort(Integer.parseInt(sPort)); + return; + } + if (isPort && isQRConfigs) { + String sPort = new String(data, start, length); + s.setWlsPort(Integer.parseInt(sPort)); + return; + } + if (isEncrypt) { String sView = new String(data, start, length); boolean result = false; @@ -659,89 +679,84 @@ public void characters( char[] data, int start, int length ) s.setEncryptUsersFile(result); return; - } + } - - if (isZIPFile) - { - String sView = new String(data, start, length); - boolean result = false; - if (sView.compareToIgnoreCase("true") == 0) + + if (isZIPFile) { + String sView = new String(data, start, length); + boolean result = false; + if (sView.compareToIgnoreCase("true") == 0) result = true; - s.setIndexZIPFiles(result); - return; - } - - if (isGZIPStorage) - { - String sView = new String(data, start, length); - boolean result = false; - if (sView.compareToIgnoreCase("true") == 0) + s.setIndexZIPFiles(result); + return; + } + + if (isGZIPStorage) { + String sView = new String(data, start, length); + boolean result = false; + if (sView.compareToIgnoreCase("true") == 0) result = true; - s.setGzipStorage(result); - return; - - } - - if (isIndexAnonymous) - { - String sView = new String(data, start, length); - boolean result = false; - if (sView.compareToIgnoreCase("true") == 0) + s.setGzipStorage(result); + return; + + } + + if (isIndexAnonymous) { + String sView = new String(data, start, length); + boolean result = false; + if (sView.compareToIgnoreCase("true") == 0) result = true; - s.setIndexAnonymous(result); - return; - } - - if (isMonitorWatcher) - { - String sView = new String(data, start, length); - boolean result = false; - if (sView.compareToIgnoreCase("true") == 0) + s.setIndexAnonymous(result); + return; + } + + if (isMonitorWatcher) { + String sView = new String(data, start, length); + boolean result = false; + if (sView.compareToIgnoreCase("true") == 0) result = true; - s.setMonitorWatcher(result); - return; - } - if(isP2P) - { + s.setMonitorWatcher(result); + return; + } + if (isP2P) { - if (autoConnect) - { - String sView = new String(data, start, length); - boolean result = false; - if (sView.compareToIgnoreCase("true") == 0) + if (autoConnect) { + String sView = new String(data, start, length); + boolean result = false; + if (sView.compareToIgnoreCase("true") == 0) result = true; // s.setP2P(result); - return; + return; - } - else if (maxmsg) - { - String max = new String(data, start, length); + } else if (maxmsg) { + String max = new String(data, start, length); - int maxMsg = Integer.valueOf(max); - s.setMaxMessages(maxMsg); - return; + int maxMsg = Integer.valueOf(max); + s.setMaxMessages(maxMsg); + return; - } - else if (isNode && isNodeName) - { - String nodeName = new String(data, start, length); - s.setNodeName(nodeName); - } - else if (isNode && isDefined) - { - String tmp = new String(data, start, length); - boolean result = false; - if (tmp.compareToIgnoreCase("true") == 0) + } else if (isNode && isNodeName) { + String nodeName = new String(data, start, length); + s.setNodeName(nodeName); + } else if (isNode && isDefined) { + String tmp = new String(data, start, length); + boolean result = false; + if (tmp.compareToIgnoreCase("true") == 0) result = true; - s.setNodeNameDefined(result); - return; - } + s.setNodeNameDefined(result); + return; + } + } + if (priorityAET) + { + String aetitle = new String(data, start, length); + s.addPriorityAETitle(aetitle); + return; + + } - } if(isStorage) { String sView = new String(data, start, length); @@ -1569,6 +1584,23 @@ public void printXML() hd.endElement("", "", "destinations"); + // CSTOREPriorities + + hd.startElement("", "", "CSTOREPriorities", atts); + + for (String aet : ServerSettings.getInstance().getPriorityAETitles()) + { + atts.clear(); + hd.startElement("", "", "aetitle", atts); + hd.characters(aet.toCharArray(), 0, aet.length()); + hd.endElement("", "", "aetitle"); + } + + hd.endElement("", "", "CSTOREPriorities"); + + + + hd.endElement("", "", "options"); hd.endElement("", "", "QueryRetrieve"); diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java index 180c9b0b5..a1c5a7c2e 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java @@ -20,10 +20,11 @@ import pt.ua.dicoogle.core.ServerSettings; +import java.awt.*; import java.io.File; import java.io.IOException; import java.net.URI; -import java.util.Collection; +import java.util.*; import java.util.List; import java.util.concurrent.*; @@ -83,10 +84,11 @@ public class RSIStorage extends StorageService private ExecutorService pool = Executors.newFixedThreadPool(threadPoolSize); private boolean gzip = ServerSettings.getInstance().isGzipStorage();; - - - private BlockingQueue queue = new LinkedBlockingQueue(); + private Set priorityAETs = new HashSet<>(); + + // Changed to support priority queue. + private BlockingQueue queue = new PriorityBlockingQueue(); /** @@ -110,6 +112,10 @@ public RSIStorage(String [] Services, SOPList l) path = "/dev/null"; } + + this.priorityAETs = settings.getPriorityAETitles(); + LoggerFactory.getLogger(RSIStorage.class).error("Priority C-STORE: " + this.priorityAETs); + device.setNetworkApplicationEntity(nae); device.setNetworkConnection(nc); nae.setNetworkConnection(nc); @@ -248,7 +254,10 @@ protected void onCStoreRQ(Association as, int pcid, DicomObject rq, PDVInputStre uri = storage.store(d); if(uri != null) { // queue to index - queue.add(uri); + ImageElement element = new ImageElement(); + element.setCallingAET(as.getCallingAET()); + element.setUri(uri); + queue.add(element); } } @@ -256,7 +265,46 @@ protected void onCStoreRQ(Association as, int pcid, DicomObject rq, PDVInputStre throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage()); } } - + + /** + * ImageElement is a entry of a C-STORE. For Each C-STORE RQ + * an ImageElement is created and are put in the queue to index. + * + * This only happens after the store in Storage Plugins. + * + * @param + */ + class ImageElement> + implements Comparable>{ + private URI uri; + private String callingAET; + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public String getCallingAET() { + return callingAET; + } + + public void setCallingAET(String callingAET) { + this.callingAET = callingAET; + } + + @Override + public int compareTo(ImageElement o1) { + if (o1.getCallingAET().equals(this.getCallingAET())) + return 0 ; + else if (settings.getPriorityAETitles().contains(this.getCallingAET())) + return -1; + else return 1; + } + } + class Indexer extends Thread { @@ -268,8 +316,9 @@ public void run() { try { - URI exam = queue.take(); - + // Fetch an element by the queue taking into account the priorities. + ImageElement element = queue.take(); + URI exam = element.getUri(); if(exam != null) { List reports = PluginController.getInstance().indexBlocking(exam); diff --git a/sdk/src/main/java/pt/ua/dicoogle/sdk/core/ServerSettingsReader.java b/sdk/src/main/java/pt/ua/dicoogle/sdk/core/ServerSettingsReader.java index 23a1c5eff..45f1f6d4d 100644 --- a/sdk/src/main/java/pt/ua/dicoogle/sdk/core/ServerSettingsReader.java +++ b/sdk/src/main/java/pt/ua/dicoogle/sdk/core/ServerSettingsReader.java @@ -132,5 +132,8 @@ public interface ServerSettingsReader { public Map getModalityFind(); public List getMoves(); + + public Set getPriorityAETitles(); + } From 2167c433ae8a5ab1ab899cb1ac9c1854fcb93a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20A=2E=20Bastia=CC=83o=20Silva?= Date: Sun, 27 Dec 2015 21:51:33 +0000 Subject: [PATCH 3/3] Changed a message from error to debug level --- dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java index a1c5a7c2e..2ae37ecb8 100755 --- a/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java +++ b/dicoogle/src/main/java/pt/ua/dicoogle/server/RSIStorage.java @@ -114,7 +114,7 @@ public RSIStorage(String [] Services, SOPList l) this.priorityAETs = settings.getPriorityAETitles(); - LoggerFactory.getLogger(RSIStorage.class).error("Priority C-STORE: " + this.priorityAETs); + LoggerFactory.getLogger(RSIStorage.class).debug("Priority C-STORE: " + this.priorityAETs); device.setNetworkApplicationEntity(nae); device.setNetworkConnection(nc); @@ -316,7 +316,7 @@ public void run() { try { - // Fetch an element by the queue taking into account the priorities. + // Fetch an element by the queue taking into account the priorities. ImageElement element = queue.take(); URI exam = element.getUri(); if(exam != null)