public abstract class BasicClient extends java.lang.Object implements ClientCommand
BasicClient client = ...;
client.init(props);
client.run();
if(client.getResult() != CommandResult.VALUE_OK) {
// handle problems
} else {
// handle success
}
setSocket(Socket)
must be called
before the client is initialized.Modifier and Type | Class and Description |
---|---|
class |
BasicClient.Debug |
Modifier and Type | Field and Description |
---|---|
protected java.lang.Long |
aid |
protected boolean |
compress |
protected java.lang.String |
filename |
protected java.lang.String |
host |
protected java.lang.Long |
iid |
protected org.apache.commons.logging.Log |
logger |
protected java.lang.Integer |
port |
protected java.lang.String |
session |
protected java.lang.String |
subDir |
Constructor and Description |
---|
BasicClient() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
doRun()
This method will execute the command itself.
|
int |
getResult()
Returns the result of the command.
|
java.lang.String |
getServerException()
Returns the exception from the server when
ClientCommand.getResult() returns
CommandResult#FAILED . |
java.lang.String |
getServerResponse()
Returns whatever the server may have sent to the client at the end of the
command.
|
protected java.net.Socket |
getSocket()
Returns a socket through the mechanics of the CorbafileServer socket
creation process.
|
protected void |
identifyClient()
Identifies the client with the server.
|
void |
init(java.util.Properties properties)
Initializes the ClientCommand with a set of properties.
|
protected boolean |
readResponse(java.io.DataInputStream in)
Reads the response from the server through the socket.
|
void |
run()
Opens the connection to the server and identifies the client, registering
it at the server side in the waiting queue.
|
protected void |
setException(java.lang.String exception) |
protected void |
setResult(int result) |
protected void |
setServerRepsonse(java.lang.String text) |
void |
setSocket(java.net.Socket s)
Sets the socket that the client is supposed to use.
|
void |
setSocketTimeOut(int milliSeconds)
Set a timeout for the socket of the client.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFileHash
protected java.lang.String session
protected java.lang.String subDir
protected java.lang.String filename
protected java.lang.String host
protected java.lang.Integer port
protected java.lang.Long aid
protected java.lang.Long iid
protected boolean compress
protected org.apache.commons.logging.Log logger
public void init(java.util.Properties properties)
ClientCommand
init
in interface ClientCommand
properties
- a set of properties for the command to useprotected java.net.Socket getSocket() throws java.net.UnknownHostException, java.io.IOException
java.net.UnknownHostException
- if the given host is unknownjava.io.IOException
- if another IOException occursprotected void identifyClient() throws java.io.IOException
java.io.IOException
public int getResult()
ClientCommand
ClientCommand.run()
was
called.getResult
in interface ClientCommand
CommandResult
or -1 if the method
could not determine the state of the commandprotected void setResult(int result)
public java.lang.String getServerException()
ClientCommand
ClientCommand.getResult()
returns
CommandResult#FAILED
. If no exception happened on the server this
method returns null. Only usable after ClientCommand.run()
was called.getServerException
in interface ClientCommand
protected void setException(java.lang.String exception)
public java.lang.String getServerResponse()
ClientCommand
getServerResponse
in interface ClientCommand
protected void setServerRepsonse(java.lang.String text)
protected boolean readResponse(java.io.DataInputStream in) throws java.io.IOException
Code | Meaning | Additional Data |
---|---|---|
1 | OK | none |
2 | VALUE_OK_WITH_RESULT | A String representing the server side response |
3 | FAILED_SERVER | A String representing the server side exception |
in
- the InputStream from which to read the responsetrue
if the server returned any OK status, otherwise
false
java.io.IOException
public void setSocket(java.net.Socket s) throws java.io.IOException
s
- the socket to be used.java.io.IOException
- thrown if the socket is already setpublic void setSocketTimeOut(int milliSeconds) throws java.net.SocketException
setSocket(Socket)
then this method may throw an
exception while setting the timeout on the foreign socket.milliSeconds
- java.net.SocketException
- thrown if a foreign socket was provided and we try to set the
timeoutpublic final void run() throws java.io.IOException
doRun()
.run
in interface ClientCommand
java.io.IOException
- thrown if something happened during the execution of the
commandprotected abstract void doRun() throws java.io.IOException
run()
java.io.IOException