com.eyebolt.iplib
Class IPKey

java.lang.Object
  |
  +--com.eyebolt.iplib.IPKey

public class IPKey
extends java.lang.Object

Connection 'key' that is the connection ID.

Version:
0.01, 4 Jan 1997
Author:
John Gardner

Field Summary
private static int BUFFER_SIZE
          Description of the Field
private  java.util.zip.CRC32 crcChecker
          class to check CRC
static int FAIL
          Return code signifying failure.
private  boolean haveHeader
          have we found a message header in the network stream
private  byte[] headerBuffer
          a buffer to store received header
private  int headerLen
          stores the length of the header of the message currently working on
private  java.io.InputStream inStream
          input stream for socket
private  IPManager ipmanager
          parent ipmanager instance
private  int key
          key identifier
private static int keyID
          unique key identifier
private  byte[] messageBuffer
          a receive buffer
private  int messageHere
          # of bytes received ...
private  int messageSize
          # of bytes received
private  boolean needHeader
          are we currently looking for a header in the network stream
private  IPCallback onreceive
          default observable 'callback' for unexpected traffic
private  java.io.OutputStream outStream
          output stream for socket
private  byte[] receiveBuffer
          a receive buffer
private  int receiveOffset
          byte offset in locbuf that contains data
private  IPAddress remoteAddress
          Address of the other end
private  boolean serverMode
          flag to indicate this is a 'server' mode socket, and should be prepared to serve requests.
private  java.net.Socket socket
          the socket for which this is a key
static int SUCCESS
          Return code signifying success.
 
Constructor Summary
(package private) IPKey(IPManager ipm, java.net.Socket sock, boolean serverMode)
          Construct an IPKey on a socket
 
Method Summary
private static boolean _checkHdr(MessageHeader msgHdr)
          Description of the Method
(package private)  void _distributeMsg(IPMessage msg)
          Description of the Method
(package private)  int _isActive()
          Description of the Method
private  int _receive_BASE()
          _receive_BASE - a big honkin method to read from the stream This does message oriented receiving; receive a header, and keep receiving until the complete message arrives.
private  int _receive_HTTP()
          _receive_HTTP - a big honkin method to read from the stream This does message oriented receiving; receive a header, and keep receiving until the complete message arrives.
private  int _receive_RAW()
          Raw receive; just reads bytes.
private  int _receive_TEXT()
          Receives on a socket in text mode (line oriented).
(package private)  int _receive()
          Determines which implementation is being used, and forwards to the apropriate receive implementation.
private  void _send_BASE(IPMessage msg)
          Description of the Method
private  void _send_HTTP(IPMessage msg)
          Description of the Method
private  void _send_RAW(IPMessage msg)
          Description of the Method
private  void _send(IPMessage msg)
          Description of the Method
 void checkConnection()
          Validate a key by excercising the connection.
 void disconnect()
          Disconnect this connection.
(package private)  IPManager getIPManager()
          Gets the IPManager attribute of the IPKey object
 int getKey()
          Return an ID for this IPKey
private static int getNextKeyId()
          Description of the Method
 IPAddress getRemoteAddress()
          Return the address of the remote machine.
 java.net.Socket getSocket()
          Return a reference to the socket for which this is a key
 int onReceive(IPCallback cb)
          Specify a callback function for messages received on this Key.
 int reply(IPMessage msg, IPMessage org)
          Send a Reply to a specific message
 int send(IPMessage msg)
          Send a message (Reply, if any, goes to default Key or IPManager overall handler).
 int sendAndCall(IPMessage msg, int tout, IPCallback cb)
          Send a message and notify on the observable when the reply is available
 IPMessage sendAndWait(IPMessage msg, int tout)
          Send a message and wait tout secs for a reply
(package private)  void sendDisconnect()
          Send a disconnect
(package private)  void setRemoteAddress(IPAddress address)
          Set the address of the remote machine.
private  void trace(byte[] bytes, int offset, int limit)
          Write a stream of bytes to output.
private  void trace(java.lang.String s)
          Write a trace message to standard output stream.
private  void updateMessageId(IPMessage msg)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

SUCCESS

public static final int SUCCESS
Return code signifying success.

FAIL

public static final int FAIL
Return code signifying failure.

BUFFER_SIZE

private static final int BUFFER_SIZE
Description of the Field

keyID

private static int keyID
unique key identifier

remoteAddress

private IPAddress remoteAddress
Address of the other end

onreceive

private IPCallback onreceive
default observable 'callback' for unexpected traffic

ipmanager

private IPManager ipmanager
parent ipmanager instance

receiveBuffer

private byte[] receiveBuffer
a receive buffer

messageBuffer

private byte[] messageBuffer
a receive buffer

messageSize

private int messageSize
# of bytes received

messageHere

private int messageHere
# of bytes received ... so ... far ... ?

receiveOffset

private int receiveOffset
byte offset in locbuf that contains data

headerBuffer

private byte[] headerBuffer
a buffer to store received header

headerLen

private int headerLen
stores the length of the header of the message currently working on

needHeader

private boolean needHeader
are we currently looking for a header in the network stream

haveHeader

private boolean haveHeader
have we found a message header in the network stream

crcChecker

private java.util.zip.CRC32 crcChecker
class to check CRC

socket

private java.net.Socket socket
the socket for which this is a key

outStream

private java.io.OutputStream outStream
output stream for socket

inStream

private java.io.InputStream inStream
input stream for socket

key

private int key
key identifier

serverMode

private boolean serverMode
flag to indicate this is a 'server' mode socket, and should be prepared to serve requests.
Constructor Detail

IPKey

IPKey(IPManager ipm,
      java.net.Socket sock,
      boolean serverMode)
throws java.io.IOException
Construct an IPKey on a socket
Parameters:
ipm - - ipmanager to which this IPKey belongs
sock - - socket for which the IPKey is the key
Throws:
java.io.IOException - Description of Exception
Method Detail

getIPManager

IPManager getIPManager()
Gets the IPManager attribute of the IPKey object
Returns:
The IPManager value

getKey

public int getKey()
Return an ID for this IPKey
Returns:
The Key value

getSocket

public java.net.Socket getSocket()
Return a reference to the socket for which this is a key
Returns:
The socket value

getRemoteAddress

public IPAddress getRemoteAddress()
Return the address of the remote machine.
Returns:
remote machine address

setRemoteAddress

void setRemoteAddress(IPAddress address)
Set the address of the remote machine.
Parameters:
address - machine address

disconnect

public void disconnect()
Disconnect this connection.

onReceive

public int onReceive(IPCallback cb)
Specify a callback function for messages received on this Key.
Parameters:
cb - - A callback to be called when data is received fo this key.
Returns:
Description of the Returned Value

sendAndWait

public IPMessage sendAndWait(IPMessage msg,
                             int tout)
                      throws java.io.IOException
Send a message and wait tout secs for a reply
Parameters:
msg - - The message to send
tout - - Number of seconds to wait for a reply
Returns:
the message that was received as a response, or a timeout message.
Throws:
java.io.IOException - if a communication error occurs.

sendAndCall

public int sendAndCall(IPMessage msg,
                       int tout,
                       IPCallback cb)
                throws java.io.IOException
Send a message and notify on the observable when the reply is available
Parameters:
msg - - The message to send
tout - - Number of seconds to wait for a reply
cb - a callback object specifying how to call back.
Returns:
an error code, or SUCCESS.
Throws:
java.io.IOException - if a communication error occurs.

send

public int send(IPMessage msg)
         throws java.io.IOException
Send a message (Reply, if any, goes to default Key or IPManager overall handler).
Parameters:
msg - message to send
Returns:
an error code, or SUCCESS if successful
Throws:
java.io.IOException - Description of Exception

reply

public int reply(IPMessage msg,
                 IPMessage org)
Send a Reply to a specific message
Parameters:
msg - This is the message that is the reply
org - the original message (used to identify source)
Returns:
an error code, or SUCCESS

checkConnection

public void checkConnection()
                     throws java.io.IOException
Validate a key by excercising the connection.

_receive

int _receive()
Determines which implementation is being used, and forwards to the apropriate receive implementation.
Returns:
An error code, or SUCCESS if successful

_receive_TEXT

private int _receive_TEXT()
Receives on a socket in text mode (line oriented).
Returns:
An error code, or SUCCESS if successful

_receive_RAW

private int _receive_RAW()
Raw receive; just reads bytes.
Returns:
An error code, or SUCCESS if successful

_receive_BASE

private int _receive_BASE()
_receive_BASE - a big honkin method to read from the stream This does message oriented receiving; receive a header, and keep receiving until the complete message arrives.
Returns:
An error code, or SUCCESS if successful

_receive_HTTP

private int _receive_HTTP()
_receive_HTTP - a big honkin method to read from the stream This does message oriented receiving; receive a header, and keep receiving until the complete message arrives.
Returns:
An error code, or SUCCESS if successful

_isActive

int _isActive()
Description of the Method
Returns:
Description of the Returned Value

sendDisconnect

void sendDisconnect()
Send a disconnect

updateMessageId

private void updateMessageId(IPMessage msg)

getNextKeyId

private static int getNextKeyId()
Description of the Method
Returns:
the next key id

_distributeMsg

final void _distributeMsg(IPMessage msg)
Description of the Method
Parameters:
msg - Description of Parameter

_send

private void _send(IPMessage msg)
            throws java.io.IOException
Description of the Method
Parameters:
msg - Description of Parameter
Throws:
java.io.IOException - Description of Exception

_send_RAW

private void _send_RAW(IPMessage msg)
                throws java.io.IOException
Description of the Method
Parameters:
msg - Description of Parameter
Throws:
java.io.IOException - Description of Exception

_send_BASE

private void _send_BASE(IPMessage msg)
                 throws java.io.IOException
Description of the Method
Parameters:
msg - Description of Parameter
Throws:
java.io.IOException - Description of Exception

_send_HTTP

private void _send_HTTP(IPMessage msg)
                 throws java.io.IOException
Description of the Method
Parameters:
msg - Description of Parameter
Throws:
java.io.IOException - Description of Exception

trace

private final void trace(java.lang.String s)
Write a trace message to standard output stream.
Parameters:
s - string to write

trace

private final void trace(byte[] bytes,
                         int offset,
                         int limit)
Write a stream of bytes to output.
Parameters:
buf - bytes to write

_checkHdr

private static boolean _checkHdr(MessageHeader msgHdr)
Description of the Method
Parameters:
msgHdr - Description of Parameter
Returns:
Description of the Returned Value


Copyright © 2001 Eyebolt, Inc.