use of com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient 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.client.binary.OChannelBinaryAsynchClient in project orientdb by orientechnologies.
the class OServerAdmin method dropDatabase.
/**
* Drops a database from a remote server instance.
*
* @param iDatabaseName The database name
* @param storageType Storage type between "plocal" or "memory".
* @return The instance itself. Useful to execute method in chain
* @throws IOException
*/
public synchronized OServerAdmin dropDatabase(final String iDatabaseName, final String storageType) throws IOException {
boolean retry = true;
while (retry) {
retry = networkAdminOperation(new OStorageRemoteOperation<Boolean>() {
@Override
public Boolean execute(final OChannelBinaryAsynchClient network, OStorageRemoteSession session) throws IOException {
try {
try {
storage.beginRequest(network, OChannelBinaryProtocol.REQUEST_DB_DROP, session);
network.writeString(iDatabaseName);
network.writeString(storageType);
} finally {
storage.endRequest(network);
}
storage.getResponse(network, session);
return false;
} catch (OModificationOperationProhibitedException oope) {
return handleDBFreeze();
}
}
}, "Cannot delete the remote storage: " + storage.getName());
}
final Set<OStorage> underlyingStorages = new HashSet<OStorage>();
for (OStorage s : Orient.instance().getStorages()) {
if (s.getType().equals(storage.getType()) && s.getName().equals(storage.getName())) {
underlyingStorages.add(s.getUnderlying());
}
}
for (OStorage s : underlyingStorages) {
s.close(true, true);
}
ODatabaseRecordThreadLocal.INSTANCE.remove();
return this;
}
use of com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient 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);
}
use of com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient in project orientdb by orientechnologies.
the class ORemoteConnectionPushListenerTest method testRegistredOnlyOnce.
@Test
public void testRegistredOnlyOnce() {
OChannelBinaryAsynchClient chann = Mockito.mock(OChannelBinaryAsynchClient.class);
OStorageRemoteAsynchEventListener listener = Mockito.mock(OStorageRemoteAsynchEventListener.class);
ORemoteConnectionPushListener poolListener = new ORemoteConnectionPushListener();
ORemoteConnectionPool pool = Mockito.mock(ORemoteConnectionPool.class);
poolListener.addListener(pool, chann, listener);
poolListener.addListener(pool, chann, listener);
poolListener.onRequest((byte) 10, null);
Mockito.verify(listener, VerificationModeFactory.only()).onRequest(Mockito.anyByte(), Mockito.anyObject());
}
use of com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient in project orientdb by orientechnologies.
the class OSBTreeCollectionManagerRemoteTest method testCreateTree.
@Test(enabled = false)
public void testCreateTree() throws Exception {
OSBTreeCollectionManagerRemote remoteManager = new OSBTreeCollectionManagerRemote(storageMock, networkSerializerMock);
ODatabaseRecordThreadLocal.INSTANCE.set(dbMock);
when(dbMock.getStorage()).thenReturn(storageMock);
when(storageMock.getUnderlying()).thenReturn(storageMock);
when(storageMock.beginRequest(Mockito.any(OChannelBinaryAsynchClient.class), eq(OChannelBinaryProtocol.REQUEST_CREATE_SBTREE_BONSAI), Mockito.any(OStorageRemoteSession.class))).thenReturn(clientMock);
when(networkSerializerMock.readCollectionPointer(Mockito.<OChannelBinaryAsynchClient>any())).thenReturn(new OBonsaiCollectionPointer(EXPECTED_FILE_ID, EXPECTED_ROOT_POINTER));
OSBTreeBonsaiRemote<OIdentifiable, Integer> tree = remoteManager.createTree(EXPECTED_CLUSTER_ID);
assertNotNull(tree);
assertEquals(tree.getFileId(), EXPECTED_FILE_ID);
assertEquals(tree.getRootBucketPointer(), EXPECTED_ROOT_POINTER);
verify(dbMock).getStorage();
verifyNoMoreInteractions(dbMock);
verify(storageMock).getUnderlying();
verify(storageMock).beginRequest(Mockito.any(OChannelBinaryAsynchClient.class), eq(OChannelBinaryProtocol.REQUEST_CREATE_SBTREE_BONSAI), Mockito.any(OStorageRemoteSession.class));
verify(clientMock).writeInt(eq(EXPECTED_CLUSTER_ID));
verify(storageMock).endRequest(Matchers.same(clientMock));
verify(storageMock).beginResponse(Matchers.same(clientMock), Mockito.any(OStorageRemoteSession.class));
verify(networkSerializerMock).readCollectionPointer(Matchers.same(clientMock));
verify(storageMock).endResponse(Matchers.same(clientMock));
verifyNoMoreInteractions(storageMock);
}
Aggregations