Class StorageSOPClassSCPDispatcher

java.lang.Object
com.pixelmed.network.StorageSOPClassSCPDispatcher
All Implemented Interfaces:
Runnable

public class StorageSOPClassSCPDispatcher extends Object implements Runnable

This class waits for incoming connections and association requests for the SCP role of SOP Classes of the Storage Service Class, the Study Root Query Retrieve Information Model Find, Get and Move SOP Classes, and the Verification SOP Class.

The class has a constructor and a run() method. The constructor is passed a socket on which to listen for transport connection open indications. The run() method waits for transport connection open indications, then instantiates StorageSOPClassSCP to accept an association and wait for storage or verification commands, storing data sets in Part 10 files in the specified folder.

An instance of ReceivedObjectHandler can be supplied in the constructor to process the received data set stored in the file when it has been completely received.

For example:

try {
  new Thread(new StorageSOPClassSCPDispatcher(104,"STORESCP",new File("/tmp"),new OurReceivedObjectHandler(),0)).start();
}
catch (IOException e) {
  slf4jlogger.error("",e);
}
 

If it is necessary to shutdown the StorageSOPClassSCPDispatcher, for example after changing the properties that define the listening port or AE Title, the shutdown() method can be called.

Debugging messages with a varying degree of verbosity can be activated.

The main method is also useful in its own right as a command-line Storage SCP utility, which will store incoming files in a specified directory.

For example, on Unix:

% java -cp ./pixelmed.jar com.pixelmed.network.StorageSOPClassSCPDispatcher "104" "STORESCP" "/tmp" 0
 

On Windows, the classpath syntax would use a different separator, e.g. .\pixelmed.jar

Note that the main method can also be used without command line arguments, in which case it looks for a properties file or uses defaults (refer to the main() method documentation for details).

See Also:
  • Field Details

  • Constructor Details

    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, ReceivedObjectHandler receivedObjectHandler) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      receivedObjectHandler - the handler to call after each data set has been received and stored
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders
      receivedObjectHandler - the handler to call after each data set has been received and stored
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, int ourMaximumLengthReceived, int socketReceiveBufferSize, int socketSendBufferSize, File savedImagesFolder, ReceivedObjectHandler receivedObjectHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      ourMaximumLengthReceived - the maximum PDU length that we will offer to receive
      socketReceiveBufferSize - the TCP socket receive buffer size to set (if possible), 0 means leave at the default
      socketSendBufferSize - the TCP socket send buffer size to set (if possible), 0 means leave at the default
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, int ourMaximumLengthReceived, int socketReceiveBufferSize, int socketSendBufferSize, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      ourMaximumLengthReceived - the maximum PDU length that we will offer to receive
      socketReceiveBufferSize - the TCP socket receive buffer size to set (if possible), 0 means leave at the default
      socketSendBufferSize - the TCP socket send buffer size to set (if possible), 0 means leave at the default
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, ReceivedObjectHandler receivedObjectHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders, or null for the default
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, PresentationContextSelectionPolicy presentationContextSelectionPolicy, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders, or null for the default
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      presentationContextSelectionPolicy - which SOP Classes and Transfer Syntaxes to accept and reject, or null for the default
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler, AssociationStatusHandler associationStatusHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, PresentationContextSelectionPolicy presentationContextSelectionPolicy, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders, or null for the default
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      associationStatusHandler - the handler to call when the Association is closed, or null if none required
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      presentationContextSelectionPolicy - which SOP Classes and Transfer Syntaxes to accept and reject, or null for the default
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
    • StorageSOPClassSCPDispatcher

      public StorageSOPClassSCPDispatcher(int port, String calledAETitle, int ourMaximumLengthReceived, int socketReceiveBufferSize, int socketSendBufferSize, File savedImagesFolder, StoredFilePathStrategy storedFilePathStrategy, ReceivedObjectHandler receivedObjectHandler, AssociationStatusHandler associationStatusHandler, QueryResponseGeneratorFactory queryResponseGeneratorFactory, RetrieveResponseGeneratorFactory retrieveResponseGeneratorFactory, NetworkApplicationInformation networkApplicationInformation, PresentationContextSelectionPolicy presentationContextSelectionPolicy, boolean secureTransport) throws IOException

      Construct an instance of dispatcher that will wait for transport connection open indications, and handle associations and commands.

      Parameters:
      port - the port on which to listen for connections
      calledAETitle - our AE Title
      ourMaximumLengthReceived - the maximum PDU length that we will offer to receive
      socketReceiveBufferSize - the TCP socket receive buffer size to set (if possible), 0 means leave at the default
      socketSendBufferSize - the TCP socket send buffer size to set (if possible), 0 means leave at the default
      savedImagesFolder - the folder in which to store received data sets (may be null, to ignore received data for testing)
      storedFilePathStrategy - the strategy to use for naming received files and folders, or null for the default
      receivedObjectHandler - the handler to call after each data set has been received and stored, or null for the default that prints the file name
      associationStatusHandler - the handler to call when the Association is closed, or null if none required
      queryResponseGeneratorFactory - the factory to make handlers to generate query responses from a supplied query message
      retrieveResponseGeneratorFactory - the factory to make handlers to generate retrieve responses from a supplied retrieve message
      networkApplicationInformation - from which to obtain a map of application entity titles to presentation addresses
      presentationContextSelectionPolicy - which SOP Classes and Transfer Syntaxes to accept and reject, or null for the default
      secureTransport - true if to use secure transport protocol
      Throws:
      IOException
  • Method Details

    • isReady

      public boolean isReady()

      Is the dispatcher ready to receive connections?

      Useful for unit tests so as to know when to start sending to it.

      return true if ready
    • shutdown

      public void shutdown()

      Request the dispatcher to stop listening and exit the thread.

    • run

      public void run()

      Waits for a transport connection indications, then spawns new threads to act as association acceptors, which then wait for storage or verification commands, storing data sets in Part 10 files in the specified folder, until the associations are released or the transport connections are closed.

      Specified by:
      run in interface Runnable
    • main

      public static void main(String[] arg)

      For testing.

      Wait for connections, accept associations and store received files in the specified folder.

      Parameters:
      arg - array of zero, thre, four, five, seven or eight strings - our port, our AE Title, optionally the max PDU size, socket receive and send buffer sizes, the folder in which to stored received files (zero length or "-" if want to ignore received data), optionally a string flag valued SECURE or NONSECURE (defaults to NONSECURE); optionally the range of Transfer Syntaxes accepted, either UNCOMPRESSED or ANY (defaults to UNCOMPRESSED); if no arguments are supplied the properties in "~/.com.pixelmed.network.StorageSOPClassSCPDispatcher.properties" will be used if present, otherwise the defaults (11112,STORESCP,~/tmp) will be used - in this mode the service will also be self-registered with dns-sd if possible