org.PingOO.DLAI.PPM.net
Class MasterProtocol

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.net.UpperProtocol
        |
        +--org.PingOO.DLAI.PPM.net.MasterProtocol

public final class MasterProtocol
extends UpperProtocol

This is the main PingOO protocol object.
It sends and receives messages to and from the PingOO PERL server conforming to the high-level protocol established for connection with such a server.
It's basically just an automaton which desbribs how the connection work.

Since:
PingOO 2.0
Version:
2.0
Author:
Fabrice Bouyé (bouye@cur-archamps.fr)

Field Summary
private static java.lang.String CLIENT_BEGIN
          The first message sent to the server.
private static java.lang.String CLIENT_RECONNECT
          The first message sent to the server when there is a reconnection.
private static int DIALOG_BEGIN
          This is the begin state in the protocol.
private static int DIALOG_END
          This is the end state in the protocol.
private static int DIALOG_ERROR
          There is a connection error.
private static int DIALOG_LOGIN
          The client must now identify itself and provide login name ad password to the server.
private static int DIALOG_LOGIN_FAILED
          The login procedure failed.
private static int DIALOG_OK
          After all intializations, the client and the server can now dialog.
private static int DIALOG_UPDATE
          An update of the client's packages is needed.
private static java.lang.String hostName
           
private static int hostPort
           
private static java.lang.String ID_SESSION
           
private static java.lang.String NO_UPDATE
           
private static java.lang.String PASSWORD_SALT
           
private  int state
          Current sate in the PingOO protocol.
private static java.lang.String VERSION
           
 
Fields inherited from class org.PingOO.DLAI.lib.net.UpperProtocol
connectionManager, formatter
 
Constructor Summary
MasterProtocol()
          Creates a new protocol.
 
Method Summary
private  void connectionLostErrorRaise()
          Manages not connected error level.
private  void connectionLostErrorRaise(java.io.IOException ioe)
          Manages not connected error level.
 MessageHashtable getUpdate(MessageHashtable message)
          Sends a signed and crypted request to the server and get the answer along the current state in the PingOO protocol
 void initialize(java.lang.String hostName, int hostPort, java.lang.String loginName, java.lang.String loginPassword, java.lang.String PPMVersion)
          Initializes a new MasterProtocol and connect to the server.
private  void loginErrorRaise()
          Manages login error level.
private  void loginErrorRaise(java.lang.String msg)
          Manages login error level.
protected  MessageHashtable makeByeMessage(java.lang.String slaveName)
          Creates the message sent to the server for closing the connection.
 MessageHashtable makeLanguageMessage(java.util.Locale locale)
          Sets the language the server will use with this client and all connection that are in the same session.
protected  MessageHashtable makeLoginMessage(java.lang.String loginName)
          Creates the message sent to the server for login autentification.
protected  MessageHashtable makePasswordMessage(java.lang.String loginPassword)
           
protected  MessageHashtable makeReconnectMessage(java.lang.String slaveName)
           
protected  MessageHashtable makeVersionMessage(java.lang.String version)
          Creates the message sent to the server for version checking.
 ConnectionManager reconnect(java.lang.String slaveName)
          Used when the appli manager wants to open a new channel for a new slave.
 MessageHashtable request(MessageHashtable message)
          Sends an signed but uncrypted request to the server and get the answer along the current state in the PingOO protocol
 MessageHashtable requestCrypted(MessageHashtable message)
          Sends a signed and crypted request to the server and get the answer along the current state in the PingOO protocol
 void terminate()
          Disconnect from the server, close the socket and return in initial mode.
private  void updateNeededRaise()
          Manages login error level.
 
Methods inherited from class org.PingOO.DLAI.lib.net.UpperProtocol
getConnectionManager, getMessageFormatter, request, request, requestCrypted, requestCrypted, terminate
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DIALOG_BEGIN

private static final int DIALOG_BEGIN
This is the begin state in the protocol.
The client is about to connect to the server.

DIALOG_LOGIN

private static final int DIALOG_LOGIN
The client must now identify itself and provide login name ad password to the server.

DIALOG_ERROR

private static final int DIALOG_ERROR
There is a connection error.

DIALOG_UPDATE

private static final int DIALOG_UPDATE
An update of the client's packages is needed.

DIALOG_LOGIN_FAILED

private static final int DIALOG_LOGIN_FAILED
The login procedure failed. The client is not connected anymore to the server.

DIALOG_OK

private static final int DIALOG_OK
After all intializations, the client and the server can now dialog.

DIALOG_END

private static final int DIALOG_END
This is the end state in the protocol.
The client is now diconnected from the server.

state

private int state
Current sate in the PingOO protocol.

CLIENT_BEGIN

private static final java.lang.String CLIENT_BEGIN
The first message sent to the server.

CLIENT_RECONNECT

private static final java.lang.String CLIENT_RECONNECT
The first message sent to the server when there is a reconnection.

ID_SESSION

private static final java.lang.String ID_SESSION

VERSION

private static final java.lang.String VERSION

PASSWORD_SALT

private static final java.lang.String PASSWORD_SALT

NO_UPDATE

private static final java.lang.String NO_UPDATE

hostName

private static java.lang.String hostName

hostPort

private static int hostPort
Constructor Detail

MasterProtocol

public MasterProtocol()
Creates a new protocol.
Method Detail

initialize

public final void initialize(java.lang.String hostName,
                             int hostPort,
                             java.lang.String loginName,
                             java.lang.String loginPassword,
                             java.lang.String PPMVersion)
                      throws NotConnectedException,
                             ConnectionLostException,
                             LoginFailedException,
                             UpdateNeededException
Initializes a new MasterProtocol and connect to the server.
Using the login name and password and the PPM's version, the manager connects to the server, automatically logs in.
If no updates are available, gets the lists of available application for the current user.
Parameters:
hostName - The name of the server's host.
hostPort - The port of the server on its host.
loginName - The user's login.
loginPassword - The user's password.
PPMVersion - the Java PPM's version.
Throws:
NotConnectedException - The PPM can not connect to the server.
ConnectionLostException - The PPM lost its connection to the server
LoginFailedException - The login name or the login password was rejected by the server.
UpdateNeededException - An update has been applyed.

reconnect

public final ConnectionManager reconnect(java.lang.String slaveName)
                                  throws NotConnectedException,
                                         LoginFailedException
Used when the appli manager wants to open a new channel for a new slave.
Throws:
NotConnectedException - The PPM can not connect to the server.
LoginFailedException - The login name or the login password was rejected by the server.

request

public final MessageHashtable request(MessageHashtable message)
                               throws java.lang.NullPointerException,
                                      RequestFailedException,
                                      NotConnectedException,
                                      ConnectionLostException
Sends an signed but uncrypted request to the server and get the answer along the current state in the PingOO protocol
Parameters:
message - The message to send to the server.
Returns:
The request's answer to the request.
Throws:
NotConnectedException - The PPM can not connect to the server.
ConnectionLostException - The PPM lost its connection to the server
Overrides:
request in class UpperProtocol

requestCrypted

public final MessageHashtable requestCrypted(MessageHashtable message)
                                      throws java.lang.NullPointerException,
                                             RequestFailedException,
                                             NotConnectedException,
                                             ConnectionLostException
Sends a signed and crypted request to the server and get the answer along the current state in the PingOO protocol
Parameters:
message - The message to send to the server.
Returns:
The request's answer to the request.
Throws:
NotConnectedException - The PPM can not connect to the server.
ConnectionLostException - The PPM lost its connection to the server
Overrides:
requestCrypted in class UpperProtocol

getUpdate

public final MessageHashtable getUpdate(MessageHashtable message)
                                 throws java.lang.NullPointerException,
                                        RequestFailedException,
                                        NotConnectedException,
                                        ConnectionLostException
Sends a signed and crypted request to the server and get the answer along the current state in the PingOO protocol
Parameters:
message - The message to send to the server.
Returns:
The request's answer to the request.
Throws:
NotConnectedException - The PPM can not connect to the server.
ConnectionLostException - The PPM lost its connection to the server

terminate

public final void terminate()
Disconnect from the server, close the socket and return in initial mode.

connectionLostErrorRaise

private final void connectionLostErrorRaise()
                                     throws ConnectionLostException
Manages not connected error level.
Basically, puts the protocol in an error state and raises a ConnectionLostException.
Throws:
ConnectionLostException - The PPM losts its connection to the server

connectionLostErrorRaise

private final void connectionLostErrorRaise(java.io.IOException ioe)
                                     throws ConnectionLostException
Manages not connected error level.
Basically, puts the protocol in an error state and raises a ConnectionLostException.
Parameters:
ioe -  
Throws:
ConnectionLostException - The PPM lost its connection to the server

loginErrorRaise

private final void loginErrorRaise()
                            throws LoginFailedException
Manages login error level.
This exception is raised when the server rejects the client login.
Throws:
LoginFailedException - The login name or the login password was rejected by the server.

loginErrorRaise

private final void loginErrorRaise(java.lang.String msg)
                            throws LoginFailedException
Manages login error level.
This exception is raised when the server rejects the client login.
Parameters:
msg - The message to pass to the exception.
Throws:
LoginFailedException - The login name or the login password was rejected by the server.

updateNeededRaise

private final void updateNeededRaise()
                              throws UpdateNeededException
Manages login error level.
This exception is raised when the server rejects the client login.
Throws:
UpdateNeededException - An update has been applyed.

makeLoginMessage

protected final MessageHashtable makeLoginMessage(java.lang.String loginName)
Creates the message sent to the server for login autentification.
Parameters:
loginName - The user's login.
loginPassword - The user's password.
Returns:
A MessageHashtable which is the message from the kernel module.

makePasswordMessage

protected final MessageHashtable makePasswordMessage(java.lang.String loginPassword)

makeReconnectMessage

protected final MessageHashtable makeReconnectMessage(java.lang.String slaveName)

makeVersionMessage

protected final MessageHashtable makeVersionMessage(java.lang.String version)
Creates the message sent to the server for version checking.
Returns:
A MessageHashtable which is the message from the kernel module.

makeByeMessage

protected final MessageHashtable makeByeMessage(java.lang.String slaveName)
Creates the message sent to the server for closing the connection.
Returns:
A MessageHashtable which is the message from the kernel module.
Overrides:
makeByeMessage in class UpperProtocol

makeLanguageMessage

public final MessageHashtable makeLanguageMessage(java.util.Locale locale)
Sets the language the server will use with this client and all connection that are in the same session.
Parameters:
locale - The language to be set.
Returns:
A MessageHashtable which is the message from the kernel module.