TopoWeb Commons API
Class SessionReader

All Implemented Interfaces:
java.lang.Runnable, org.topoweb.util.concurrent.SingleRun

public class SessionReader
extends java.lang.Object
implements org.topoweb.util.concurrent.SingleRun

An org.topoweb.util.concurrent.SingleRun that reads from sockets. Receives new Sessions from a queue and registers them with an internally managed selector that detects the readiness of sockets for read operations. Reads from sockets until the completion of an interpretable request is detected, and then enqueue's the socket's associated Session for processing by some other agent.


This class should be run in a single thread and then only once.

Babak Farhang

Field Summary
protected static java.util.logging.Logger LOGGER
          The logger used to log messages.
Constructor Summary
SessionReader(org.topoweb.util.concurrent.Takable readPendingQueue, org.topoweb.util.concurrent.Puttable readCompletedQueue, RequestBoundaryDetector requestDetector, SessionPool sessionPool)
          Creates a new instance with the given parameters.
Method Summary
protected  boolean enqueue(Session session)
          Enqueue's the given session in the read-completed queue.
 void init()
          Initializes the instance.
 boolean isAlive()
 void join(int timeout)
 void run()
          Runs the session reader loop.
 void stop()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected static final java.util.logging.Logger LOGGER
The logger used to log messages. This logger uses this class's package namespace.

Constructor Detail


public SessionReader(org.topoweb.util.concurrent.Takable readPendingQueue,
                     org.topoweb.util.concurrent.Puttable readCompletedQueue,
                     RequestBoundaryDetector requestDetector,
                     SessionPool sessionPool)
              throws java.lang.IllegalArgumentException
Creates a new instance with the given parameters.

readPendingQueue - the queue from which Sessions arrive
readCompletedQueue - the queue on which Sessions are sent once a request has been completely read
requestDetector - the request boundary detector used to tell whether enough bytes have been read to form an interpretable request
sessionPool - the pool to which cancelled Session instances are returned
java.lang.IllegalArgumentException - if any of the arguments is null
Method Detail


public void init()
          throws java.lang.IllegalStateException,
Initializes the instance. A new "read-op" selector is opened.

java.lang.IllegalStateException - if this method has already been invoked - if an I/O error occurs


public void run()
         throws java.lang.IllegalStateException
Runs the session reader loop.

Specified by:
run in interface org.topoweb.util.concurrent.SingleRun
java.lang.IllegalStateException - if the instance was not first initialized; if invoked more than once
See Also:
init(), stop()


public void stop()
          throws java.lang.IllegalStateException
Specified by:
stop in interface org.topoweb.util.concurrent.SingleRun


public boolean isAlive()
Specified by:
isAlive in interface org.topoweb.util.concurrent.SingleRun


public void join(int timeout)
          throws java.lang.InterruptedException
Specified by:
join in interface org.topoweb.util.concurrent.SingleRun


protected boolean enqueue(Session session)
Enqueue's the given session in the read-completed queue. The basic implementation waits roughly 1 second for the queue operation to succeed.

session - the session to be enqueued
true, if successfully enqueued; false, o.w.

TopoWeb Commons API

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.