Search in sources :

Example 1 with OChannel

use of com.orientechnologies.orient.enterprise.channel.OChannel in project orientdb by orientechnologies.

the class ORemoteConnectionPushListener method addListener.

public void addListener(final ORemoteConnectionPool pool, final OChannelBinaryAsynchClient connection, final OStorageRemoteAsynchEventListener listener) {
    this.listeners.add(listener);
    Set<OChannelBinaryAsynchClient> ans = conns.get(listener);
    if (ans == null) {
        ans = Collections.synchronizedSet(new HashSet<OChannelBinaryAsynchClient>());
        Set<OChannelBinaryAsynchClient> putRet = conns.putIfAbsent(listener, ans);
        if (putRet != null)
            ans = putRet;
    }
    if (!ans.contains(connection)) {
        ans.add(connection);
        connection.registerListener(new OChannelListener() {

            @Override
            public void onChannelClose(OChannel iChannel) {
                Set<OChannelBinaryAsynchClient> all = conns.get(listener);
                all.remove(iChannel);
                if (all.isEmpty()) {
                    listener.onEndUsedConnections(pool);
                }
                connection.unregisterListener(this);
            }
        });
    }
}
Also used : OChannelListener(com.orientechnologies.orient.enterprise.channel.binary.OChannelListener) HashSet(java.util.HashSet) Set(java.util.Set) OChannel(com.orientechnologies.orient.enterprise.channel.OChannel) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) HashSet(java.util.HashSet)

Aggregations

OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)1 OChannel (com.orientechnologies.orient.enterprise.channel.OChannel)1 OChannelListener (com.orientechnologies.orient.enterprise.channel.binary.OChannelListener)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1