Search in sources :

Example 1 with ClientRequestHandlerFactory

use of voldemort.server.protocol.ClientRequestHandlerFactory in project voldemort by voldemort.

the class VoldemortServer method createOnlineServices.

public void createOnlineServices() {
    onlineServices = Lists.newArrayList();
    if (voldemortConfig.isHttpServerEnabled()) {
        /*
             * TODO: Get rid of HTTP Service.
             */
        HttpService httpService = new HttpService(this, storageService, storeRepository, RequestFormatType.VOLDEMORT_V1, voldemortConfig.getMaxThreads(), identityNode.getHttpPort());
        onlineServices.add(httpService);
    }
    if (voldemortConfig.isRestServiceEnabled()) {
        RestService restService = new RestService(voldemortConfig, identityNode.getRestPort(), storeRepository, identityNode.getZoneId(), metadata.getStoreDefList());
        onlineServices.add(restService);
    }
    if (voldemortConfig.isSocketServerEnabled()) {
        RequestHandlerFactory clientRequestHandlerFactory = new ClientRequestHandlerFactory(this.storeRepository);
        if (voldemortConfig.getUseNioConnector()) {
            logger.info("Using NIO Connector.");
            NioSocketService nioSocketService = new NioSocketService(clientRequestHandlerFactory, identityNode.getSocketPort(), voldemortConfig.getSocketBufferSize(), voldemortConfig.isNioConnectorKeepAlive(), voldemortConfig.getNioConnectorSelectors(), "nio-socket-server", voldemortConfig.isJmxEnabled(), voldemortConfig.getNioAcceptorBacklog(), voldemortConfig.getNioSelectorMaxHeartBeatTimeMs());
            onlineServices.add(nioSocketService);
        } else {
            logger.info("Using BIO Connector.");
            SocketService socketService = new SocketService(clientRequestHandlerFactory, identityNode.getSocketPort(), voldemortConfig.getCoreThreads(), voldemortConfig.getMaxThreads(), voldemortConfig.getSocketBufferSize(), "socket-server", voldemortConfig.isJmxEnabled());
            onlineServices.add(socketService);
        }
    }
}
Also used : HttpService(voldemort.server.http.HttpService) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) SocketRequestHandlerFactory(voldemort.server.protocol.SocketRequestHandlerFactory) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) RequestHandlerFactory(voldemort.server.protocol.RequestHandlerFactory) NioSocketService(voldemort.server.niosocket.NioSocketService) NioSocketService(voldemort.server.niosocket.NioSocketService) SocketService(voldemort.server.socket.SocketService) RestService(voldemort.rest.server.RestService)

Example 2 with ClientRequestHandlerFactory

use of voldemort.server.protocol.ClientRequestHandlerFactory in project voldemort by voldemort.

the class SimpleSocketPoolTest method testClientRequestExecutorLimitSomeTimeout.

@Test
public void testClientRequestExecutorLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(null), 7666, 50, 50, 1000);
    server.start();
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ClientRequestExecutorPool clientRequestExecutorPool = new ClientRequestExecutorPool(config.getMaxPoolSize(), (int) config.getTimeout(TimeUnit.MILLISECONDS), 100, 1000);
    try {
        ResourceFactory<SocketDestination, ClientRequestExecutor> factory = clientRequestExecutorPool.getFactory();
        final AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor> test = new AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor>() {

            @Override
            protected void doSomethingWithResource(SocketDestination key, ClientRequestExecutor resource) throws Exception {
                Thread.sleep(100);
                int random = (int) (Math.random() * 10);
                if (random >= 5)
                    resource.close();
            }

            @Override
            protected SocketDestination getRequestKey() throws Exception {
                return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
            }
        };
        // borrow timeout >> doSomething() no timeout expected
        TestStats testStats = test.startTest(factory, config, 50, 200);
        assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
        server.stop();
    } finally {
        clientRequestExecutorPool.close();
    }
}
Also used : SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) ClientRequestExecutor(voldemort.store.socket.clientrequest.ClientRequestExecutor) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Example 3 with ClientRequestHandlerFactory

use of voldemort.server.protocol.ClientRequestHandlerFactory in project voldemort by voldemort.

the class SimpleSocketPoolTest method testSocketPoolLimitSomeTimeout.

@Test
public void testSocketPoolLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(null), 7666, 50, 50, 1000);
    server.start();
    final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50, TimeUnit.MILLISECONDS).setMaxPoolSize(20);
    ResourceFactory<SocketDestination, SocketAndStreams> factory = ResourcePoolTestUtils.getSocketPoolFactory();
    final AbstractSocketPoolTest<SocketDestination, SocketAndStreams> test = new AbstractSocketPoolTest<SocketDestination, SocketAndStreams>() {

        @Override
        protected void doSomethingWithResource(SocketDestination key, SocketAndStreams resource) throws Exception {
            Thread.sleep(100);
            int random = (int) (Math.random() * 10);
            if (random >= 5)
                resource.getSocket().close();
        }

        @Override
        protected SocketDestination getRequestKey() throws Exception {
            return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
        }
    };
    // borrow timeout >> doSomething() no timeout expected
    TestStats testStats = test.startTest(factory, config, 50, 200);
    assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
    server.stop();
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Aggregations

ClientRequestHandlerFactory (voldemort.server.protocol.ClientRequestHandlerFactory)3 Test (org.junit.Test)2 AbstractSocketService (voldemort.server.AbstractSocketService)2 TestStats (voldemort.socketpool.AbstractSocketPoolTest.TestStats)2 SocketDestination (voldemort.store.socket.SocketDestination)2 ResourcePoolConfig (voldemort.utils.pool.ResourcePoolConfig)2 SocketAndStreams (voldemort.client.protocol.admin.SocketAndStreams)1 RestService (voldemort.rest.server.RestService)1 HttpService (voldemort.server.http.HttpService)1 NioSocketService (voldemort.server.niosocket.NioSocketService)1 RequestHandlerFactory (voldemort.server.protocol.RequestHandlerFactory)1 SocketRequestHandlerFactory (voldemort.server.protocol.SocketRequestHandlerFactory)1 SocketService (voldemort.server.socket.SocketService)1 ClientRequestExecutor (voldemort.store.socket.clientrequest.ClientRequestExecutor)1 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)1