Search in sources :

Example 1 with NioServer

use of com.cloud.utils.nio.NioServer 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 NioServer

use of com.cloud.utils.nio.NioServer 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 NioServer

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

the class AgentManagerImpl method configure.

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    s_logger.info("Ping Timeout is " + PingTimeout.value());
    final int threads = DirectAgentLoadSize.value();
    _nodeId = ManagementServerNode.getManagementServerId();
    s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId);
    final long lastPing = (System.currentTimeMillis() >> 10) - (long) (PingTimeout.value() * PingInterval.value());
    _hostDao.markHostsAsDisconnected(_nodeId, lastPing);
    registerForHostEvents(new BehindOnPingListener(), true, true, false);
    registerForHostEvents(new SetHostParamsListener(), true, true, false);
    _executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));
    _connectExecutor = new ThreadPoolExecutor(100, 500, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentConnectTaskPool"));
    // allow core threads to time out even when there are no items in the queue
    _connectExecutor.allowCoreThreadTimeOut(true);
    _connection = new NioServer("AgentManager", Port.value(), Workers.value() + 10, this);
    s_logger.info("Listening on " + Port.value() + " with " + Workers.value() + " workers");
    // executes all agent commands other than cron and ping
    _directAgentExecutor = new ScheduledThreadPoolExecutor(DirectAgentPoolSize.value(), new NamedThreadFactory("DirectAgent"));
    // executes cron and ping agent commands
    _cronJobExecutor = new ScheduledThreadPoolExecutor(DirectAgentPoolSize.value(), new NamedThreadFactory("DirectAgentCronJob"));
    s_logger.debug("Created DirectAgentAttache pool with size: " + DirectAgentPoolSize.value());
    // add 1 to always make the value > 0
    _directAgentThreadCap = Math.round(DirectAgentPoolSize.value() * DirectAgentThreadCap.value()) + 1;
    _monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor"));
    return true;
}
Also used : NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NioServer(com.cloud.utils.nio.NioServer) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

NioServer (com.cloud.utils.nio.NioServer)3 NioClient (com.cloud.utils.nio.NioClient)2 NamedThreadFactory (com.cloud.utils.concurrency.NamedThreadFactory)1 NioConnectionException (com.cloud.utils.exception.NioConnectionException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Before (org.junit.Before)1