jfreerails.network
Class LocalConnection

java.lang.Object
  extended by jfreerails.network.LocalConnection
All Implemented Interfaces:
Connection2Client, Connection2Server

public class LocalConnection
extends java.lang.Object
implements Connection2Client, Connection2Server

A connection between the a client and server in the same JVM.

Author:
Luke

Field Summary
private  SychronizedQueue fromClient
           
private  SychronizedQueue fromServer
           
static java.lang.String SERVER_IN_SAME_JVM
           
private  SynchronizedFlag status
           
 
Constructor Summary
LocalConnection()
           
 
Method Summary
 void disconnect()
          Disconnect from the client.
 void flush()
          Flush the underlying stream.
 java.lang.String getServerDetails()
           
 boolean isOpen()
          Returns true if this connection is open.
 FreerailsSerializable[] readFromClient()
          Returns an array containing all the objects read from the client since the last time this method or waitForObjectFromClient() was called, if no objects have been received, it returns an empty array rather than blocking.
 FreerailsSerializable[] readFromServer()
          Returns an array containing all the objects read from the server since the last time this method or waitForObjectFromServer() was called, if no objects have been received, it returns an empty array rather than blocking.
 FreerailsSerializable waitForObjectFromClient()
          Returns the next object read from the client, blocking if non is available.
 FreerailsSerializable waitForObjectFromServer()
          Returns the next object read from the server, blocking if non is available.
 void writeToClient(FreerailsSerializable object)
          Sends the specified object to the client.
 void writeToServer(FreerailsSerializable object)
          Sends the specified object to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_IN_SAME_JVM

public static final java.lang.String SERVER_IN_SAME_JVM
See Also:
Constant Field Values

fromServer

private final SychronizedQueue fromServer

fromClient

private final SychronizedQueue fromClient

status

private final SynchronizedFlag status
Constructor Detail

LocalConnection

public LocalConnection()
Method Detail

readFromClient

public FreerailsSerializable[] readFromClient()
                                       throws java.io.IOException
Description copied from interface: Connection2Client
Returns an array containing all the objects read from the client since the last time this method or waitForObjectFromClient() was called, if no objects have been received, it returns an empty array rather than blocking.

Specified by:
readFromClient in interface Connection2Client
Throws:
java.io.IOException

waitForObjectFromClient

public FreerailsSerializable waitForObjectFromClient()
                                              throws java.io.IOException,
                                                     java.lang.InterruptedException
Description copied from interface: Connection2Client
Returns the next object read from the client, blocking if non is available.

Specified by:
waitForObjectFromClient in interface Connection2Client
Throws:
java.io.IOException
java.lang.InterruptedException

writeToClient

public void writeToClient(FreerailsSerializable object)
                   throws java.io.IOException
Description copied from interface: Connection2Client
Sends the specified object to the client.

Specified by:
writeToClient in interface Connection2Client
Throws:
java.io.IOException

readFromServer

public FreerailsSerializable[] readFromServer()
                                       throws java.io.IOException
Description copied from interface: Connection2Server
Returns an array containing all the objects read from the server since the last time this method or waitForObjectFromServer() was called, if no objects have been received, it returns an empty array rather than blocking.

Specified by:
readFromServer in interface Connection2Server
Throws:
java.io.IOException

waitForObjectFromServer

public FreerailsSerializable waitForObjectFromServer()
                                              throws java.io.IOException,
                                                     java.lang.InterruptedException
Description copied from interface: Connection2Server
Returns the next object read from the server, blocking if non is available.

Specified by:
waitForObjectFromServer in interface Connection2Server
Throws:
java.io.IOException
java.lang.InterruptedException

writeToServer

public void writeToServer(FreerailsSerializable object)
                   throws java.io.IOException
Description copied from interface: Connection2Server
Sends the specified object to the server.

Specified by:
writeToServer in interface Connection2Server
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Description copied from interface: Connection2Client
Returns true if this connection is open.

Specified by:
isOpen in interface Connection2Client
Specified by:
isOpen in interface Connection2Server

flush

public void flush()
Description copied from interface: Connection2Client
Flush the underlying stream.

Specified by:
flush in interface Connection2Client
Specified by:
flush in interface Connection2Server

disconnect

public void disconnect()
Description copied from interface: Connection2Client
Disconnect from the client. When this method returns, calling isOpen() on this object returns false and calling isOpen() on the corresponding Connection2Server held by the client also returns false.

Specified by:
disconnect in interface Connection2Client
Specified by:
disconnect in interface Connection2Server

getServerDetails

public java.lang.String getServerDetails()
Specified by:
getServerDetails in interface Connection2Server