|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.server.genericServer.StringConnection soc.server.genericServer.LocalStringConnection
public class 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.
As used within JSettlers, the structure of this class has much in common
with LocalStringConnection
, as they both subclass StringConnection
.
If you add something to one class, you should probably add it to the other, or to the superclass instead.
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 1.0.4 - 2008-09-04 - add appData 1.0.5 - 2009-05-31 - add isVersionKnown, setVersion(int,bool), setVersionTracking, isInputAvailable, callback to processFirstCommand, wantsHideTimeoutMessage, setHideTimeoutMessage; common constructor code moved to init(). 1.0.5.1- 2009-10-26- javadoc warnings fixed 1.0.5.2- 2010-04-05- add toString for debugging 1.2.0 - 2013-09-07 - for I18N, addStringConnection.setI18NStringManager(SOCStringManager, String)
andStringConnection.getLocalized(String)
. StringConnection is now a superclass, not an interface
Field Summary | |
---|---|
protected boolean |
accepted
Active connection, server has called accept, and not disconnected yet |
protected static java.lang.String |
EOF_MARKER
Unique end-of-file marker object. |
protected java.util.Vector<java.lang.String> |
in
|
protected boolean |
in_reachedEOF
|
private LocalStringConnection |
ourPeer
|
protected java.util.Vector<java.lang.String> |
out
|
protected boolean |
out_setEOF
|
Fields inherited from class soc.server.genericServer.StringConnection |
---|
appData, connectTime, data, error, hideTimeoutMessage, localeStr, ourServer, remoteVersion, remoteVersionKnown, remoteVersionTrack, stringMgr |
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. |
LocalStringConnection |
getPeer()
Remember, the peer's in is our out, and vice versa. |
Server |
getServer()
Server-side: Reference to the server handling this connection. |
java.lang.String |
host()
Hostname of the remote side of the connection - Always returns localhost; this method required for StringConnection interface. |
private void |
init()
Constructor common-fields initialization |
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 |
isInputAvailable()
Is input available now, without blocking? Same idea as FilterInputStream.available() . |
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; continuously read and treat input. |
void |
setAccepted()
Intended for server to call: Set our accepted flag. |
void |
setEOF()
Signal the end of outbound data. |
void |
setServer(Server srv)
Server-side: Set the generic server for this connection. |
java.lang.String |
toString()
toString includes data.toString for debugging. |
Methods inherited from class soc.server.genericServer.StringConnection |
---|
getAppData, getConnectTime, getData, getError, getI18NLocale, getLocalized, getLocalized, getLocalizedSpecial, getVersion, isVersionKnown, setAppData, setData, setHideTimeoutMessage, setI18NStringManager, setVersion, setVersion, setVersionTracking, wantsHideTimeoutMessage |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static java.lang.String EOF_MARKER
protected java.util.Vector<java.lang.String> in
protected java.util.Vector<java.lang.String> out
protected boolean in_reachedEOF
protected boolean out_setEOF
protected boolean accepted
private LocalStringConnection ourPeer
Constructor Detail |
---|
public LocalStringConnection()
connect(String)
to use this object.
This class has a run method, but you must start the thread yourself.
Constructors will not create or start a thread.
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 |
---|
private void init()
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 connectionpublic void put(java.lang.String dat) throws java.lang.IllegalStateException
put
in class StringConnection
dat
- Data to send
java.lang.IllegalStateException
- if not yet accepted by serverpublic void disconnect()
disconnect
in class StringConnection
public void disconnectSoft()
isConnected()
will return false, even if output is still being
sent to the other side.
disconnectSoft
in class 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 Server getServer()
public void setServer(Server srv)
srv
- The new server, or nullStringConnection.setVersionTracking(boolean)
public java.lang.String host()
host
in class StringConnection
public boolean connect()
connect
in class StringConnection
connect(String)
public boolean isConnected()
isConnected
in class StringConnection
public boolean isInputAvailable()
FilterInputStream.available()
.
isInputAvailable
in class StringConnection
public void run()
run
in interface java.lang.Runnable
run
in class StringConnection
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |