Search in sources :

Example 1 with NioClient

use of com.cloud.utils.nio.NioClient in project CloudStack-archive by CloudStack-extras.

the class NioTest method setUp.

public void setUp() {
    s_logger.info("Test");
    _testCount = 0;
    _completedCount = 0;
    _server = new NioServer("NioTestServer", 7777, 5, new NioTestServer());
    _server.start();
    _client = new NioClient("NioTestServer", "127.0.0.1", 7777, 5, new NioTestClient());
    _client.start();
    while (_clientLink == null) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : NioServer(com.cloud.utils.nio.NioServer) NioClient(com.cloud.utils.nio.NioClient)

Example 2 with NioClient

use of com.cloud.utils.nio.NioClient in project cloudstack by apache.

the class NioTest method setUp.

@Before
public void setUp() {
    LOGGER.info("Setting up Benchmark Test");
    completedTestCount = 0;
    testBytes = new byte[1000000];
    randomGenerator.nextBytes(testBytes);
    server = new NioServer("NioTestServer", 0, 1, new NioTestServer());
    try {
        server.start();
    } catch (final NioConnectionException e) {
        Assert.fail(e.getMessage());
    }
    for (int i = 0; i < totalTestCount; i++) {
        final NioClient maliciousClient = new NioMaliciousClient("NioMaliciousTestClient-" + i, "127.0.0.1", server.getPort(), 1, new NioMaliciousTestClient());
        maliciousClients.add(maliciousClient);
        maliciousExecutor.submit(new ThreadedNioClient(maliciousClient));
        final NioClient client = new NioClient("NioTestClient-" + i, "127.0.0.1", server.getPort(), 1, new NioTestClient());
        clients.add(client);
        clientExecutor.submit(new ThreadedNioClient(client));
    }
}
Also used : NioServer(com.cloud.utils.nio.NioServer) NioConnectionException(com.cloud.utils.exception.NioConnectionException) NioClient(com.cloud.utils.nio.NioClient) Before(org.junit.Before)

Example 3 with NioClient

use of com.cloud.utils.nio.NioClient in project CloudStack-archive by CloudStack-extras.

the class Agent method start.

public void start() {
    if (!_resource.start()) {
        s_logger.error("Unable to start the resource: " + _resource.getName());
        throw new CloudRuntimeException("Unable to start the resource: " + _resource.getName());
    }
    _connection.start();
    while (!_connection.isStartup()) {
        _shell.getBackoffAlgorithm().waitBeforeRetry();
        _connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
        _connection.start();
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NioClient(com.cloud.utils.nio.NioClient)

Example 4 with NioClient

use of com.cloud.utils.nio.NioClient in project CloudStack-archive by CloudStack-extras.

the class Agent method reconnect.

protected void reconnect(final Link link) {
    if (!_reconnectAllowed) {
        return;
    }
    synchronized (this) {
        if (_startup != null) {
            _startup.cancel();
            _startup = null;
        }
    }
    link.close();
    link.terminated();
    setLink(null);
    cancelTasks();
    _resource.disconnected();
    int inProgress = 0;
    do {
        _shell.getBackoffAlgorithm().waitBeforeRetry();
        s_logger.info("Lost connection to the server. Dealing with the remaining commands...");
        inProgress = _inProgress.get();
        if (inProgress > 0) {
            s_logger.info("Cannot connect because we still have " + inProgress + " commands in progress.");
        }
    } while (inProgress > 0);
    _connection.stop();
    while (_connection.isStartup()) {
        _shell.getBackoffAlgorithm().waitBeforeRetry();
    }
    try {
        _connection.cleanUp();
    } catch (IOException e) {
        s_logger.warn("Fail to clean up old connection. " + e);
    }
    _connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
    do {
        s_logger.info("Reconnecting...");
        _connection.start();
        _shell.getBackoffAlgorithm().waitBeforeRetry();
    } while (!_connection.isStartup());
    s_logger.info("Connected to the server");
}
Also used : IOException(java.io.IOException) NioClient(com.cloud.utils.nio.NioClient)

Example 5 with NioClient

use of com.cloud.utils.nio.NioClient in project cloudstack by apache.

the class Agent method start.

public void start() {
    if (!_resource.start()) {
        s_logger.error("Unable to start the resource: " + _resource.getName());
        throw new CloudRuntimeException("Unable to start the resource: " + _resource.getName());
    }
    try {
        _connection.start();
    } catch (final NioConnectionException e) {
        s_logger.warn("NIO Connection Exception  " + e);
        s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...");
    }
    while (!_connection.isStartup()) {
        _shell.getBackoffAlgorithm().waitBeforeRetry();
        _connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
        try {
            _connection.start();
        } catch (final NioConnectionException e) {
            s_logger.warn("NIO Connection Exception  " + e);
            s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...");
        }
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NioConnectionException(com.cloud.utils.exception.NioConnectionException) NioClient(com.cloud.utils.nio.NioClient)

Aggregations

NioClient (com.cloud.utils.nio.NioClient)6 NioConnectionException (com.cloud.utils.exception.NioConnectionException)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 NioServer (com.cloud.utils.nio.NioServer)2 IOException (java.io.IOException)2 Before (org.junit.Before)1