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