com.streamhub.api
Interface PushServer

All Superinterfaces:
Publisher
All Known Implementing Classes:
NIOServer, SecureNIOServer

public interface PushServer
extends Publisher

The server to which connections are made by clients. This interface represents the core functionality of the Comet and HTTP Push server.

To create and start an implementation of the server use one of the NIOServer constructors

See Also:
NIOServer

Method Summary
 void addContext(String context, com.streamhub.handler.Handler handler)
          Adds or overrides a context.
 void addStaticContent(File directory)
          Adds a directory to be served from the root context / as if it were a standard HTTP server.
 void addStaticContent(File directory, String context)
          Adds a directory to be served from the a specified context as if it were a standard HTTP server.
 SubscriptionManager getSubscriptionManager()
          Returns the servers SubscriptionManager.
 boolean isStarted()
          Identifies whether the server is currently started or not
 void setDefaultHeader(String name, String value)
          Sets the value of a default HTTP header for synchronous responses.
 void setDefaultPushHeader(String name, String value)
          Sets the value of a default HTTP header for asynchronous push responses.
 void start()
          Starts the server
 void stop()
          Stops the server
 
Methods inherited from interface com.streamhub.api.Publisher
publish
 

Method Detail

start

void start()
Starts the server

Note this method is non-blocking


stop

void stop()
          throws IOException
Stops the server

This method will block until all the connections have been forcibly closed and internal threads shutdown

Throws:
IOException

isStarted

boolean isStarted()
Identifies whether the server is currently started or not

Returns:
true if the server is currently started and running, false if it has not been started or has been stopped

getSubscriptionManager

SubscriptionManager getSubscriptionManager()
Returns the servers SubscriptionManager.

The SubscriptionManager provides the core publish and subscribe listening capabilities of the server.

Use SubscriptionManager.addPublishListener(PublishListener) to receive callbacks when a client publishes a message to the server.

Use SubscriptionManager.addSubscriptionListener(SubscriptionListener) to receive callbacks when a client subscribes to a topic.

It is recommended to call this method after starting the server using start()

Returns:
the SubscriptionManager associated with this server

addStaticContent

void addStaticContent(File directory)
Adds a directory to be served from the root context / as if it were a standard HTTP server. This allows static content, for example HTML pages, to be retrieved via a web browser.

Although StreamHub is capable of serving normal static content it was primarily designed as a Comet and HTTP Push server. For a live website or application it is recommended to serve static content from a standard HTTP Web server such as Apache or IIS.

Parameters:
directory - the directory on the local filesytem to make available via the web
See Also:
addStaticContent(File, String)

addStaticContent

void addStaticContent(File directory,
                      String context)
Adds a directory to be served from the a specified context as if it were a standard HTTP server. This allows static content, for example HTML pages, to be retrieved via a web browser.

Although StreamHub is capable of serving normal static content it was primarily designed as a Comet and HTTP Push server. For a live website or application it is recommended to serve static content from a standard HTTP Web server such as Apache or IIS.

Parameters:
directory - the directory on the local filesytem to make available via the web
context - the context to serve the directory under. For example using a context of site would make content available under http://serverurl/site/
See Also:
addStaticContent(File)

setDefaultPushHeader

void setDefaultPushHeader(String name,
                          String value)
Sets the value of a default HTTP header for asynchronous push responses.

Parameters:
name - the name of the header
value - the value of the header

setDefaultHeader

void setDefaultHeader(String name,
                      String value)
Sets the value of a default HTTP header for synchronous responses.

Parameters:
name - the name of the header
value - the value of the header

addContext

void addContext(String context,
                com.streamhub.handler.Handler handler)
Adds or overrides a context. An example of a context is /examples/*. Any incoming requests which match the context will be routed to the handler.

Parameters:
context - a context specifier string e.g. /examples/*
handler - a handler which will handle requests matching the context


Copyright © 2009 StreamHub. Tutorials, news and guides can be found on the StreamHub Comet Blog.