/** * The key/value entry is removed and the value is cleaned up. */ public D removeAllOf(K key) { D removed = content.remove(key).value; dispose(removed); return removed; }
/** * @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); } }
/** * If the key exists, the counter is increased. Otherwise, a value is created, and the * key/value pair is added to the map. */ public D put(K key) throws Exception { if (content.containsKey(key)) { return content.put(key, content.get(key).increase()).getValue(); } else { Count c = new Count(open(key)); content.put(key, c); return c.getValue(); } }
/** * @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); } }
public Connection getKnownConnection(ConnectionData key) { return connections.get(key); }
public Set<? extends ConnectionData> allConnections() { return connections.keySet(); }
public Connection getKnownConnection(ConnectionData key) { return connections.get(key); }
public Set<? extends ConnectionData> allConnections() { return connections.keySet(); }
/** * If the counter of the key/value is greater than one, the counter is decreased. Otherwise, * the entry is removed and the value is cleaned up. */ public D remove(K key) { Count pair = content.get(key); if (pair == null) return null; if (pair.isLast()) { return removeAllOf(key); } return content.put(key, content.get(key).decrease()).getValue(); }
/** * If the counter of the key/value is greater than one, the counter is decreased. Otherwise, * the entry is removed and the value is cleaned up. */ public D remove(K key) { Count pair = content.get(key); if (pair == null) return null; if (pair.isLast()) { return removeAllOf(key); } return content.put(key, content.get(key).decrease()).getValue(); }
/** * Closes and discards all connections. */ public void discardAll() { for (ConnectionData cd : allConnections()) { connections.removeAllOf(cd); } }
/** * 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. */ public void discard(Connection c) { ConnectionData cd = connections.find(c); if (cd != null) connections.removeAllOf(cd); }
/** * 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. */ public void detach(Connection c) { ConnectionData cd = connections.find(c); if (cd != null) connections.remove(cd); }
/** * If the key exists, the counter is increased. Otherwise, a value is created, and the * key/value pair is added to the map. */ public D put(K key) throws Exception { if (content.containsKey(key)) { return content.put(key, content.get(key).increase()).getValue(); } else { Count c = new Count(open(key)); content.put(key, c); return c.getValue(); } }
/** * Closes and discards all connections. */ public void discardAll() { for (ConnectionData cd : allConnections()) { connections.removeAllOf(cd); } }
/** * The key/value entry is removed and the value is cleaned up. */ public D removeAllOf(K key) { D removed = content.remove(key).value; dispose(removed); return removed; }
/** * 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. */ public void detach(Connection c) { ConnectionData cd = connections.find(c); if (cd != null) connections.remove(cd); }
/** * 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. */ public void discard(Connection c) { ConnectionData cd = connections.find(c); if (cd != null) connections.removeAllOf(cd); }