Package org.jcsp.lang
Class AltingConnectionServerImpl<T>
- java.lang.Object
-
- org.jcsp.lang.Guard
-
- org.jcsp.lang.AltingConnectionServer<T>
-
- org.jcsp.lang.AltingConnectionServerImpl<T>
-
- All Implemented Interfaces:
ConnectionServer<T>
- Direct Known Subclasses:
NetAltingConnectionServer
public class AltingConnectionServerImpl<T> extends AltingConnectionServer<T>
This class does not need to be used by standard JCSP users. It is exposed so that the connection mechanism can be extended for custom connections.
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelInput<ConnectionMessage<T>>
currentInputChannel
private int
currentServerState
private AltingChannelInput<ConnectionMessage<T>>
furtherRequestIn
private ConnectionServerMessage<T>
msg
private AltingChannelInput<ConnectionMessage<T>>
openIn
protected static int
SERVER_STATE_CLOSED
Server state.protected static int
SERVER_STATE_OPEN
Server state.protected static int
SERVER_STATE_RECEIVED
Server state.private ChannelOutput<ConnectionMessage<T>>
toClient
-
Fields inherited from interface org.jcsp.lang.ConnectionServer
FACTORY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AltingConnectionServerImpl(AltingChannelInput<ConnectionMessage<T>> openIn, AltingChannelInput<ConnectionMessage<T>> furtherRequestIn)
Constructs a new server instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
getServerState()
void
reply(T data)
Sends some data back to the client after a request has been received but keeps the connection open.void
reply(T data, boolean close)
Sends some data back to the client after a request has been received.void
replyAndClose(T data)
Sends some data back to the client and closes the connection.T
request()
Receives some data from a client once a connection has been established.-
Methods inherited from class org.jcsp.lang.AltingConnectionServer
disable, enable, getAltingChannel, pending, setAltingChannel
-
-
-
-
Field Detail
-
SERVER_STATE_CLOSED
protected static final int SERVER_STATE_CLOSED
Server state. The server is initially CLOSED the first request will take it to the RECEIVED state. A reply will take it back to OPEN or CLOSED depending on the mode of reply. From the OPEN or CLOSED state a further request can occur.- See Also:
- Constant Field Values
-
SERVER_STATE_OPEN
protected static final int SERVER_STATE_OPEN
Server state. The server is initially CLOSED the first request will take it to the RECEIVED state. A reply will take it back to OPEN or CLOSED depending on the mode of reply. From the OPEN or CLOSED state a further request can occur.- See Also:
- Constant Field Values
-
SERVER_STATE_RECEIVED
protected static final int SERVER_STATE_RECEIVED
Server state. The server is initially CLOSED the first request will take it to the RECEIVED state. A reply will take it back to OPEN or CLOSED depending on the mode of reply. From the OPEN or CLOSED state a further request can occur.- See Also:
- Constant Field Values
-
currentServerState
private int currentServerState
-
openIn
private AltingChannelInput<ConnectionMessage<T>> openIn
-
furtherRequestIn
private AltingChannelInput<ConnectionMessage<T>> furtherRequestIn
-
currentInputChannel
private ChannelInput<ConnectionMessage<T>> currentInputChannel
-
toClient
private ChannelOutput<ConnectionMessage<T>> toClient
-
msg
private ConnectionServerMessage<T> msg
-
-
Constructor Detail
-
AltingConnectionServerImpl
protected AltingConnectionServerImpl(AltingChannelInput<ConnectionMessage<T>> openIn, AltingChannelInput<ConnectionMessage<T>> furtherRequestIn)
Constructs a new server instance. This must be called by a subclass which is responsible for creating the channels.
-
-
Method Detail
-
request
public T request() throws java.lang.IllegalStateException
Receives some data from a client once a connection has been established. This will block until the client callsrequest(Object)
but by establishing a connection.- Returns:
- the
Object
sent by the client. - Throws:
java.lang.IllegalStateException
-
reply
public void reply(T data) throws java.lang.IllegalStateException
Sends some data back to the client after a request has been received but keeps the connection open. After calling this method, the server should callrecieve()
to receive a further request.- Parameters:
data
- the data to send to the client.- Throws:
java.lang.IllegalStateException
-
reply
public void reply(T data, boolean close) throws java.lang.IllegalStateException
Sends some data back to the client after a request has been received. The closed parameter indicates whether or not the connection should be closed. The connection will be closed iff close istrue
.- Parameters:
data
- the data to send to the client.close
-boolean
indicating whether or not the connection should be closed.- Throws:
java.lang.IllegalStateException
-
replyAndClose
public void replyAndClose(T data) throws java.lang.IllegalStateException
Sends some data back to the client and closes the connection. This method will not block. After calling this method, the server may callaccept()
in order to allow another connection to this server to be established. If this method did not take any data to send back to the client, and the server was meant to callreply(Object)
followed by aclose()
, then there would be a race hazard at the client as it would not know whether the connection had remained open or not.- Parameters:
data
- the data to send back to client.- Throws:
java.lang.IllegalStateException
-
getServerState
protected int getServerState()
-
-