TopoWeb Commons API
Class SessionWriter

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

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

An org.topoweb.util.concurrent.SingleRun that writes to sockets. Receives new Sessions from a queue and registers them with an internally managed selector that detects the readiness of sockets for write operations.


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
SessionWriter(org.topoweb.util.concurrent.Takable writePendingQueue, org.topoweb.util.concurrent.Puttable readPendingQueue, SessionFilter nextReadFilter, 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 SessionWriter(org.topoweb.util.concurrent.Takable writePendingQueue,
                     org.topoweb.util.concurrent.Puttable readPendingQueue,
                     SessionFilter nextReadFilter,
                     SessionPool sessionPool)
              throws java.lang.IllegalArgumentException
Creates a new instance with the given parameters.

writePendingQueue - the queue from which "write-pending" Sessions arrive
readPendingQueue - the queue on which Sessions are sent if the client is allowed another request
nextReadFilter - the filter used to decide whether any given Session should be scheduled for another 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.