public void cleanResources( ConstructorFunction<Object, Throwable> responseCtor, ClientConnection connection) { final Iterator<Map.Entry<Integer, ClientInvocation>> iter = callIdMap.entrySet().iterator(); while (iter.hasNext()) { final Map.Entry<Integer, ClientInvocation> entry = iter.next(); final ClientInvocation invocation = entry.getValue(); if (connection.equals(invocation.getSendConnection())) { iter.remove(); invocation.notifyException(responseCtor.createNew(null)); eventHandlerMap.remove(entry.getKey()); } } final Iterator<ClientListenerInvocation> iterator = eventHandlerMap.values().iterator(); while (iterator.hasNext()) { final ClientInvocation invocation = iterator.next(); if (connection.equals(invocation.getSendConnection())) { iterator.remove(); invocation.notifyException(responseCtor.createNew(null)); } } }
@Override public void heartBeatStopped(Connection connection) { ClientMessage request = ClientRemoveAllListenersCodec.encodeRequest(); ClientInvocation removeListenerInvocation = new ClientInvocation(client, request, connection); removeListenerInvocation.setBypassHeartbeatCheck(true); removeListenerInvocation.invoke(); final Address remoteEndpoint = connection.getEndPoint(); final Iterator<ClientListenerInvocation> iterator = eventHandlerMap.values().iterator(); final TargetDisconnectedException response = new TargetDisconnectedException(remoteEndpoint); while (iterator.hasNext()) { final ClientInvocation clientInvocation = iterator.next(); if (clientInvocation.getSendConnection().equals(connection)) { iterator.remove(); clientInvocation.notifyException(response); } } }