org.cometd.server
Class AbstractServerTransport

java.lang.Object
  extended by org.cometd.server.AbstractServerTransport
All Implemented Interfaces:
ServerTransport, Transport
Direct Known Subclasses:
HttpTransport

public abstract class AbstractServerTransport
extends Object
implements ServerTransport

The base class of all server transports.

Each derived Transport class should declare all options that it supports by calling setOption(String, Object) for each option. Then during the call the init(), each transport should call the variants of getOption(String) to obtained the configured value for the option.


Nested Class Summary
static interface AbstractServerTransport.OneTimeScheduler
           
static interface AbstractServerTransport.Scheduler
           
 
Field Summary
static String INTERVAL_OPTION
           
static String MAX_INTERVAL_OPTION
           
static String MAX_LAZY_OPTION
           
static String META_CONNECT_DELIVERY_OPTION
           
static String TIMEOUT_OPTION
           
 
Constructor Summary
protected AbstractServerTransport(BayeuxServerImpl bayeux, String name)
          Construct a ServerTransport.
 
Method Summary
protected  void doSweep()
          Housekeeping sweep, called a regular intervals
 Object getAdvice()
           
 BayeuxServerImpl getBayeux()
          Get the bayeux.
 long getInterval()
          Get the interval.
 long getMaxInterval()
          Get the maxInterval.
 long getMaxLazyTimeout()
          Get the max time before dispatching lazy message.
 String getName()
           
 Object getOption(String name)
          Get an option value.
 boolean getOption(String option, boolean dftValue)
          Get option or default value.
 int getOption(String option, int dftValue)
          Get option or default value.
 long getOption(String option, long dftValue)
          Get option or default value.
 String getOption(String option, String dftValue)
          Get option or default value.
 Set<String> getOptionNames()
           
 String getOptionPrefix()
           
 long getTimeout()
          Get the timeout.
protected  void init()
          Initialise the transport.
 boolean isMetaConnectDeliveryOnly()
           
 void setAdvice(Object advice)
          Set the advice.
 void setInterval(long interval)
          Set the interval.
 void setMaxInterval(long maxInterval)
          Set the maxInterval.
 void setMaxLazyTimeout(long maxLazyTimeout)
          Set the maxLazyTimeout.
 void setMetaConnectDeliveryOnly(boolean meta)
           
 void setOption(String name, Object value)
           
 void setOptionPrefix(String prefix)
          Set the option name prefix segment.
 void setTimeout(long timeout)
          Set the timeout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.cometd.bayeux.server.ServerTransport
getContext, getCurrentLocalAddress, getCurrentRemoteAddress
 

Field Detail

TIMEOUT_OPTION

public static final String TIMEOUT_OPTION
See Also:
Constant Field Values

INTERVAL_OPTION

public static final String INTERVAL_OPTION
See Also:
Constant Field Values

MAX_INTERVAL_OPTION

public static final String MAX_INTERVAL_OPTION
See Also:
Constant Field Values

MAX_LAZY_OPTION

public static final String MAX_LAZY_OPTION
See Also:
Constant Field Values

META_CONNECT_DELIVERY_OPTION

public static final String META_CONNECT_DELIVERY_OPTION
See Also:
Constant Field Values
Constructor Detail

AbstractServerTransport

protected AbstractServerTransport(BayeuxServerImpl bayeux,
                                  String name)
Construct a ServerTransport.

The construct is passed the BayeuxServerImpl instance for the transport. The BayeuxServerImpl.getOptions() map is populated with the default options known by this transport. The options are then inspected again when init() is called, to set the actual values used. The options are arranged into a naming hierarchy by derived classes adding prefix segments by calling add #addPrefix(String). Calls to getOption(String) will use the list of prefixes to search for the most specific option set.

Method Detail

getAdvice

public Object getAdvice()
Specified by:
getAdvice in interface ServerTransport

getInterval

public long getInterval()
Get the interval.

Specified by:
getInterval in interface ServerTransport
Returns:
the interval

getMaxInterval

public long getMaxInterval()
Get the maxInterval.

Specified by:
getMaxInterval in interface ServerTransport
Returns:
the maxInterval

getMaxLazyTimeout

public long getMaxLazyTimeout()
Get the max time before dispatching lazy message.

Specified by:
getMaxLazyTimeout in interface ServerTransport
Returns:
the max lazy timeout in MS

getName

public String getName()
Specified by:
getName in interface Transport
See Also:
Transport.getName()

getOption

public Object getOption(String name)
Get an option value. Get an option value by searching the option name tree. The option map obtained by calling BayeuxServerImpl.getOptions() is searched for the option name with the most specific prefix. If this transport was initialised with calls:
   addPrefix("long-polling");
   addPrefix("jsonp");
 
then a call to getOption("foobar") will look for the most specific value with names:
   long-polling.json.foobar
   long-polling.foobar
   foobar
 

Specified by:
getOption in interface Transport

getOption

public boolean getOption(String option,
                         boolean dftValue)
Get option or default value.

Parameters:
option - The option name.
dftValue - The default value.
Returns:
option or default value
See Also:
getOption(String)

getOption

public int getOption(String option,
                     int dftValue)
Get option or default value.

Parameters:
option - The option name.
dftValue - The default value.
Returns:
option or default value
See Also:
getOption(String)

getOption

public long getOption(String option,
                      long dftValue)
Get option or default value.

Parameters:
option - The option name.
dftValue - The default value.
Returns:
option or default value
See Also:
getOption(String)

getOption

public String getOption(String option,
                        String dftValue)
Get option or default value.

Parameters:
option - The option name.
dftValue - The default value.
Returns:
option or default value
See Also:
getOption(String)

getOptionNames

public Set<String> getOptionNames()
Specified by:
getOptionNames in interface Transport
See Also:
AbstractTransport.getOptionNames()

getOptionPrefix

public String getOptionPrefix()
Specified by:
getOptionPrefix in interface Transport

setOptionPrefix

public void setOptionPrefix(String prefix)
Set the option name prefix segment.

Normally this is called by the super class constructors to establish a naming hierarchy for options and iteracts with the setOption(String, Object) method to create a naming hierarchy for options. For example the following sequence of calls:

   setOption("foo","x");
   setOption("bar","y");
   setOptionPrefix("long-polling");
   setOption("foo","z");
   setOption("whiz","p");
   setOptionPrefix("long-polling.jsonp");
   setOption("bang","q");
   setOption("bar","r");
 
will establish the following option names and values:
   foo: x
   bar: y
   long-polling.foo: z
   long-polling.whiz: p
   long-polling.jsonp.bang: q
   long-polling.jsonp.bar: r
 
The various getOption(String) methods will search this name tree for the most specific match.

Parameters:
segment - name
Throws:
IllegalArgumentException - if the new prefix is not prefixed by the old prefix.

getTimeout

public long getTimeout()
Get the timeout.

Specified by:
getTimeout in interface ServerTransport
Returns:
the timeout

isMetaConnectDeliveryOnly

public boolean isMetaConnectDeliveryOnly()
Specified by:
isMetaConnectDeliveryOnly in interface ServerTransport

setMetaConnectDeliveryOnly

public void setMetaConnectDeliveryOnly(boolean meta)

setOption

public void setOption(String name,
                      Object value)
Parameters:
name -
value -

init

protected void init()
Initialise the transport. Initialise the transport, resolving default and direct options. After the call to init, the #getMutableOptions() set should be reset to reflect only the options that can be changed on a running transport. This implementation clears the mutable options set.


getBayeux

public BayeuxServerImpl getBayeux()
Get the bayeux.

Returns:
the bayeux

setInterval

public void setInterval(long interval)
Set the interval.

Parameters:
interval - the interval to set

setMaxInterval

public void setMaxInterval(long maxInterval)
Set the maxInterval.

Parameters:
maxInterval - the maxInterval to set

setTimeout

public void setTimeout(long timeout)
Set the timeout.

Parameters:
timeout - the timeout to set

setMaxLazyTimeout

public void setMaxLazyTimeout(long maxLazyTimeout)
Set the maxLazyTimeout.

Parameters:
maxLazyTimeout - the maxLazyTimeout to set

setAdvice

public void setAdvice(Object advice)
Set the advice.

Parameters:
advice - the advice to set

doSweep

protected void doSweep()
Housekeeping sweep, called a regular intervals



Copyright © 2008-2010 Dojo Foundation. All Rights Reserved.