Search in sources :

Example 1 with RequestHandler

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

the class ServerTestUtils method getJettyServer.

public static Context getJettyServer(String clusterXml, String storesXml, String storeName, RequestFormatType requestFormat, int port) throws Exception {
    StoreRepository repository = getStores(storeName, clusterXml, storesXml);
    // initialize servlet
    Server server = new Server(port);
    server.setSendServerVersion(false);
    Context context = new Context(server, "/", Context.NO_SESSIONS);
    RequestHandler handler = getSocketRequestHandlerFactory(clusterXml, storesXml, repository).getRequestHandler(requestFormat);
    context.addServlet(new ServletHolder(new StoreServlet(handler)), "/stores");
    server.start();
    return context;
}
Also used : Context(org.mortbay.jetty.servlet.Context) Server(org.mortbay.jetty.Server) VoldemortServer(voldemort.server.VoldemortServer) RequestHandler(voldemort.server.protocol.RequestHandler) ServletHolder(org.mortbay.jetty.servlet.ServletHolder) StoreRepository(voldemort.server.StoreRepository) StoreServlet(voldemort.server.http.StoreServlet)

Example 2 with RequestHandler

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

the class SocketServerSession method run.

public void run() {
    try {
        activeSessions.put(sessionId, this);
        DataInputStream inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream(), 64000));
        DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream(), 64000));
        RequestFormatType protocol = negotiateProtocol(inputStream, outputStream);
        RequestHandler handler = handlerFactory.getRequestHandler(protocol);
        logger.info("Client " + socket.getRemoteSocketAddress() + " connected successfully with protocol " + protocol.getCode());
        while (!isInterrupted() && !socket.isClosed() && !isClosed) {
            StreamRequestHandler srh = handler.handleRequest(inputStream, outputStream);
            if (srh != null) {
                if (logger.isTraceEnabled())
                    logger.trace("Request is streaming");
                StreamRequestHandlerState srhs = null;
                try {
                    do {
                        if (logger.isTraceEnabled())
                            logger.trace("About to enter streaming request handler");
                        srhs = srh.handleRequest(inputStream, outputStream);
                        if (logger.isTraceEnabled())
                            logger.trace("Finished invocation of streaming request handler, result is " + srhs);
                    } while (srhs != StreamRequestHandlerState.COMPLETE);
                } catch (VoldemortException e) {
                    srh.handleError(outputStream, e);
                    outputStream.flush();
                    break;
                } finally {
                    srh.close(outputStream);
                }
            }
            outputStream.flush();
        }
        if (isInterrupted())
            logger.info(Thread.currentThread().getName() + " has been interrupted, closing session.");
    } catch (EOFException e) {
        logger.info("Client " + socket.getRemoteSocketAddress() + " disconnected.");
    } catch (IOException e) {
        // if this is an unexpected
        if (!isClosed)
            logger.error(e);
    } finally {
        try {
            if (!socket.isClosed())
                socket.close();
        } catch (Exception e) {
            logger.error("Error while closing socket", e);
        }
        // now remove ourselves from the set of active sessions
        this.activeSessions.remove(sessionId);
    }
}
Also used : StreamRequestHandler(voldemort.server.protocol.StreamRequestHandler) StreamRequestHandler(voldemort.server.protocol.StreamRequestHandler) RequestHandler(voldemort.server.protocol.RequestHandler) BufferedInputStream(java.io.BufferedInputStream) DataOutputStream(java.io.DataOutputStream) EOFException(java.io.EOFException) RequestFormatType(voldemort.client.protocol.RequestFormatType) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) BufferedOutputStream(java.io.BufferedOutputStream) VoldemortException(voldemort.VoldemortException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) EOFException(java.io.EOFException) StreamRequestHandlerState(voldemort.server.protocol.StreamRequestHandler.StreamRequestHandlerState)

Aggregations

RequestHandler (voldemort.server.protocol.RequestHandler)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 Server (org.mortbay.jetty.Server)1 Context (org.mortbay.jetty.servlet.Context)1 ServletHolder (org.mortbay.jetty.servlet.ServletHolder)1 VoldemortException (voldemort.VoldemortException)1 RequestFormatType (voldemort.client.protocol.RequestFormatType)1 StoreRepository (voldemort.server.StoreRepository)1 VoldemortServer (voldemort.server.VoldemortServer)1 StoreServlet (voldemort.server.http.StoreServlet)1 StreamRequestHandler (voldemort.server.protocol.StreamRequestHandler)1 StreamRequestHandlerState (voldemort.server.protocol.StreamRequestHandler.StreamRequestHandlerState)1