|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectsoc.server.genericServer.LocalStringConnection
Symmetric buffered connection sending strings between two local peers. Uses vectors and thread synchronization, no actual network traffic. This class has a run method, but you must start the thread yourself. Constructors will not create or start a thread.
1.0.0 - 2007-11-18 - initial release 1.0.1 - 2008-06-28 - add getConnectTime 1.0.2 - 2008-07-30 - check if s already null in disconnect 1.0.3 - 2008-08-08 - add disconnectSoft, getVersion, setVersion
| Field Summary | |
protected boolean |
accepted
Active connection, server has called accept, and not disconnected yet |
protected java.util.Date |
connectTime
|
protected java.lang.Object |
data
the abritrary app-specific data associated with this connection |
protected static java.lang.Object |
EOF_MARKER
|
protected java.lang.Exception |
error
|
protected java.util.Vector |
in
|
protected boolean |
in_reachedEOF
|
private LocalStringConnection |
ourPeer
|
protected Server |
ourServer
|
protected java.util.Vector |
out
|
protected boolean |
out_setEOF
|
protected int |
remoteVersion
|
| Constructor Summary | |
LocalStringConnection()
Create a new, unused LocalStringConnection. |
|
LocalStringConnection(LocalStringConnection peer)
Constructor for an existing peer; we'll share two Vectors for in/out queues. |
|
| Method Summary | |
boolean |
connect()
Local version; nothing special to do to start reading messages. |
void |
connect(java.lang.String serverSocketName)
Connect to specified stringport. |
void |
disconnect()
close the socket, discard pending buffered data, set EOF. |
void |
disconnectSoft()
Accept no further input, allow output to drain, don't immediately close the socket. |
java.util.Date |
getConnectTime()
|
java.lang.Object |
getData()
|
java.lang.Exception |
getError()
|
LocalStringConnection |
getPeer()
Remember, the peer's in is our out, and vice versa. |
Server |
getServer()
Server-side: Reference to the server handling this connection. |
int |
getVersion()
Give the version number (if known) of the remote end of this connection. |
java.lang.String |
host()
Hostname of the remote side of the connection - Always returns localhost; this method required for StringConnection interface. |
boolean |
isAccepted()
Is currently accepted by a server |
boolean |
isConnected()
Are we currently connected and active? |
boolean |
isInEOF()
Have we received an EOF marker inbound? |
boolean |
isOutEOF()
Have we closed our outbound side? |
void |
put(java.lang.String dat)
Send data over the connection. |
java.lang.String |
readNext()
Read the next string sent from the remote end, blocking if necessary to wait. |
void |
run()
For server-side (ourServer != null); continuously read and treat input. |
void |
setAccepted()
Intended for server to call: Set our accepted flag. |
void |
setData(java.lang.Object dat)
Set the app-specific data for this connection. |
void |
setEOF()
Signal the end of outbound data. |
void |
setServer(Server srv)
Server-side: Set the generic server for this connection. |
void |
setVersion(int version)
Set the version number of the remote end of this connection. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static java.lang.Object EOF_MARKER
protected java.util.Vector in
protected java.util.Vector out
protected boolean in_reachedEOF
protected boolean out_setEOF
protected boolean accepted
private LocalStringConnection ourPeer
protected Server ourServer
protected java.lang.Exception error
protected java.util.Date connectTime
protected int remoteVersion
protected java.lang.Object data
| Constructor Detail |
public LocalStringConnection()
connect(String)
public LocalStringConnection(LocalStringConnection peer)
throws java.io.EOFException
peer - The peer to use.
java.io.EOFException - If peer is at EOF already
java.lang.IllegalArgumentException - if peer is null, or already
has a peer.| Method Detail |
public java.lang.String readNext()
throws java.io.EOFException,
java.lang.IllegalStateException
java.io.EOFException - Our input buffer has reached EOF
java.lang.IllegalStateException - Server has not yet accepted our connection
public void put(java.lang.String dat)
throws java.lang.IllegalStateException
put in interface StringConnectiondat - Data to send
java.lang.IllegalStateException - if not yet accepted by serverpublic void disconnect()
disconnect in interface StringConnectionpublic void disconnectSoft()
isConnected() will return false, even if output is still being
sent to the other side.
disconnectSoft in interface StringConnection
public void connect(java.lang.String serverSocketName)
throws java.net.ConnectException,
java.lang.IllegalStateException
serverSocketName - stringport name to connect to
java.net.ConnectException - If stringport name is not found, or is EOF,
or if its connect/accept queue is full.
java.lang.IllegalStateException - If this object is already connectedpublic LocalStringConnection getPeer()
public boolean isAccepted()
public void setAccepted()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - If we can't be, or already are, acceptedpublic void setEOF()
public boolean isInEOF()
public boolean isOutEOF()
setEOF()public java.lang.Object getData()
getData in interface StringConnectionsetData(Object)public void setData(java.lang.Object dat)
setData in interface StringConnectiondat - The new data, or nullpublic Server getServer()
public void setServer(Server srv)
srv - The new server, or nullpublic java.lang.Exception getError()
getError in interface StringConnectionpublic java.util.Date getConnectTime()
getConnectTime in interface StringConnectionStringConnection.connect()public java.lang.String host()
host in interface StringConnectionpublic boolean connect()
connect in interface StringConnectionconnect(String)public boolean isConnected()
isConnected in interface StringConnectionpublic int getVersion()
getVersion in interface StringConnectionpublic void setVersion(int version)
setVersion in interface StringConnectionversion - Version number, or 0 if unknown.public void run()
run in interface StringConnection
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||