com.altair.hwm.comm
Class HWMClientComm

java.lang.Object
  extended by java.lang.Thread
      extended by com.altair.hwm.comm.HWMClientComm
All Implemented Interfaces:
HWMComm, java.lang.Runnable
Direct Known Subclasses:
HWMCommHM

public class HWMClientComm
extends java.lang.Thread
implements HWMComm

Title: HWMClientComm

Description: The thread class that controls all communication to/from the slave application

Company: Altair Engineering class


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
HWMClientComm(HWMCommMgr hwmCommMgr, java.lang.String szSessionName, int nPort)
          Purpose: Constructor.
HWMClientComm(HWMCommMgr hwmCommMgr, java.lang.String szSessionName, int nPort, java.lang.String strAddress)
          Purpose: Constructor.
HWMClientComm(HWMCommMgr hwmCommMgr, java.lang.String szApp, java.lang.String[] arrszArgs, java.lang.String szWorkingDir, java.lang.String szSessionName)
          Purpose: Constructor.
HWMClientComm(HWMCommMgr hwmCommMgr, java.lang.String szApp, java.lang.String[] arrszArgs, java.lang.String szWorkingDir, java.lang.String szSessionName, int nPort)
          Purpose: Constructor.
 
Method Summary
 void AddCommListener(HWMCommListener hwmCommListener)
          Add a CommListener to the listener list.
 void Connect(java.lang.String strAddress, int nPort)
          Establishes connection with the server
 void ConnectToApplication()
          Purpose: Start a new application specified by the user.
 int CreateServerSocket()
          Create a server socket so that client applications can connect
 void Disconnect()
          Purpose: Exits the application.
 java.lang.String GetSessionName()
          Purpose: Returns the session name associated with the HWMClientComm.
 boolean IsActive()
          Purpose: Returns whether or not the HWMClientComm is Active, which means that it has a client application that has identified itself.
 boolean IsPeerAlive()
          Check if the peer is alive
 boolean IsTerminated()
          Purpose: Returns whether or not the HWMClientComm has terminated
 void RemoveCommListener(HWMCommListener hwmCommListener)
          Remove a CommListener from the listener list.
 void run()
          Purpose: Initiates the thread.
 void SendCommand(java.lang.String strMsg)
          Purpose: Sends a command to the client application, adding the command to the m_vectPendingCommand vector.
 HWMResponseHandle SendMessage(java.lang.String strMsg)
          Purpose: Very similar to SendQuery, but also throws an exception if not successful
 HWMResponseHandle SendQuery(java.lang.String strMsg)
          Purpose: Sends a single SYNCHRONOUS query to the slave.
 void StartApplication()
          Purpose: Start a new application specified by the user.
 void Terminate()
          Purpose: Terminate the thread, after the next iteration of the main loop
 void WaitForHandShake()
          After the server socket has been created, wait for the slave application to connect to the server socket and hand-shake with us
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HWMClientComm

public HWMClientComm(HWMCommMgr hwmCommMgr,
                     java.lang.String szApp,
                     java.lang.String[] arrszArgs,
                     java.lang.String szWorkingDir,
                     java.lang.String szSessionName,
                     int nPort)
Purpose: Constructor. This version is designed to accept a port, so if a specific TCP/IP port is desired, it will be used.

Parameters:
hwmCommMgr - -- The reference to the manager that manages this thread
String - szApp -- The application that the client comm thread will be associated with
String[] - arrszArgs -- Any arguments that need to be passed to the application, BEYOND those needed for the communications
String - szWorkingDir -- The directory that the application should be started from
int - nPort -- The port that should be used for the ServerSocket
String - szSessionName -- The Session Name that should be used

HWMClientComm

public HWMClientComm(HWMCommMgr hwmCommMgr,
                     java.lang.String szApp,
                     java.lang.String[] arrszArgs,
                     java.lang.String szWorkingDir,
                     java.lang.String szSessionName)
Purpose: Constructor. This version is designed to force the client comm thread to request a port from the OS

Parameters:
hwmCommMgr - -- The reference to the manager that manages this thread
String - szApp -- The application that the client comm thread will be associated with
String[] - arrszArgs -- Any arguments that need to be passed to the application, BEYOND those needed for the communications
String - szWorkingDir -- The directory that the application should be started from
String - szSessionName -- The Session Name that should be used

HWMClientComm

public HWMClientComm(HWMCommMgr hwmCommMgr,
                     java.lang.String szSessionName,
                     int nPort,
                     java.lang.String strAddress)
Purpose: Constructor. This version is designed to force the client comm thread to connect to an application already started

Parameters:
hwmCommMgr - -- The reference to the manager that manages this thread
String - szSessionName -- The Session Name that should be used
nPort - The port number that the server application is listening to
strAddress - The IP of the server app is listening at

HWMClientComm

public HWMClientComm(HWMCommMgr hwmCommMgr,
                     java.lang.String szSessionName,
                     int nPort)
Purpose: Constructor. This version is designed to force the client comm thread to connect to an application already started

Parameters:
hwmCommMgr - -- The reference to the manager that manages this thread
String - szSessionName -- The Session Name that should be used
nPort - The port number that the server application is listening to
Method Detail

Terminate

public void Terminate()
Purpose: Terminate the thread, after the next iteration of the main loop


GetSessionName

public java.lang.String GetSessionName()
Purpose: Returns the session name associated with the HWMClientComm.


IsActive

public boolean IsActive()
Purpose: Returns whether or not the HWMClientComm is Active, which means that it has a client application that has identified itself.


IsTerminated

public boolean IsTerminated()
Purpose: Returns whether or not the HWMClientComm has terminated


IsPeerAlive

public boolean IsPeerAlive()
Check if the peer is alive

Returns:
boolean Returns true if the peer is alive else false

Disconnect

public void Disconnect()
Purpose: Exits the application. This has not been implemented here yet since we need to design a common way of ending the apps like UG etc. For the time being, the HM exit is done in the class derived for HM

Specified by:
Disconnect in interface HWMComm

Connect

public void Connect(java.lang.String strAddress,
                    int nPort)
             throws java.lang.Exception
Establishes connection with the server

Specified by:
Connect in interface HWMComm
Parameters:
strAddress - The address of the server
nPort - The port number to which to connect to
Throws:
IOException, - UnknownHostException
java.lang.Exception

CreateServerSocket

public int CreateServerSocket()
                       throws java.io.IOException
Create a server socket so that client applications can connect

Returns:
The port number that the server socket has been created
Throws:
java.lang.Exception
java.io.IOException

StartApplication

public void StartApplication()
Purpose: Start a new application specified by the user. This function will also ensure that the appropriate socket connection is established between HWManager and this slave application


WaitForHandShake

public void WaitForHandShake()
                      throws java.io.IOException
After the server socket has been created, wait for the slave application to connect to the server socket and hand-shake with us

Throws:
java.io.IOException

ConnectToApplication

public void ConnectToApplication()
                          throws java.lang.Exception
Purpose: Start a new application specified by the user. This function will also ensure that the appropriate socket connection is established between HWManager and this slave application

Throws:
java.lang.Exception - If any error occurs

run

public void run()
Purpose: Initiates the thread. Called when the .start method is called on the Thread itself

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

SendCommand

public void SendCommand(java.lang.String strMsg)
Purpose: Sends a command to the client application, adding the command to the m_vectPendingCommand vector.

Parameters:
String - strMsg The unformatted message, exactly as it should be seen by the slave application.

SendQuery

public HWMResponseHandle SendQuery(java.lang.String strMsg)
Purpose: Sends a single SYNCHRONOUS query to the slave. This command will block until the slave responds.

Parameters:
String - strMsg The unformatted message, exactly as it should be seen by the slave application.

SendMessage

public HWMResponseHandle SendMessage(java.lang.String strMsg)
                              throws java.lang.Exception
Purpose: Very similar to SendQuery, but also throws an exception if not successful

Parameters:
String - strMsg The unformatted message, exactly as it should be seen by the slave application.
Throws:
java.lang.Exception

AddCommListener

public void AddCommListener(HWMCommListener hwmCommListener)
Add a CommListener to the listener list. The listener is registered for all commands that are received from the socket.

Parameters:
hwmCommListener - - The HWMCommListener to be added

RemoveCommListener

public void RemoveCommListener(HWMCommListener hwmCommListener)
Remove a CommListener from the listener list. This removes a CommListener that was registered for all commands received from the socket

Parameters:
hwmCommListener - - The HWMCommListener to be removed