io
Class AbstractSocketDriver

java.lang.Object
  extended by util.PropertyContainer
      extended by io.AbstractDriver
          extended by io.AbstractSocketDriver
All Implemented Interfaces:
Driver, Cloneable, ExitCleaning, Initializable, PropertyBearing
Direct Known Subclasses:
ServerClient

public abstract class AbstractSocketDriver
extends AbstractDriver
implements ExitCleaning

An abstract driver that is based on a client socket connection. Provides methods for opening the socket and changing the timeout.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyContainer
PropertyContainer.URLResource
 
Field Summary
private static long DEFCLOSETIMEOUT
          Defaults to no wait before closing.
private  InputStream in
          On open, the input stream opened.
static String KEY_CLOSETIMEOUT
          Wait before close.
static String KEY_SOCKETPORT
          Port of the server.
static String KEY_SOCKETSERVER
          Key to the host.
static String KEY_SOCKETTIMEOUT
          Timeout.
private  OutputStream out
          On open, the output stream opened.
private  Socket socket
          This is the connected socket.
 
Fields inherited from class io.AbstractDriver
KEY_DRIVERNAME
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR, KEY_NOINITONCREATE, KEY_RESOURCEBUNDLES
 
Fields inherited from interface util.PropertyBearing
CONFIG, KEY_CLASS, KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected AbstractSocketDriver(Map prop)
          Creates a new socket server.
 
Method Summary
protected  boolean authenticate()
          Authenticates at the remote host.
 boolean close()
          Disconnect from remote host.
 void exit()
          On exit we always close.
protected  InputStream getInputStream()
          Returns the input stream for this socket driver.
protected  OutputStream getOutputStream()
          Returns the output stream for this socket driver.
protected  Socket getSocket()
          Returns the socket.
 void init()
          On init, we check if we have all the required properties set.
 boolean isOpen()
          Returns true if the connection is open.
 boolean open()
          Connect to remote host.
 void setTimeout(int mils)
          Set default timeout for socket reads
 
Methods inherited from class io.AbstractDriver
createDriver, equals, getDriverName, hashCode
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, clone, createFrom, createFrom, createFrom, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getLocalClassLoader, getLocalized, getLocalized, getLocalizedString, getLocalizedString, getProperties, getPropertiesToKey, getPropertiesToKey, getProperty, getResource, getResourceAsStream, getResourceFromKey, getResources, has, isNew, keyCreate, keyCreate, parseObject, reload, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_SOCKETSERVER

public static final String KEY_SOCKETSERVER
Key to the host.

See Also:
Constant Field Values

KEY_SOCKETPORT

public static final String KEY_SOCKETPORT
Port of the server.

See Also:
Constant Field Values

KEY_SOCKETTIMEOUT

public static final String KEY_SOCKETTIMEOUT
Timeout.

See Also:
Constant Field Values

KEY_CLOSETIMEOUT

public static final String KEY_CLOSETIMEOUT
Wait before close.

See Also:
Constant Field Values

DEFCLOSETIMEOUT

private static final long DEFCLOSETIMEOUT
Defaults to no wait before closing.

See Also:
Constant Field Values

socket

private Socket socket
This is the connected socket.


in

private InputStream in
On open, the input stream opened.


out

private OutputStream out
On open, the output stream opened.

Constructor Detail

AbstractSocketDriver

protected AbstractSocketDriver(Map prop)
Creates a new socket server. Init checks for host/port ptoperty.

Method Detail

init

public void init()
On init, we check if we have all the required properties set. If either the connection port or the connection server is missing, an IllegalArgumentException is thrown.

Specified by:
init in interface Initializable
Overrides:
init in class PropertyContainer

exit

public void exit()
On exit we always close.

Specified by:
exit in interface ExitCleaning

setTimeout

public void setTimeout(int mils)
                throws SocketException
Set default timeout for socket reads

Parameters:
mils - timeout in msec for socket reads
Throws:
SocketException

open

public boolean open()
             throws IOException
Connect to remote host. If we have already connected in persistent mode, reconnection is

Specified by:
open in interface Driver
Returns:
True if initialization was successful.
Throws:
IOException - Exception to throw on connection error

authenticate

protected boolean authenticate()
                        throws IOException
Authenticates at the remote host. This method is called on open, directly after the input and output streams have been opened. The default implementation does nothing here, but subclasses can override.

Returns:
True if authentication was successful.
Throws:
IOException

isOpen

public boolean isOpen()
Returns true if the connection is open.

Specified by:
isOpen in interface Driver
Returns:
True, if a previous initialization was successful

close

public boolean close()
              throws IOException
Disconnect from remote host.

Specified by:
close in interface Driver
Parameters:
force - force a disconnect, even in persistent mode
Returns:
True if clean-up was successful.
Throws:
IOException - Exception to throw on disconnection error

getInputStream

protected InputStream getInputStream()
Returns the input stream for this socket driver. Available if open.


getOutputStream

protected OutputStream getOutputStream()
Returns the output stream for this socket driver. Available if open.


getSocket

protected Socket getSocket()
Returns the socket.