Ila

org.topoweb.ila.server
Class RequestProcessor

java.lang.Object
  |
  +--org.topoweb.ila.server.RequestProcessor
All Implemented Interfaces:
DefaultConstants, NodeConstants, ProtocolConstants, java.lang.Runnable, org.topoweb.util.concurrent.SingleRun, SpiProtocolConstants

public class RequestProcessor
extends java.lang.Object
implements org.topoweb.util.concurrent.SingleRun, NodeConstants, SpiProtocolConstants, DefaultConstants

An org.topoweb.util.concurrent.SingleRun that processes incoming requests. Receives new IlaSessions representing requests. These requests are processed and enqueued for writing. The processing model here is single threaded.

Currently, this implementation is a quick hack at getting the thing working ASAP. It uses XML/DOM processing which is inherently inefficient. There are a number of ways to improve this. Likely, we'll end up writing a library that arranges read-only byte buffers for XML output. That's an interesting project in its own right, but will be deferred for the time being.

Note:

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

Author:
Babak Farhang

Field Summary
protected static java.util.logging.Logger LOGGER
          The logger used to log messages.
 
Fields inherited from interface org.topoweb.ila.NodeConstants
BACK, FIRST_PAGE, FORE, LAST_PAGE, LINK_MASK, PAGE_MASK
 
Fields inherited from interface org.topoweb.ila.protocol.SpiProtocolConstants
SPC_REGISTER, SPC_REMOVE_BACKLINK, SPC_SET_LINK, SPC_SPI, SPC_SPI_NAMESPACE
 
Fields inherited from interface org.topoweb.ila.protocol.ProtocolConstants
PC_BACKLINK_COUNT, PC_BACKLINKS, PC_CO_BACKLINK_COUNT, PC_CO_FORELINK_COUNT, PC_CONTENT_LENGTH, PC_CONTENT_TYPE, PC_ERROR_CODE, PC_EXPIRATION, PC_FAIL, PC_FIRST, PC_FORELINK_COUNT, PC_FORELINKS, PC_GET_KNOWN, PC_GET_LINK_NODE, PC_GET_LINKS, PC_GET_NODE, PC_HI, PC_HTTP, PC_ID, PC_ILA, PC_INCOMMUNICADO, PC_LAST, PC_LAST_MODIFIED, PC_LINK_NODE, PC_LINK_TYPE, PC_LO, PC_MAX_COUNT, PC_NODE, PC_NODE_SET, PC_OKAY, PC_ORI, PC_PAGE, PC_REGISTER, PC_REQUEST, PC_RESPONSE, PC_SIZE, PC_STATE, PC_STATUS, PC_SYNC_VERSION_ID, PC_SYNC_VERSION_TIMESTAMP, PC_TITLE, PC_USER, PC_USER_AGENT, PC_USER_NAMESPACE, PC_VERSION, PC_VERSION_ID, PC_VERSION_TIMESTAMP
 
Fields inherited from interface org.topoweb.ila.server.DefaultConstants
DEF_MAX_COUNT
 
Constructor Summary
RequestProcessor(org.topoweb.util.concurrent.Takable processPendingQueue, org.topoweb.util.concurrent.Puttable writePendingQueue)
          Creates a new instance with the given parameters.
 
Method Summary
protected  void backOut(org.topoweb.net.server.Session session)
           
protected  void checkVersion(org.w3c.dom.Element env)
          Checks the protocol version.
protected  void doGetKnown(org.w3c.dom.Element func, IlaSession session)
           
protected  void doGetLinkNode(org.w3c.dom.Element func, IlaSession session)
           
protected  void doGetLinks(org.w3c.dom.Element func, IlaSession session)
           
protected  void doGetNode(org.w3c.dom.Element func, IlaSession session)
           
protected  void doRegister(org.w3c.dom.Element func, IlaSession session)
           
protected  void doRemoveBacklink(org.w3c.dom.Element func, IlaSession session)
           
protected  void doSetLink(org.w3c.dom.Element func, IlaSession session)
           
protected  boolean enqueue(org.topoweb.net.server.Session session)
          Enqueue's the given session in the read-completed queue.
protected  int getDefaultMaxCount()
          Returns the default "max count" property.
 void init()
          Initializes the instance.
protected  void initImpl()
          Initialization implementation method.
 boolean isAlive()
           
 void join(int timeout)
           
protected  void processLocalRequest(Request request)
          Processes the given local request.
protected  void processRemoteRequest(Request request)
          Processes the given remote request.
 void run()
          Runs the session processor loop.
 void stop()
           
protected  void writeError(IlaException ix, org.topoweb.net.server.Session session)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

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

Constructor Detail

RequestProcessor

public RequestProcessor(org.topoweb.util.concurrent.Takable processPendingQueue,
                        org.topoweb.util.concurrent.Puttable writePendingQueue)
                 throws java.lang.IllegalArgumentException
Creates a new instance with the given parameters.

Parameters:
processPendingQueue - the queue from which "write-pending" Sessions arrive
writePendingQueue - the queue on which Sessions are sent to once processing is completed
Throws:
java.lang.IllegalArgumentException - if any of the arguments is null
Method Detail

init

public void init()
          throws java.lang.IllegalStateException,
                 IlaException
Initializes the instance.

Throws:
java.lang.IllegalStateException - if this method has already been successfully invoked
IlaException - if an error occurs

initImpl

protected void initImpl()
                 throws IlaException,
                        java.lang.Exception
Initialization implementation method.

Throws:
java.lang.Exception - if an error occurs during startup
IlaException

run

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

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

processLocalRequest

protected void processLocalRequest(Request request)
Processes the given local request.


processRemoteRequest

protected void processRemoteRequest(Request request)
Processes the given remote request.


writeError

protected void writeError(IlaException ix,
                          org.topoweb.net.server.Session session)

backOut

protected void backOut(org.topoweb.net.server.Session session)

getDefaultMaxCount

protected int getDefaultMaxCount()
Returns the default "max count" property. Subclasses may override in order to customize. This base implementation returns DEF_MAX_COUNT.

Returns:
a number greater than zero

doGetKnown

protected void doGetKnown(org.w3c.dom.Element func,
                          IlaSession session)
                   throws IlaException
IlaException

doGetLinkNode

protected void doGetLinkNode(org.w3c.dom.Element func,
                             IlaSession session)
                      throws IlaException
IlaException

doGetLinks

protected void doGetLinks(org.w3c.dom.Element func,
                          IlaSession session)
                   throws IlaException
IlaException

doGetNode

protected void doGetNode(org.w3c.dom.Element func,
                         IlaSession session)
                  throws IlaException
IlaException

doRegister

protected void doRegister(org.w3c.dom.Element func,
                          IlaSession session)
                   throws IlaException
IlaException

doSetLink

protected void doSetLink(org.w3c.dom.Element func,
                         IlaSession session)
                  throws IlaException
IlaException

doRemoveBacklink

protected void doRemoveBacklink(org.w3c.dom.Element func,
                                IlaSession session)
                         throws IlaException
IlaException

checkVersion

protected void checkVersion(org.w3c.dom.Element env)
                     throws IlaException
Checks the protocol version. This usually entails checking the PC_VERSION attribute. The base implementation performs no checks.

Parameters:
env - the envelope (root) element (<ila>)
Throws:
IlaException - if this instance cannot handle the protocol version requested by the client

stop

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

isAlive

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

join

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

enqueue

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

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

Ila

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.