arlut.csd.ganymede.client
Class ClientBase

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--arlut.csd.ganymede.client.ClientBase
All Implemented Interfaces:
Client, java.rmi.Remote, java.io.Serializable

public class ClientBase
extends java.rmi.server.UnicastRemoteObject
implements Client

The core of a client. Provides all the logic necessary to establish a connection to the server and get logged in. By using this class, the server will only need an RMI stub for this class, regardless of what client is written.

See Also:
Serialized Form

Field Summary
private  boolean connected
           
private static boolean debug
           
private  java.util.Vector listeners
           
private  java.lang.String loginRefuseMessage
           
private  java.lang.String password
           
private  Server server
          RMI reference to a Ganymede server
private  Session session
          RMI reference to a client session on a Ganymede server
private  java.lang.String username
           
private  XMLSession xSession
          RMI reference to a client XMLSession on a Ganymede server
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
csf, port, portFactoryParamTypes, portParamTypes, serialVersionUID, ssf
 
Fields inherited from class java.rmi.server.RemoteServer
log, logname
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ClientBase(java.lang.String serverURL, ClientListener listener)
          This constructor takes a URL for the Ganymede server to connect to, a reference to an object implementing the ClientListener interface to report problems.
 
Method Summary
 void addClientListener(ClientListener l)
          Register a client listener.
 void disconnect()
          Calls the logout() method on the Session object.
 void forceDisconnect(java.lang.String reason)
          Allows the server to force us off when it goes down.
 java.lang.String getName()
          Allows the server to retrieve the username.
 java.lang.String getPassword()
          Allows the server to retrieve the password.
 Session getSession()
          This method can be used to retrieve a handle to the client's login session.
 XMLSession getXSession()
          This method can be used to retrieve a handle to the client's login session.
 boolean isConnected()
          This method returns true if the client holds a valid reference to the server.
 boolean isLoggedIn()
          This method returns true if the client has already logged in.
 Session login(java.lang.String username, java.lang.String password)
          This method is used by a client to actually get logged into the server.
 void removeClientListener(ClientListener l)
          Remove a client listener.
private  void sendErrorMessage(java.lang.String message)
          Private method to inform clientListeners if we get an error from the server after construction..
 void sendMessage(int messageType, java.lang.String status)
          Allows the server to send an asynchronous message to the client..
 XMLSession xmlLogin(java.lang.String username, java.lang.String password)
          This method is used by a client to actually get logged into the server.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
, clone, exportObject, exportObject, exportObject, exportObject, readObject, reexport, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub, writeObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

debug

private static final boolean debug

server

private Server server
RMI reference to a Ganymede server

session

private Session session
RMI reference to a client session on a Ganymede server

xSession

private XMLSession xSession
RMI reference to a client XMLSession on a Ganymede server

username

private java.lang.String username

password

private java.lang.String password

connected

private boolean connected

listeners

private java.util.Vector listeners

loginRefuseMessage

private java.lang.String loginRefuseMessage
Constructor Detail

ClientBase

public ClientBase(java.lang.String serverURL,
                  ClientListener listener)
           throws java.rmi.RemoteException

This constructor takes a URL for the Ganymede server to connect to, a reference to an object implementing the ClientListener interface to report problems. The constructor will establish an initial connection to the server and prepare itself for subsequent login before returning.

Parameters:
serverURL - An rmi:// URL for a Ganymede server.
listener - A ClientListener to report problems and disconnection to.
Method Detail

login

public Session login(java.lang.String username,
                     java.lang.String password)
              throws java.rmi.RemoteException

This method is used by a client to actually get logged into the server. The Session handle returned is then used to do all server operations appropriate for a normal client. Calling the Session logout() method will end the client's connection to the server.

Returns:
null if login failed, else a valid server Session reference
See Also:
Session

xmlLogin

public XMLSession xmlLogin(java.lang.String username,
                           java.lang.String password)
                    throws java.rmi.RemoteException

This method is used by a client to actually get logged into the server. The Session handle returned is then used to do all server operations appropriate for a normal client. Calling the Session logout() method will end the client's connection to the server.

Returns:
null if login failed, else a valid server Session reference
See Also:
Session

isLoggedIn

public boolean isLoggedIn()
This method returns true if the client has already logged in.

getSession

public Session getSession()

This method can be used to retrieve a handle to the client's login session. This simply returns the same handle that login() returned, in case the client forgets it or something.


getXSession

public XMLSession getXSession()

This method can be used to retrieve a handle to the client's login session. This simply returns the same handle that login() returned, in case the client forgets it or something.


isConnected

public boolean isConnected()

This method returns true if the client holds a valid reference to the server. This will always return true unless the server has forced a disconnect.


addClientListener

public void addClientListener(ClientListener l)

Register a client listener. A client listener is an object that is to be notified if we get an asynchronous callback from the Ganymede server, such as a forced log-off, or if we need to report an error during login.


removeClientListener

public void removeClientListener(ClientListener l)

Remove a client listener.


disconnect

public void disconnect()
                throws java.rmi.RemoteException

Calls the logout() method on the Session object. This could be done by the client using the Session reference returned by the login() method, but using this method allows us to reflect login status internally.


getName

public java.lang.String getName()

Allows the server to retrieve the username.

Specified by:
getName in interface Client
See Also:
Client

getPassword

public java.lang.String getPassword()

Allows the server to retrieve the password.

Specified by:
getPassword in interface Client
See Also:
Client

forceDisconnect

public void forceDisconnect(java.lang.String reason)

Allows the server to force us off when it goes down.

Specified by:
forceDisconnect in interface Client
See Also:
Client

sendMessage

public void sendMessage(int messageType,
                        java.lang.String status)

Allows the server to send an asynchronous message to the client.. Used by the server to tell the client when a build is/is not being performed on the server.

Specified by:
sendMessage in interface Client
See Also:
Client

sendErrorMessage

private void sendErrorMessage(java.lang.String message)

Private method to inform clientListeners if we get an error from the server after construction..