net.sf.j2ep.servers
Class ClusterContainer

java.lang.Object
  extended by net.sf.j2ep.servers.ServerContainerBase
      extended by net.sf.j2ep.servers.ClusterContainer
All Implemented Interfaces:
java.util.EventListener, ServerContainer, ServerStatusListener
Direct Known Subclasses:
RoundRobinCluster

public abstract class ClusterContainer
extends ServerContainerBase
implements ServerStatusListener

A ServerContainer implementation that have multiple domains to choose from. When a request is received one server is chosen to handle the request. If the request is linked to a session this server will make sure that it's the domain that created the session that will process this request.

Author:
Anders Nyman

Nested Class Summary
protected  class ClusterContainer.ClusteredServer
          A server in the cluster.
 
Field Summary
protected  java.util.HashMap servers
          The servers in our cluster,
 
Constructor Summary
ClusterContainer()
          Basic constructor
 
Method Summary
 void addServer(java.lang.String domainName, java.lang.String directory)
          Will create a new ClusteredServer and add it to the hash map.
protected abstract  ClusterContainer.ClusteredServer createNewServer(java.lang.String domainName, java.lang.String directory)
          Will create a new server based on the domainName and the directory.
protected abstract  ClusterContainer.ClusteredServer getNextServer()
          Returns the next server in out cluster.
 Server getServer(HttpServletRequest request)
          Checks the request for any session.
 Server getServerMapped(java.lang.String location)
          Finds a server with the full path specified by the location sent in.
 void serverOffline(Server server)
          Sets the server to offline status.
 void serverOnline(Server server)
          Sets the server to online status.
 
Methods inherited from class net.sf.j2ep.servers.ServerContainerBase
getRule, setRule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

servers

protected java.util.HashMap servers
The servers in our cluster,

Constructor Detail

ClusterContainer

public ClusterContainer()
Basic constructor

Method Detail

createNewServer

protected abstract ClusterContainer.ClusteredServer createNewServer(java.lang.String domainName,
                                                                    java.lang.String directory)
Will create a new server based on the domainName and the directory.

Parameters:
domainName - The domain
directory - The directory
Returns:
The created server

getNextServer

protected abstract ClusterContainer.ClusteredServer getNextServer()
Returns the next server in out cluster. Is used when we can't get a server from the requests session.

Returns:
The next server

getServer

public Server getServer(HttpServletRequest request)
Checks the request for any session. If there is a session created we make sure that the server returned is the one the issued the session. If no session is included in the request we will choose the next server in a round-robin fashion.

Specified by:
getServer in interface ServerContainer
Returns:
The server that is finished to be used.
See Also:
net.sf.j2ep.model.ServerContainer#getServer(javax.servlet.http.HttpServletRequest)

getServerMapped

public Server getServerMapped(java.lang.String location)
Description copied from interface: ServerContainer
Finds a server with the full path specified by the location sent in.

Specified by:
getServerMapped in interface ServerContainer
Parameters:
location - The start of a link that a server is mapped to
Returns:
The server that can handle the link, null if no server is found
See Also:
ServerContainer.getServerMapped(java.lang.String)

serverOffline

public void serverOffline(Server server)
Sets the server to offline status. Will only handle servers that are ClusteredServers

Specified by:
serverOffline in interface ServerStatusListener
Parameters:
server - Server that is now offline
See Also:
ServerStatusListener.serverOffline(net.sf.j2ep.model.Server)

serverOnline

public void serverOnline(Server server)
Sets the server to online status. Will only handle servers that are ClusteredServers

Specified by:
serverOnline in interface ServerStatusListener
Parameters:
server - Server that is now online
See Also:
ServerStatusListener.serverOnline(net.sf.j2ep.model.Server)

addServer

public void addServer(java.lang.String domainName,
                      java.lang.String directory)
Will create a new ClusteredServer and add it to the hash map.

Parameters:
domainName - The domain name for the new server
directory - The director for the new server.