Search in sources :

Example 16 with OChannelBinaryAsynchClient

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);
            }
        });
    }
}
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 17 with OChannelBinaryAsynchClient

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;
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException) HashSet(java.util.HashSet)

Example 18 with OChannelBinaryAsynchClient

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);
}
Also used : OChannelListener(com.orientechnologies.orient.enterprise.channel.binary.OChannelListener) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) Test(org.testng.annotations.Test)

Example 19 with OChannelBinaryAsynchClient

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());
}
Also used : OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) Test(org.testng.annotations.Test)

Example 20 with OChannelBinaryAsynchClient

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);
}
Also used : OBonsaiCollectionPointer(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OBonsaiCollectionPointer) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Test(org.testng.annotations.Test)

Aggregations

OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)21 IOException (java.io.IOException)12 OIOException (com.orientechnologies.common.io.OIOException)9 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)6 OException (com.orientechnologies.common.exception.OException)6 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)4 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)4 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)4 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)4 NamingException (javax.naming.NamingException)4 Test (org.testng.annotations.Test)4 Test (org.junit.Test)3 OSBTreeCollectionManager (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeCollectionManager)2 OChannelListener (com.orientechnologies.orient.enterprise.channel.binary.OChannelListener)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OCommandRequestAsynch (com.orientechnologies.orient.core.command.OCommandRequestAsynch)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1