org.PingOO.DLAI.PPM.io
Class MasterConnectionManager

java.lang.Object
  |
  +--org.PingOO.DLAI.PPM.io.MasterConnectionManager

public final class MasterConnectionManager
extends java.lang.Object
implements ConnectionManager

This is the client side of PingOO.
It manages all readings and writings on the socket connection.
Using this gateway the PPM will send and receive datas to and from the PERL Server.

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

Field Summary
private static int BUFFER_SIZE
          Determines the common maximum size of a buffer.
private  ExtendedDataInputStream dataInputStream
          The InputStream reader needed to receive datas from the server.
private  java.io.DataOutputStream dataOutputStream
          The OutputStream writer needed to emit data towards the server.
private  java.lang.String hostName
          The name of the PERL Server's host.
private  int hostPort
          The port of the PERL Server on the host.
private static java.lang.String LINE_TAG
          Marks the end of the line.
private static java.lang.String MESSAGE_CRYPTED
          The tag which indicates the end of a line buffer.
private static java.lang.String MESSAGE_NORMAL
          The tag which indicates the end of a line buffer.
private  java.net.Socket socket
          The socket for the connection.
 
Constructor Summary
MasterConnectionManager()
          Constructs a new ConnectionManager.
 
Method Summary
 void connect(java.lang.String hostName, int hostPort)
          Connects to the defined server's host and port.
 void disconnect()
          Cuts the connection with the server.
 byte[] get()
          Gets a message from the server complete without the encapsulating tags.
 byte[] get(int size)
          Gets a message from the server complete without the end tag.
 int getBuffer(byte[] message)
          Gets a binary buffer from the server.
 java.lang.String getLine()
          Gets a message line from the server.
 void reconnect()
          Reconnects to the server's host.
 void send(byte[] data)
          Sends a byte array to the server.
 void send(java.lang.String message)
          Sends a String message to the server.
 void sendCrypted(byte[] data)
          Sends an encrypted byte array to the server.
 void sendCrypted(java.lang.String message)
          Sends an encrypted String message to the server.
 void sendLine(java.lang.String message)
          Sends a String message to the server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

hostName

private java.lang.String hostName
The name of the PERL Server's host.

hostPort

private int hostPort
The port of the PERL Server on the host.

socket

private java.net.Socket socket
The socket for the connection.

dataOutputStream

private java.io.DataOutputStream dataOutputStream
The OutputStream writer needed to emit data towards the server.

dataInputStream

private ExtendedDataInputStream dataInputStream
The InputStream reader needed to receive datas from the server.

MESSAGE_NORMAL

private static final java.lang.String MESSAGE_NORMAL
The tag which indicates the end of a line buffer.

MESSAGE_CRYPTED

private static final java.lang.String MESSAGE_CRYPTED
The tag which indicates the end of a line buffer.

LINE_TAG

private static final java.lang.String LINE_TAG
Marks the end of the line.

BUFFER_SIZE

private static final int BUFFER_SIZE
Determines the common maximum size of a buffer.
Constructor Detail

MasterConnectionManager

public MasterConnectionManager()
Constructs a new ConnectionManager.
Method Detail

sendLine

public final void sendLine(java.lang.String message)
                    throws java.io.IOException,
                           java.lang.NullPointerException
Sends a String message to the server.
! this line is NOT encapsulated with:

BEGIN_CRYPTED
...
SIZE

Parameters:
message - The message to send.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.NullPointerException - if message is null.

send

public final void send(byte[] data)
                throws java.io.IOException,
                       java.lang.NullPointerException
Sends a byte array to the server.
! this buffer is encapsulated with:

BEGIN_CRYPTED
...
SIZE

Specified by:
send in interface ConnectionManager
Parameters:
message - The byte array to send.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.NullPointerException - if data is null.

send

public final void send(java.lang.String message)
                throws java.io.IOException,
                       java.lang.NullPointerException
Sends a String message to the server.
! this message is encapsulated with:

BEGIN_CRYPTED
...
SIZE

Specified by:
send in interface ConnectionManager
Parameters:
message - The message to send.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.NullPointerException - if message is null.

sendCrypted

public final void sendCrypted(java.lang.String message)
                       throws java.io.IOException,
                              java.lang.NullPointerException
Sends an encrypted String message to the server.
! This message is encapsulated with :

BEGIN_CRYPTED
...
SIZE

Specified by:
sendCrypted in interface ConnectionManager
Parameters:
message - The message to send.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.NullPointerException - if message is null.

sendCrypted

public final void sendCrypted(byte[] data)
                       throws java.io.IOException,
                              java.lang.NullPointerException
Sends an encrypted byte array to the server.
! This buffer is encapsulated with :

BEGIN_CRYPTED
...
SIZE

Specified by:
sendCrypted in interface ConnectionManager
Parameters:
message - The byte array to send.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.NullPointerException - if data is null.

get

public final byte[] get()
                 throws java.io.IOException
Gets a message from the server complete without the encapsulating tags.
Specified by:
get in interface ConnectionManager
Returns:
The incoming message from the server.
Throws:
java.io.IOException - If an I/O error occurs.

get

public final byte[] get(int size)
                 throws java.io.IOException
Gets a message from the server complete without the end tag.
Parameters:
size - the size of the message we want to get.
Returns:
The incoming message from the server.
Throws:
java.io.IOException - If an I/O error occurs.

getBuffer

public final int getBuffer(byte[] message)
                    throws java.io.IOException
Gets a binary buffer from the server.
Returns:
The total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException - If an I/O error occurs.

getLine

public final java.lang.String getLine()
                               throws java.io.IOException
Gets a message line from the server.
Returns:
The line sent by the server.
Throws:
java.io.IOException - If an I/O error occurs.

connect

public final void connect(java.lang.String hostName,
                          int hostPort)
                   throws java.io.IOException,
                          java.lang.SecurityException,
                          NotConnectedException
Connects to the defined server's host and port.
Parameters:
hostName - The name of the server's host.
hostPort - The port of the server on its host.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.SecurityException - If a security manager exists and its checkConnect method doesn't allow the operation.
NotConnectedException - The host is not defined, or the port is incorrect.

reconnect

public final void reconnect()
                     throws java.io.IOException,
                            java.lang.SecurityException,
                            NotConnectedException
Reconnects to the server's host.
To be used in case of problems. If a reconnection is attempted while there's no host nor port defined, this will cause a NotConnectedException to be raised.
Throws:
java.io.IOException - If an I/O error occurs.
java.lang.SecurityException - If a security manager exists and its checkConnect method doesn't allow the operation.
NotConnectedException - The host is not defined, or the port is incorrect.

disconnect

public final void disconnect()
                      throws java.io.IOException
Cuts the connection with the server.
Specified by:
disconnect in interface ConnectionManager
Throws:
java.io.IOException - If an I/O error occurs.