net.agmodel.utilBean
Class ServerBean

java.lang.Object
  |
  +--net.agmodel.utilBean.ServerBean
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ChizuBrokerBean, DEMBrokerBean, MetBrokerBean, ResourceBean

public abstract class ServerBean
extends Object
implements Serializable

An invisible abstract bean for managing RMI (direct) and HTTP (indirect) connections to a server or broker.
The bean connects using RMI, and if RMI is blocked then to a wrapper servlet using HTTP.
Note that the bean will only attempt a direct connection if setRMIHost() has been called, and will only attempt an indirect connecion if setHTTPHost() has been called. The connection (and disconnection) process runs in a separate thread which is initiated when setLive(true) is called.
Listening applications are notified when the connection has been established.
To use the bean, applications or applets must implement ServerBeanListener, and register themselves as listeners using #addServerBeanListener(ServerBeanListener) The basic sequence of using this kind of bean is:
1. Create the bean
2. Set the RMIHost and HTTPHost details (ParameterManager is useful for this)
3. Register your application/applet as a ServerBeanListener
4. Start the connection process with setLive(true)
Your application will be notified when the connection has been established, and can then use the bean.

5. When the application has finished using the bean (typically at shutdown), please
call setLive(false) which will cause the bean to disconnect. This helps the server to promptly free-up resources associated with the connection.

See Also:
Serialized Form

Nested Class Summary
 class ServerBean.ConnectThreadEJBHTTP
           
 class ServerBean.ConnectThreadHTTP
           
 class ServerBean.ConnectThreadRMIHTTP
           
 
Field Summary
protected  ServiceHTTP serverHTTP
           
protected  Remote serverRMI
           
protected  String sessionID
           
 
Constructor Summary
ServerBean()
          Creates a "dead" ServerBean object ready to be parameterized with details of the host server.
 
Method Summary
 void addServiceBeanListener(ServiceBeanListener l)
          Register a listener to be notified when a connection to the server has been established.
protected abstract  Remote createEJB(Object obj)
           
protected abstract  void disconnect()
          If the services is a Server, then connects and returns a sessionID.
 void finalize()
          Forces the bean to disconnect immediately.
protected  void fireServiceBeanEvent(ServiceBeanEvent evt)
           
 String getClientInfo()
           
 String getHTTPHost()
           
 String getHTTPHostParamName()
          The preferred name of an applet parameter to hold the host address of the HTTP wrapper servlet associated with this bean.
protected abstract  ServerHTTP getHTTPObject()
           
 int getHTTPPort()
           
 String getHTTPPortParamName()
          The preferred name for an applet parameter to hold the port number of the HTTP wrapper servlet associated with this bean.
 String getLanguage()
           
protected abstract  void getRMIConnection()
          If the services is an RMIServer, then connects and returns a sessionID.
 String getRMIHost()
           
 String getRMIHostParamName()
          The preferred name of an applet parameter to hold the host address of the RMI server associated with this bean.
abstract  String getRMIName()
          Return the name the server registers itself by in RMIRegistry.
protected abstract  Thread getServiceFinderThread()
          Returns a thread object which can find a reference to the service, and in the case of Servers establish a connection to the broker, through whichever mechanisms are available.
protected abstract  boolean isEJB()
           
 boolean isLive()
           
protected abstract  boolean isStateful()
           
 void removeServiceBeanListener(ServiceBeanListener l)
           
 void setClientInfo(String clientInfo)
          Sets the information passed by the bean to the server when a connection is established.
 void setHTTPHost(String host)
          Sets the IP address or host name of the machine that the bean will try to find a wrapper servlet running on.
 void setHTTPPort(int port)
          Sets port number that the bean will try to find a wrapper servlet running on.
 void setLanguage(String language)
          Sets the national language that this user would like to use when receiving information like database names.
 void setLive(boolean makeLive)
          Initiates either connection to (true) or disconnection from (false) the server.
 void setRMIHost(String host)
          Sets the IP address or host name of the machine that the bean will try to find the RMI server running on.
protected  void setUpBean()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverRMI

protected transient volatile Remote serverRMI

serverHTTP

protected transient volatile ServiceHTTP serverHTTP

sessionID

protected transient volatile String sessionID
Constructor Detail

ServerBean

public ServerBean()
Creates a "dead" ServerBean object ready to be parameterized with details of the host server.

Method Detail

getHTTPObject

protected abstract ServerHTTP getHTTPObject()
                                     throws GeneralException
GeneralException

getRMIHostParamName

public String getRMIHostParamName()
The preferred name of an applet parameter to hold the host address of the RMI server associated with this bean.

Returns:
an applet parameter name

getHTTPHostParamName

public String getHTTPHostParamName()
The preferred name of an applet parameter to hold the host address of the HTTP wrapper servlet associated with this bean.

Returns:
an applet parameter name

getHTTPPortParamName

public String getHTTPPortParamName()
The preferred name for an applet parameter to hold the port number of the HTTP wrapper servlet associated with this bean.

Returns:
an applet parameter name

setUpBean

protected void setUpBean()

fireServiceBeanEvent

protected void fireServiceBeanEvent(ServiceBeanEvent evt)

addServiceBeanListener

public void addServiceBeanListener(ServiceBeanListener l)
Register a listener to be notified when a connection to the server has been established.
Note that the connection may have been established either by RMI or via an HTTP wrapper servlet.

Parameters:
l - the listener to be notified

removeServiceBeanListener

public void removeServiceBeanListener(ServiceBeanListener l)

getRMIHost

public String getRMIHost()

getHTTPHost

public String getHTTPHost()

setRMIHost

public void setRMIHost(String host)
Sets the IP address or host name of the machine that the bean will try to find the RMI server running on.
Call this method before calling setLive(true) or it will probably be ignored.

Parameters:
host - eg ume.narc.affrc.go.jp
See Also:
setHTTPHost(String)

getRMIName

public abstract String getRMIName()
Return the name the server registers itself by in RMIRegistry.
Also used as the stem of applet parameters.

Returns:
a short identifier for the server, usually stored as a constant in the corresponding RMI interface.

setHTTPHost

public void setHTTPHost(String host)
Sets the IP address or host name of the machine that the bean will try to find a wrapper servlet running on.
Call this method before calling setLive(true) or it will probably be ignored.

Parameters:
host - a computer which is running the corresponding wrapper servlet in a container like Tomcat eg www.agmodel.net
See Also:
setRMIHost(String)

setHTTPPort

public void setHTTPPort(int port)
Sets port number that the bean will try to find a wrapper servlet running on.
Call this method before calling setLive(true) or it will probably be ignored.

Parameters:
port - a port on the computer which is running the wrapper servlet eg 8080 for accessing Tomcat directly, or 80 if accessing via a web server.
See Also:
setHTTPHost(String)

getHTTPPort

public int getHTTPPort()

setClientInfo

public void setClientInfo(String clientInfo)
Sets the information passed by the bean to the server when a connection is established.
Typically this identifies the name of the client application for logging, tracing or debugging.

Parameters:
clientInfo - something to identify this client application, and perhaps user.

getClientInfo

public String getClientInfo()

setLanguage

public void setLanguage(String language)
Sets the national language that this user would like to use when receiving information like database names.
Typically an application can retrieve a useful value from the JVM using Locale.getDefault().getLanguage()

Parameters:
language - an ISO 2 letter language identifier like "en", "ja", "zn", "ko".

getLanguage

public String getLanguage()

isLive

public boolean isLive()

getServiceFinderThread

protected abstract Thread getServiceFinderThread()
Returns a thread object which can find a reference to the service, and in the case of Servers establish a connection to the broker, through whichever mechanisms are available.
This thread must call fireServerBeanEvent when the connection is established.
This method is called by setLive(true).
A thread is used, because searching for the way to talk to a broker can take a while, and the application should not block while this is happening. It allows multiple beans to find brokers at the same time.

Returns:
a thread, not yet started.

getRMIConnection

protected abstract void getRMIConnection()
                                  throws GeneralException,
                                         RemoteException
If the services is an RMIServer, then connects and returns a sessionID.
Otherwise does nothing.
This method is normally called, if necessary, by the connect thread

GeneralException
RemoteException

disconnect

protected abstract void disconnect()
                            throws Exception
If the services is a Server, then connects and returns a sessionID. Otherwise does nothing. This method is called by setLive(false)

Exception

isStateful

protected abstract boolean isStateful()

isEJB

protected abstract boolean isEJB()

createEJB

protected abstract Remote createEJB(Object obj)
                             throws Exception
Exception

setLive

public void setLive(boolean makeLive)
Initiates either connection to (true) or disconnection from (false) the server.
Make sure to call addServerBeanListener(), setClientInfo(), setLanguage(), setRMIHost(), etc before setLive(true).
This call will return immediately, but connection may take some time. Your listener(s) will be notified when the connection is established.

Parameters:
makeLive - true-allow the connection thread to start, false-allow the disconnection thread to start

finalize

public void finalize()
Forces the bean to disconnect immediately.

Overrides:
finalize in class Object