/** * @since 2.0 */ public Connection attach(String host, int port, Parser parser, Class<? extends LowerLayerProtocol> llpClass, boolean tls) throws HL7Exception { return attach(host, port, 0, parser, llpClass, tls); }
/** * <p> * Returns a new (non-singleton) instance of the ConnectionHub which uses the given executor * service. * </p> * <p> * See <a href="http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/SendAndReceiveAMessage.html">this example page</a> * for an example of how to use ConnectionHub. * </p> */ public synchronized static ConnectionHub getNewInstance(HapiContext context) { return new ConnectionHub(context); }
/** * @since 2.2 */ public Connection attachLazily(String host, int port, Parser parser, LowerLayerProtocol llp) throws HL7Exception { return attachLazily(host, port, 0, parser, llp, false); }
/** * @since 2.0 */ public Connection attach(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception { return attach(new ConnectionData(host, outboundPort, inboundPort, getHapiContext() .getGenericParser(), getHapiContext().getLowerLayerProtocol(), tls, getHapiContext().getSocketFactory(), false)); }
ConnectionHub connectionHub = ConnectionHub.getInstance(); .attach("localhost", port, new PipeParser(), MinLowerLayerProtocol.class); connectionHub.discard(connection); server.stop();
/** * @deprecated default executor service is shut down automatically */ public static void shutdown() { ConnectionHub hub = getInstance(); if (DefaultExecutorService.isDefaultService(hub.getHapiContext().getExecutorService())) { hub.getHapiContext().getExecutorService().shutdown(); instance = null; } }
private void discardConnectionIfStale(Connection conn) { if (conn != null && !conn.isOpen()) { log.info("Discarding connection which appears to be closed. Remote addr: {}", conn.getRemoteAddress()); discard(conn); conn = null; } }
/** * Returns the singleton instance of ConnectionHub * * @deprecated Use {@link HapiContext#getConnectionHub()} to get an instance of ConnectionHub. * See <a href="http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/SendAndReceiveAMessage.html">this example page</a> for an example of how to use ConnectionHub. */ public static ConnectionHub getInstance() { return getInstance(DefaultExecutorService.getDefaultService()); }
/** * Closes and discards all connections. */ public void discardAll() { for (ConnectionData cd : allConnections()) { connections.removeAllOf(cd); } }
public void close() throws IOException { getConnectionHub().discardAll(); if (DefaultExecutorService.isDefaultService(executorService)) { executorService.shutdownNow(); } }
@Override protected Connection open(ConnectionData connectionData) throws Exception { return ConnectionFactory .open(connectionData, getHapiContext().getExecutorService()); }
public boolean isOpen(ConnectionData key) { return getKnownConnection(key).isOpen(); }
/** * @since 2.0 */ public Connection attach(ConnectionData data) throws HL7Exception { try { Connection conn = null; // Disallow establishing same connection targets concurrently connectionMutexes.putIfAbsent(data.toString(), data.toString()); String mutex = connectionMutexes.get(data.toString()); synchronized (mutex) { discardConnectionIfStale(connections.get(data)); // Create connection or increase counter conn = connections.put(data); } return conn; } catch (Exception e) { log.debug("Failed to attach", e); throw new HL7Exception("Cannot open connection to " + data.getHost() + ":" + data.getPort() + "/" + data.getPort2(), e); } }
/** * @since 2.0 */ public Connection attach(String host, int outboundPort, int inboundPort, boolean tls) throws HL7Exception { return attach(new ConnectionData(host, outboundPort, inboundPort, getHapiContext() .getGenericParser(), getHapiContext().getLowerLayerProtocol(), tls, getHapiContext().getSocketFactory(), false)); }
/** * @deprecated default executor service is shut down automatically */ public static void shutdown() { ConnectionHub hub = getInstance(); if (DefaultExecutorService.isDefaultService(hub.getHapiContext().getExecutorService())) { hub.getHapiContext().getExecutorService().shutdown(); instance = null; } }
private void discardConnectionIfStale(Connection conn) { if (conn != null && !conn.isOpen()) { log.info("Discarding connection which appears to be closed. Remote addr: {}", conn.getRemoteAddress()); discard(conn); conn = null; } }
/** * Returns the singleton instance of ConnectionHub * * @deprecated Use {@link HapiContext#getConnectionHub()} to get an instance of ConnectionHub. * See <a href="http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/SendAndReceiveAMessage.html">this example page</a> for an example of how to use ConnectionHub. */ public static ConnectionHub getInstance() { return getInstance(DefaultExecutorService.getDefaultService()); }
/** * Closes and discards all connections. */ public void discardAll() { for (ConnectionData cd : allConnections()) { connections.removeAllOf(cd); } }
public void close() throws IOException { getConnectionHub().discardAll(); if (DefaultExecutorService.isDefaultService(executorService)) { executorService.shutdownNow(); } }
@Override protected Connection open(ConnectionData connectionData) throws Exception { return ConnectionFactory .open(connectionData, getHapiContext().getExecutorService()); }