Search in sources :

Example 1 with TransportClient

use of com.baidu.hugegraph.computer.core.network.TransportClient in project hugegraph-computer by hugegraph.

the class TransportConnectionManager method getOrCreateClient.

@Override
public TransportClient getOrCreateClient(ConnectionId connectionId) throws TransportException {
    E.checkArgument(this.clientFactory != null, "The clientManager has not been initialized yet");
    TransportClient client = this.clients.get(connectionId);
    if (client == null) {
        // Create the client if we don't have it yet.
        ClientFactory clientFactory = this.clientFactory;
        TransportClient newClient = clientFactory.createClient(connectionId, this.clientHandler);
        this.clients.putIfAbsent(connectionId, newClient);
        client = this.clients.get(connectionId);
    }
    return client;
}
Also used : TransportClient(com.baidu.hugegraph.computer.core.network.TransportClient) ClientFactory(com.baidu.hugegraph.computer.core.network.ClientFactory)

Example 2 with TransportClient

use of com.baidu.hugegraph.computer.core.network.TransportClient in project hugegraph-computer by hugegraph.

the class TransportConnectionManager method shutdownClients.

@Override
public void shutdownClients() {
    if (this.clientFactory != null) {
        this.clientFactory.close();
        this.clientFactory = null;
    }
    if (!this.clients.isEmpty()) {
        Iterator<Map.Entry<ConnectionId, TransportClient>> iterator = this.clients.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<ConnectionId, TransportClient> next = iterator.next();
            TransportClient client = next.getValue();
            if (client != null) {
                client.close();
            }
            iterator.remove();
        }
    }
}
Also used : ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) TransportClient(com.baidu.hugegraph.computer.core.network.TransportClient) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 3 with TransportClient

use of com.baidu.hugegraph.computer.core.network.TransportClient in project hugegraph-computer by hugegraph.

the class ConnectionManagerTest method testShutDown.

@Test
public void testShutDown() throws IOException {
    ConnectionId connectionId = ConnectionId.parseConnectionId("127.0.0.1", port);
    TransportClient client = connectionManager.getOrCreateClient(connectionId);
    Assert.assertTrue(client.active());
    connectionManager.shutdownClients();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        connectionManager.getOrCreateClient(connectionId);
    }, e -> {
        Assert.assertContains("has not been initialized yet", e.getMessage());
    });
    connectionManager.shutdownServer();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        connectionManager.getServer();
    }, e -> {
        Assert.assertContains("has not been initialized yet", e.getMessage());
    });
    connectionManager.shutdown();
}
Also used : ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) TransportClient(com.baidu.hugegraph.computer.core.network.TransportClient) Test(org.junit.Test)

Example 4 with TransportClient

use of com.baidu.hugegraph.computer.core.network.TransportClient in project hugegraph-computer by hugegraph.

the class ConnectionManagerTest method testGetOrCreateClient.

@Test
public void testGetOrCreateClient() throws IOException {
    ConnectionId connectionId = ConnectionId.parseConnectionId("127.0.0.1", port);
    TransportClient client = connectionManager.getOrCreateClient(connectionId);
    Assert.assertTrue(client.active());
}
Also used : ConnectionId(com.baidu.hugegraph.computer.core.network.ConnectionId) TransportClient(com.baidu.hugegraph.computer.core.network.TransportClient) Test(org.junit.Test)

Example 5 with TransportClient

use of com.baidu.hugegraph.computer.core.network.TransportClient in project hugegraph-computer by hugegraph.

the class ConnectionManagerTest method testCloseClientWithHostAndPort.

@Test
public void testCloseClientWithHostAndPort() throws IOException {
    TransportClient client = connectionManager.getOrCreateClient("127.0.0.1", port);
    Assert.assertTrue(client.active());
}
Also used : TransportClient(com.baidu.hugegraph.computer.core.network.TransportClient) Test(org.junit.Test)

Aggregations

TransportClient (com.baidu.hugegraph.computer.core.network.TransportClient)7 ConnectionId (com.baidu.hugegraph.computer.core.network.ConnectionId)5 Test (org.junit.Test)4 ClientFactory (com.baidu.hugegraph.computer.core.network.ClientFactory)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1