use of voldemort.server.protocol.StreamRequestHandler 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);
}
}
Aggregations