org.flexunit.ant
Class FlexUnitSocketServer

java.lang.Object
  extended by org.flexunit.ant.FlexUnitSocketServer

public class FlexUnitSocketServer
extends java.lang.Object

Class responsible for managing the connections to the test runner and any boiler plate in the network interactivity.


Field Summary
private  java.net.Socket clientSocket
           
private static java.lang.String DOMAIN_POLICY
           
private static java.lang.String END_OF_TEST_RUN
           
private static java.lang.String END_OF_TEST_RUN_ACK
           
private  int inboundBufferSize
           
private  java.io.InputStreamReader inboundReader
           
private static char NULL_BYTE
           
private  java.io.OutputStreamWriter outboundWriter
           
private static java.lang.String POLICY_FILE_REQUEST
           
private  int port
           
private  java.net.ServerSocket serverSocket
           
private static java.lang.String START_OF_TEST_RUN_ACK
           
private  int timeout
           
private  boolean waitForPolicyFile
           
 
Constructor Summary
FlexUnitSocketServer(int port, int timeout, int inboundBufferSize, boolean waitForPolicyFile)
           
 
Method Summary
private  void closeClientSocket()
          Closes the client connection and all buffers, ignoring any errors
private  void closeServerSocket()
          Closes the server socket.
private  void openClientSocket()
          Creates the client connection.
private  void openServerSocket()
          Creates a connection on the specified socket.
private  void prepareClientSocket()
          Decides whether to send a policy request or a start ack
 java.lang.String readNextTokenFromSocket()
          Reads tokens from the socket input stream based on NULL_BYTE as a delimiter
private  void resetInboundStream()
          Resets the client connection.
private  void sendOutboundMessage(java.lang.String message)
           
private  void sendPolicyFile()
          Generate domain policy message and send
private  void sendTestRunEndAcknowledgement()
          Sends the end of test run to the listener to close the connection
private  void sendTestRunStartAcknowledgement()
          Generate and send message to inform test runner to begin sending test data
 void start()
          Starts the socket server, managing policy file requests, and starting the test process.
 void stop()
          Stops the socket server, notifying the test runner, and closing the appropriate connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_BYTE

private static final char NULL_BYTE
See Also:
Constant Field Values

POLICY_FILE_REQUEST

private static final java.lang.String POLICY_FILE_REQUEST
See Also:
Constant Field Values

DOMAIN_POLICY

private static final java.lang.String DOMAIN_POLICY
See Also:
Constant Field Values

START_OF_TEST_RUN_ACK

private static final java.lang.String START_OF_TEST_RUN_ACK
See Also:
Constant Field Values

END_OF_TEST_RUN

private static final java.lang.String END_OF_TEST_RUN
See Also:
Constant Field Values

END_OF_TEST_RUN_ACK

private static final java.lang.String END_OF_TEST_RUN_ACK
See Also:
Constant Field Values

port

private int port

timeout

private int timeout

inboundBufferSize

private int inboundBufferSize

waitForPolicyFile

private boolean waitForPolicyFile

serverSocket

private java.net.ServerSocket serverSocket

clientSocket

private java.net.Socket clientSocket

inboundReader

private java.io.InputStreamReader inboundReader

outboundWriter

private java.io.OutputStreamWriter outboundWriter
Constructor Detail

FlexUnitSocketServer

public FlexUnitSocketServer(int port,
                            int timeout,
                            int inboundBufferSize,
                            boolean waitForPolicyFile)
Method Detail

start

public void start()
           throws java.io.IOException
Starts the socket server, managing policy file requests, and starting the test process.

Throws:
java.io.IOException

resetInboundStream

private void resetInboundStream()
                         throws java.io.IOException
Resets the client connection.

Throws:
java.io.IOException

openServerSocket

private void openServerSocket()
                       throws java.io.IOException
Creates a connection on the specified socket. Waits {socketTimeout} seconds for a client connection before throwing an error

Throws:
java.io.IOException

openClientSocket

private void openClientSocket()
                       throws java.io.IOException
Creates the client connection. This method will pause until the connection is made or the timout limit is reached. Once a connection is established opens the in and out buffer.

Throws:
java.io.IOException

prepareClientSocket

private void prepareClientSocket()
                          throws java.io.IOException
Decides whether to send a policy request or a start ack

Throws:
java.io.IOException

sendPolicyFile

private void sendPolicyFile()
                     throws java.io.IOException
Generate domain policy message and send

Throws:
java.io.IOException

sendTestRunStartAcknowledgement

private void sendTestRunStartAcknowledgement()
                                      throws java.io.IOException
Generate and send message to inform test runner to begin sending test data

Throws:
java.io.IOException

readNextTokenFromSocket

public java.lang.String readNextTokenFromSocket()
                                         throws java.io.IOException
Reads tokens from the socket input stream based on NULL_BYTE as a delimiter

Throws:
java.io.IOException

sendOutboundMessage

private void sendOutboundMessage(java.lang.String message)
                          throws java.io.IOException
Throws:
java.io.IOException

stop

public void stop()
          throws java.io.IOException
Stops the socket server, notifying the test runner, and closing the appropriate connections.

Throws:
java.io.IOException

sendTestRunEndAcknowledgement

private void sendTestRunEndAcknowledgement()
                                    throws java.io.IOException
Sends the end of test run to the listener to close the connection

Throws:
java.io.IOException

closeClientSocket

private void closeClientSocket()
                        throws java.io.IOException
Closes the client connection and all buffers, ignoring any errors

Throws:
java.io.IOException

closeServerSocket

private void closeServerSocket()
                        throws java.io.IOException
Closes the server socket. Ignores any errors if unable to close

Throws:
java.io.IOException