|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object soc.server.genericServer.StringConnection
public abstract class StringConnection
StringConnection allows clients and servers to communicate, with no difference between local and actual networked traffic.
1.0.0 - 2007-11-18 - initial release 1.0.1 - 2008-06-28 - add getConnectTime 1.0.2 - 2008-07-30 - no change in this file 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, wantsHideTimeoutMessage, setHideTimeoutMessage 1.0.5.1- 2009-10-26- javadoc warnings fixed; remove unused import EOFException 1.2.0 - 2013-09-07 - for I18N, addsetI18NStringManager(SOCStringManager, String)
andgetLocalized(String)
. StringConnection is now a superclass, not an interface.
Field Summary | |
---|---|
protected java.lang.Object |
appData
The arbitrary app-specific data associated with this connection, or null . |
protected java.util.Date |
connectTime
Time of connection to server, or of object creation if that time's not available |
protected java.lang.Object |
data
The arbitrary key data (client "name") associated with this connection, or null . |
protected java.lang.Exception |
error
Any error encountered, or null |
protected boolean |
hideTimeoutMessage
|
protected java.lang.String |
localeStr
The server-side locale for this client connection, for app-specific message formatting, or null . |
protected Server |
ourServer
Is set if server-side. |
protected int |
remoteVersion
|
protected boolean |
remoteVersionKnown
|
protected boolean |
remoteVersionTrack
|
protected SOCStringManager |
stringMgr
The server-side string manager for app-specific client message formatting, or null . |
Constructor Summary | |
---|---|
StringConnection()
|
Method Summary | |
---|---|
abstract boolean |
connect()
Start ability to read from the net; called only by the server. |
abstract void |
disconnect()
Close the socket, set EOF; called after conn is removed from server structures |
abstract void |
disconnectSoft()
Accept no further input, allow output to drain, don't immediately close the socket. |
java.lang.Object |
getAppData()
The optional app-specific changeable data for this connection. |
java.util.Date |
getConnectTime()
|
java.lang.Object |
getData()
The optional key data used to name this connection. |
java.lang.Exception |
getError()
|
java.lang.String |
getI18NLocale()
Get the locale for this connection, as reported to setI18NStringManager(SOCStringManager, String) . |
java.lang.String |
getLocalized(java.lang.String key)
Get a localized string (having no parameters) with the given key. |
java.lang.String |
getLocalized(java.lang.String key,
java.lang.Object... arguments)
Get and format a localized string (with parameters) with the given key. |
java.lang.String |
getLocalizedSpecial(SOCGame game,
java.lang.String key,
java.lang.Object... arguments)
Get and format a localized string (with special SoC-specific parameters) with the given key. |
int |
getVersion()
Give the version number (if known) of the remote end of this connection. |
abstract java.lang.String |
host()
|
abstract boolean |
isConnected()
Are we currently connected and active? |
abstract boolean |
isInputAvailable()
Is input available now, without blocking? Same idea as FilterInputStream.available() . |
boolean |
isVersionKnown()
Is the version known of the remote end of this connection? We may have just assumed it, or taken a default. |
abstract void |
put(java.lang.String str)
Send data over the connection. |
abstract void |
run()
For server-side thread which reads and treats incoming messages |
void |
setAppData(java.lang.Object data)
Set the app-specific non-key data for this connection. |
void |
setData(java.lang.Object data)
Set the optional key data for this connection. |
void |
setHideTimeoutMessage(boolean wantsHide)
If client connection times out at server, should the server not print a message to console? This would be desired, for instance, in automated clients, which would reconnect if they become disconnected. |
void |
setI18NStringManager(SOCStringManager mgr,
java.lang.String loc)
Set the I18N string manager and locale name for this connection, for server convenience. |
void |
setVersion(int version)
Set the version number of the remote end of this connection. |
void |
setVersion(int version,
boolean isKnown)
Set the version number of the remote end of this connection. |
void |
setVersionTracking(boolean doTracking)
For server-side use, should we notify the server when our version is changed by setVersion calls? |
boolean |
wantsHideTimeoutMessage()
If client connection times out at server, should the server not print a message to console? This would be desired, for instance, in automated clients, which would reconnect if they become disconnected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.Object data
null
.
protected java.lang.Object appData
null
.
Not used or referenced by generic server.
protected java.lang.String localeStr
null
.
Not used or referenced by the generic server layer.
App-specific connection data (getAppData()
) can hold a full Locale
object;
see SOCClientData
for an example.
protected SOCStringManager stringMgr
null
.
Not used or referenced by the generic server layer.
protected int remoteVersion
protected boolean remoteVersionKnown
protected boolean remoteVersionTrack
protected boolean hideTimeoutMessage
protected Server ourServer
protected java.lang.Exception error
null
protected java.util.Date connectTime
Constructor Detail |
---|
public StringConnection()
Method Detail |
---|
public abstract java.lang.String host()
public abstract void put(java.lang.String str) throws java.lang.IllegalStateException
str
- Data to send
java.lang.IllegalStateException
- if not yet accepted by serverpublic abstract void run()
public abstract boolean isConnected()
public abstract boolean connect()
public abstract void disconnect()
public abstract void disconnectSoft()
isConnected()
will return false, even if output is still being
sent to the other side.
public java.lang.Object getData()
getAppData()
public java.lang.Object getAppData()
getData()
public void setData(java.lang.Object data)
This is anything your application wants to associate with the connection. The StringConnection system uses this data to name the connection, so it should not change once set.
If you call setData after Server.newConnection1(StringConnection)
,
please call Server.nameConnection(StringConnection)
afterwards
to ensure the name is tracked properly at the server.
data
- The new key data, or nullsetAppData(Object)
public void setAppData(java.lang.Object data)
This is anything your application wants to associate with the connection. The StringConnection system itself does not reference or use this data. You can change it as often as you'd like, or not use it.
data
- The new data, or nullsetData(Object)
public java.lang.String getI18NLocale()
setI18NStringManager(SOCStringManager, String)
.
setI18NStringManager
, which may be null
public void setI18NStringManager(SOCStringManager mgr, java.lang.String loc)
getLocalized(String)
.
mgr
- String manager, or nullloc
- Locale name, used only for getI18NLocale()
public java.lang.String getLocalized(java.lang.String key) throws java.util.MissingResourceException
key
- Key to use for string retrieval
java.util.MissingResourceException
- if no string can be found for key
; this is a RuntimeExceptiongetLocalized(String, Object...)
,
getLocalizedSpecial(SOCGame, String, Object...)
public java.lang.String getLocalized(java.lang.String key, java.lang.Object... arguments) throws java.util.MissingResourceException
key
- Key to use for string retrievalarguments
- Objects to use with {0}, {1}, etc in the localized string
by calling MessageFormat.format(String, Object...)
.
java.util.MissingResourceException
- if no string can be found for key
; this is a RuntimeExceptiongetLocalized(String)
,
getLocalizedSpecial(SOCGame, String, Object...)
public java.lang.String getLocalizedSpecial(SOCGame game, java.lang.String key, java.lang.Object... arguments) throws java.util.MissingResourceException, java.lang.IllegalArgumentException
SOCStringManager.getSpecial(SOCGame, String, Object...)
for details.
Uses locale/strings from our client connection's SOCStringManager
if set,
SOCStringManager.getFallbackServerManagerForClient()
otherwise.
game
- Game object to pass through to SOCStringManager.getSpecial(...)
key
- Key to use for string retrievalarguments
- Objects to use with {0}, {1,rsrcs}, etc in the localized string
java.util.MissingResourceException
- if no string can be found for key
; this is a RuntimeException
java.lang.IllegalArgumentException
- if the localized pattern string has a parse error (closing '}' brace without opening '{' brace, etc)getLocalized(String)
,
getLocalized(String, Object...)
public java.lang.Exception getError()
public java.util.Date getConnectTime()
connect()
public int getVersion()
public void setVersion(int version)
Locking: If we're on server side, and setVersionTracking(boolean)
is true,
caller should synchronize on Server.unnamedConns
.
version
- Version number, or 0 if unknown.
If version is greater than 0, future calls to isVersionKnown()
should return true.public void setVersion(int version, boolean isKnown)
Locking: If we're on server side, and setVersionTracking(boolean)
is true,
caller should synchronize on Server.unnamedConns
.
version
- Version number, or 0 if unknown.isKnown
- Should this version be considered confirmed/known by isVersionKnown()
?public boolean isVersionKnown()
setVersion(int, boolean)
.
public void setVersionTracking(boolean doTracking)
doTracking
- true if we should notify server, false otherwise.
If true, please call both setVersion and
Server.clientVersionAdd(int)
before calling setVersionTracking.
If false, please call Server.clientVersionRem(int)
before
calling setVersionTracking.public abstract boolean isInputAvailable()
FilterInputStream.available()
.
public boolean wantsHideTimeoutMessage()
setHideTimeoutMessage(boolean)
public void setHideTimeoutMessage(boolean wantsHide)
wantsHide
- true to hide, false to print, the log message on idle-disconnectwantsHideTimeoutMessage()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |