Search in sources :

Example 1 with OChannelListener

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

the class OChannel method close.

public synchronized void close() {
    PROFILER.unregisterHookValue(profilerMetric + ".transmittedBytes");
    PROFILER.unregisterHookValue(profilerMetric + ".receivedBytes");
    PROFILER.unregisterHookValue(profilerMetric + ".flushes");
    try {
        if (socket != null) {
            socket.close();
            socket = null;
        }
    } catch (Exception e) {
        OLogManager.instance().debug(this, "Error during socket close", e);
    }
    try {
        if (inStream != null) {
            inStream.close();
            inStream = null;
        }
    } catch (Exception e) {
        OLogManager.instance().debug(this, "Error during closing of input stream", e);
    }
    try {
        if (outStream != null) {
            outStream.close();
            outStream = null;
        }
    } catch (Exception e) {
        OLogManager.instance().debug(this, "Error during closing of output stream", e);
    }
    for (OChannelListener l : getListenersCopy()) try {
        l.onChannelClose(this);
    } catch (Exception e) {
        OLogManager.instance().debug(this, "Error during closing of channel close listener", e);
    }
    lockRead.close();
    lockWrite.close();
    resetListeners();
}
Also used : OChannelListener(com.orientechnologies.orient.enterprise.channel.binary.OChannelListener) IOException(java.io.IOException)

Example 2 with OChannelListener

use of com.orientechnologies.orient.enterprise.channel.binary.OChannelListener 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)

Example 3 with OChannelListener

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

the class ORemoteConnectionPushListenerTest method testCloseListerner.

@Test
public void testCloseListerner() {
    OChannelBinaryAsynchClient chann = Mockito.mock(OChannelBinaryAsynchClient.class);
    OStorageRemoteAsynchEventListener listener = Mockito.mock(OStorageRemoteAsynchEventListener.class);
    ORemoteConnectionPool pool = Mockito.mock(ORemoteConnectionPool.class);
    ArgumentCaptor<OChannelListener> captor = ArgumentCaptor.forClass(OChannelListener.class);
    Mockito.doNothing().when(chann).registerListener(captor.capture());
    ORemoteConnectionPushListener poolListener = new ORemoteConnectionPushListener();
    poolListener.addListener(pool, chann, listener);
    poolListener.addListener(pool, chann, listener);
    captor.getValue().onChannelClose(chann);
    Mockito.verify(listener, VerificationModeFactory.only()).onEndUsedConnections(pool);
}
Also used : OChannelListener(com.orientechnologies.orient.enterprise.channel.binary.OChannelListener) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) Test(org.testng.annotations.Test)

Aggregations

OChannelListener (com.orientechnologies.orient.enterprise.channel.binary.OChannelListener)3 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)2 OChannel (com.orientechnologies.orient.enterprise.channel.OChannel)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1