nl.justobjects.pushlet.core
Class Subscriber

java.lang.Object
  extended by nl.justobjects.pushlet.core.Subscriber
All Implemented Interfaces:
ConfigDefs, Protocol

public class Subscriber
extends java.lang.Object
implements Protocol, ConfigDefs

Handles data channel between dispatcher and client.

Version:
$Id: Subscriber.java,v 1.26 2007/11/23 14:33:07 justb Exp $
Author:
Just van den Broecke - Just Objects ©

Field Summary
private  boolean active
          Are we able to accept/send events ?.
private  EventQueue eventQueue
          Blocking queue.
(package private)  long lastAlive
           
private  java.lang.String mode
          Transfer mode (stream, pull, poll).
private  long queueReadTimeoutMillis
          URL to be used in refresh requests in pull/poll modes.
private  long queueWriteTimeoutMillis
           
private  long refreshTimeoutMillis
           
private  Session session
           
private  java.util.Map subscriptions
          Map of active subscriptions, keyed by their subscription id.
 
Fields inherited from interface nl.justobjects.pushlet.core.Protocol
DEFAULT_SERVLET_URI, E_ABORT, E_DATA, E_HEARTBEAT, E_HEARTBEAT_ACK, E_JOIN, E_JOIN_ACK, E_JOIN_LISTEN, E_JOIN_LISTEN_ACK, E_LEAVE, E_LEAVE_ACK, E_LISTEN, E_LISTEN_ACK, E_NACK, E_PUBLISH, E_PUBLISH_ACK, E_REFRESH, E_REFRESH_ACK, E_SUBSCRIBE, E_SUBSCRIBE_ACK, E_UNSUBSCRIBE, E_UNSUBSCRIBE_ACK, FORMAT_JAVASCRIPT, FORMAT_SERIALIZED_JAVA_OBJECT, FORMAT_XML, FORMAT_XML_STRICT, MODE_POLL, MODE_PULL, MODE_STREAM, P_EVENT, P_FORMAT, P_FROM, P_ID, P_MODE, P_REASON, P_SEQ, P_SUBJECT, P_SUBSCRIPTION_ID, P_SUBSCRIPTION_LABEL, P_TIME, P_TO, P_URL, P_WAIT, SUBJECT_META, SUBJECT_META_JOINS, SUBJECT_META_SUBS
 
Fields inherited from interface nl.justobjects.pushlet.core.ConfigDefs
CONTROLLER_CLASS, DISPATCHER_CLASS, LISTEN_FORCE_PULL_AGENTS, LISTEN_FORCE_PULL_ALL, LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_WARN, LOGGER_CLASS, POLL_REFRESH_TIMEOUT_MILLIS, POLL_REFRESH_WAIT_MAX_MILLIS, POLL_REFRESH_WAIT_MIN_MILLIS, PULL_REFRESH_TIMEOUT_MILLIS, PULL_REFRESH_WAIT_MAX_MILLIS, PULL_REFRESH_WAIT_MIN_MILLIS, QUEUE_READ_TIMEOUT_MILLIS, QUEUE_SIZE, QUEUE_WRITE_TIMEOUT_MILLIS, SESSION_CLASS, SESSION_ID_GENERATION, SESSION_ID_GENERATION_RANDOMSTRING, SESSION_ID_GENERATION_UUID, SESSION_ID_SIZE, SESSION_MANAGER_CLASS, SESSION_TIMEOUT_MINS, SOURCES_ACTIVATE, SUBSCRIBER_CLASS, SUBSCRIPTION_CLASS
 
Constructor Summary
protected Subscriber()
          Protected constructor as we create through factory method.
 
Method Summary
 Subscription addSubscription(java.lang.String aSubject, java.lang.String aLabel)
          Add a subscription.
 void bailout()
           
static Subscriber create(Session aSession)
          Create instance through factory method.
protected  void debug(java.lang.String s)
          Exceptional print util.
 void fetchEvents(Command aCommand)
          Get events from queue and push to client.
 java.lang.String getId()
          Get (session) id.
 java.lang.String getMode()
           
 long getRefreshTimeMillis()
           
 Session getSession()
          Return client session.
 Subscription[] getSubscriptions()
          Return subscriptions.
protected  void info(java.lang.String s)
          Info.
 boolean isActive()
          Are we still active to handle events.
 Subscription match(Event event)
          Determine if we should receive event.
 void onEvent(Event theEvent)
          Event from Dispatcher: enqueue it.
 Subscription removeSubscription(java.lang.String aSubscriptionId)
          Remove a subscription.
 void removeSubscriptions()
          Remove all subscriptions.
protected  void sendRefresh(ClientAdapter aClientAdapter, java.lang.String aRefreshURL)
          Send refresh command to pull/poll clients.
 void setMode(java.lang.String aMode)
           
 void start()
           
 void stop()
           
 java.lang.String toString()
           
protected  void warn(java.lang.String s)
          Exceptional print util.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

session

private Session session

eventQueue

private EventQueue eventQueue
Blocking queue.


queueReadTimeoutMillis

private long queueReadTimeoutMillis
URL to be used in refresh requests in pull/poll modes.


queueWriteTimeoutMillis

private long queueWriteTimeoutMillis

refreshTimeoutMillis

private long refreshTimeoutMillis

lastAlive

volatile long lastAlive

subscriptions

private java.util.Map subscriptions
Map of active subscriptions, keyed by their subscription id.


active

private volatile boolean active
Are we able to accept/send events ?.


mode

private java.lang.String mode
Transfer mode (stream, pull, poll).

Constructor Detail

Subscriber

protected Subscriber()
Protected constructor as we create through factory method.

Method Detail

create

public static Subscriber create(Session aSession)
                         throws PushletException
Create instance through factory method.

Parameters:
aSession - the parent Session
Returns:
a Subscriber object (or derived)
Throws:
PushletException - exception, usually misconfiguration

start

public void start()

stop

public void stop()

bailout

public void bailout()

isActive

public boolean isActive()
Are we still active to handle events.


getSession

public Session getSession()
Return client session.


getId

public java.lang.String getId()
Get (session) id.


getSubscriptions

public Subscription[] getSubscriptions()
Return subscriptions.


addSubscription

public Subscription addSubscription(java.lang.String aSubject,
                                    java.lang.String aLabel)
                             throws PushletException
Add a subscription.

Throws:
PushletException

removeSubscription

public Subscription removeSubscription(java.lang.String aSubscriptionId)
Remove a subscription.


removeSubscriptions

public void removeSubscriptions()
Remove all subscriptions.


getMode

public java.lang.String getMode()

setMode

public void setMode(java.lang.String aMode)

getRefreshTimeMillis

public long getRefreshTimeMillis()

fetchEvents

public void fetchEvents(Command aCommand)
                 throws PushletException
Get events from queue and push to client.

Throws:
PushletException

match

public Subscription match(Event event)
Determine if we should receive event.


onEvent

public void onEvent(Event theEvent)
Event from Dispatcher: enqueue it.


sendRefresh

protected void sendRefresh(ClientAdapter aClientAdapter,
                           java.lang.String aRefreshURL)
Send refresh command to pull/poll clients.


info

protected void info(java.lang.String s)
Info.


warn

protected void warn(java.lang.String s)
Exceptional print util.


debug

protected void debug(java.lang.String s)
Exceptional print util.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright 2000-2003 - Just Objects B.V.