Interface ConnectionClient
-
- All Known Subinterfaces:
NetConnectionClient
,NetSharedConnectionClient
,SharedConnectionClient
- All Known Implementing Classes:
AltingConnectionClient
,AltingConnectionClientImpl
,NetAltingConnectionClient
,NetSharedAltingConnectionClient
,SharedAltingConnectionClient
public interface ConnectionClient
This is an interface to be implemented by classes that wish to act as a client to connect to a
ConnectionServer
.Users of classes implementing this interface should call
request(Object)
to initiate a conversation and to send some data to the server. Implementations may decide to return immediately or to wait until the server accepts the connection and then return. The Connection is not guaranteed to be open until a call toreply()
has returned. Thereply()
method should be called soon after the call toreqeust(Object)
. Some computation may be done between the calls but any external process synchronization is potentially hazardous.After calling
reply()
, clients can check whether the server closed the connection by callingisOpen()
. If it returnstrue
, then the connection has been kept open. If the connection has been kept open then the client may assume that a call torequest(Object)
will not block and that the connection will soon be dealt with by the server.This is an example of typical code structure for using a ConnectionClient:
//have a variable client of type ConnectionClient do { client.request(some_data); some_variable = client.receive(); } while (client.isOpen())
- Author:
- Quickstone Technologies Limited
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
isOpen()
Returns whether the server has kept its end of the Connection open.java.lang.Object
reply()
Receives some data back from the server afterrequest(Object)
has been called.void
request(java.lang.Object data)
This method is used to send data to aConnectionServer
in a client/server conversation.
-
-
-
Method Detail
-
request
void request(java.lang.Object data) throws java.lang.IllegalStateException
This method is used to send data to a
ConnectionServer
in a client/server conversation. If a connection has not yet been established, then this method will open the connection as necessary.Once this method has returned, the client may do some computation but must then guarantee to call
reply()
. This will obtain a server's response to the request. In between calling this method andreply()
, doing pure computation is safe. Performing synchronization with other process is potentially hazardous.Once a server replies, if the connection has been kept open, then this method should be called again to make a further request.
Programs using
Connection
s need to adopt a protocol so that the server knows when a conversation with a client has finished and will then drop the connection.- Parameters:
data
- theObject
to send to the server.- Throws:
java.lang.IllegalStateException
- if the method is called when it is not meant to be.
-
reply
java.lang.Object reply() throws java.lang.IllegalStateException
Receives some data back from the server after
request(Object)
has been called.After calling this method,
isOpen()
may be called to establish whether the server dropped the connection after replying.Implementations may make this operation ALTable.
- Returns:
- the
Object
sent from the server. - Throws:
java.lang.IllegalStateException
- if the method is called when it is not meant to be.
-
isOpen
boolean isOpen() throws java.lang.IllegalStateException
Returns whether the server has kept its end of the Connection open. This should only be called after a call to
reply()
and before any other Connection method is called.- Returns:
true
iff the server has kept the connection open.- Throws:
java.lang.IllegalStateException
-
-