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();
}
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);
}
});
}
}
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);
}
Aggregations