ca.uhn.hl7v2.app
Class ConnectionHub

java.lang.Object
  extended by ca.uhn.hl7v2.app.ConnectionHub

public class ConnectionHub
extends Object

Provides access to shared HL7 Connections. The ConnectionHub has at most one connection to any given address at any time.

Synchronization Note: This class should be safe to use in a multithreaded environment. A synchronization mutex is maintained for any given target host and port, so that if two threads are trying to connect to two separate destinations neither will block, but if two threads are trying to connect to the same destination, one will block until the other has finished trying. Use caution if this class is to be used in an environment where a very large (over 1000) number of target host/port destinations will be accessed at the same time.

Author:
Bryan Tripp

Field Summary
static String MAX_CONCURRENT_TARGETS
          Set a system property with this key to a string containing an integer larger than the default ("1000") if you need to connect to a very large number of targets at the same time in a multithreaded environment.
 
Method Summary
 Set<? extends ca.uhn.hl7v2.app.ConnectionData> allConnections()
           
 Connection attach(ca.uhn.hl7v2.app.ConnectionData data)
           
 Connection attach(String host, int outboundPort, int inboundPort, Parser parser, Class<? extends LowerLayerProtocol> llpClass)
           
 Connection attach(String host, int outboundPort, int inboundPort, Parser parser, Class<? extends LowerLayerProtocol> llpClass, boolean tls)
           
 Connection attach(String host, int outboundPort, int inboundPort, Parser parser, LowerLayerProtocol llp, boolean tls)
           
 Connection attach(String host, int port, Parser parser, Class<? extends LowerLayerProtocol> llpClass)
          Returns a Connection to the given address, opening this Connection if necessary.
 Connection attach(String host, int port, Parser parser, Class<? extends LowerLayerProtocol> llpClass, boolean tls)
           
 Connection attach(String host, int port, Parser parser, LowerLayerProtocol llp, boolean tls)
           
 void detach(Connection c)
          Informs the ConnectionHub that you are done with the given Connection - if no other code is using it, it will be closed, so you should not attempt to use a Connection after detaching from it.
 void discard(Connection c)
          Closes and discards the given Connection so that it can not be returned in subsequent calls to attach().
 void discardAll()
           
static ConnectionHub getInstance()
          Returns the singleton instance of ConnectionHub
static ConnectionHub getInstance(ExecutorService service)
          Returns the singleton instance of ConnectionHub.
 Connection getKnownConnection(ca.uhn.hl7v2.app.ConnectionData key)
           
 boolean isOpen(ca.uhn.hl7v2.app.ConnectionData key)
           
static void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CONCURRENT_TARGETS

public static final String MAX_CONCURRENT_TARGETS
Set a system property with this key to a string containing an integer larger than the default ("1000") if you need to connect to a very large number of targets at the same time in a multithreaded environment.

Method Detail

getInstance

public static ConnectionHub getInstance()
Returns the singleton instance of ConnectionHub


shutdown

public static void shutdown()

getInstance

public static ConnectionHub getInstance(ExecutorService service)
Returns the singleton instance of ConnectionHub. If called


attach

public Connection attach(String host,
                         int port,
                         Parser parser,
                         Class<? extends LowerLayerProtocol> llpClass)
                  throws HL7Exception
Returns a Connection to the given address, opening this Connection if necessary. The given Parser will only be used if a new Connection is opened, so there is no guarantee that the Connection returned will be using the Parser you provide. If you need explicit access to the Parser the Connection is using, call Connection.getParser().

Throws:
HL7Exception

attach

public Connection attach(String host,
                         int port,
                         Parser parser,
                         Class<? extends LowerLayerProtocol> llpClass,
                         boolean tls)
                  throws HL7Exception
Throws:
HL7Exception

attach

public Connection attach(String host,
                         int port,
                         Parser parser,
                         LowerLayerProtocol llp,
                         boolean tls)
                  throws HL7Exception
Throws:
HL7Exception

attach

public Connection attach(String host,
                         int outboundPort,
                         int inboundPort,
                         Parser parser,
                         Class<? extends LowerLayerProtocol> llpClass)
                  throws HL7Exception
Throws:
HL7Exception

attach

public Connection attach(String host,
                         int outboundPort,
                         int inboundPort,
                         Parser parser,
                         Class<? extends LowerLayerProtocol> llpClass,
                         boolean tls)
                  throws HL7Exception
Throws:
HL7Exception

attach

public Connection attach(String host,
                         int outboundPort,
                         int inboundPort,
                         Parser parser,
                         LowerLayerProtocol llp,
                         boolean tls)
                  throws HL7Exception
Throws:
HL7Exception

attach

public Connection attach(ca.uhn.hl7v2.app.ConnectionData data)
                  throws HL7Exception
Throws:
HL7Exception

detach

public void detach(Connection c)
Informs the ConnectionHub that you are done with the given Connection - if no other code is using it, it will be closed, so you should not attempt to use a Connection after detaching from it. If the connection is not enlisted, this method does nothing.


discard

public void discard(Connection c)
Closes and discards the given Connection so that it can not be returned in subsequent calls to attach(). This method is to be used when there is a problem with a Connection, e.g. socket connection closed by remote host.


discardAll

public void discardAll()

allConnections

public Set<? extends ca.uhn.hl7v2.app.ConnectionData> allConnections()

getKnownConnection

public Connection getKnownConnection(ca.uhn.hl7v2.app.ConnectionData key)

isOpen

public boolean isOpen(ca.uhn.hl7v2.app.ConnectionData key)


Copyright © 2001-2012 University Health Network. All Rights Reserved.