Package org.jcsp.lang

# Class AltingConnectionServerImpl

java.lang.Object
org.jcsp.lang.Guard
org.jcsp.lang.AltingConnectionServer
org.jcsp.lang.AltingConnectionServerImpl

All Implemented Interfaces:
  `ConnectionServer`

public class AltingConnectionServerImpl extends AltingConnectionServer
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.

Author:
  Quickstone Technologies Limited

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final int`
`SERVER_STATE_CLOSED`
Server state.
`protected static final int`
`SERVER_STATE_OPEN`
Server state.
`protected static final int`
`SERVER_STATE_RECEIVED`
Server state.

### Fields inherited from interface org.jcsp.lang.ConnectionServer

`FACTORY`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AltingConnectionServerImpl(AltingChannelInput openIn, AltingChannelInput furtherRequestIn)`
Constructs a new server instance.

## Method Summary

Modifier and Type
Method
Description
`protected int`
`getServerState()`
`void`
`reply(Object data)`
Sends some data back to the client after a request has been received but keeps the connection open.
`void`
`reply(Object data, boolean close)`
Sends some data back to the client after a request has been received.
`void`
`replyAndClose(Object data)`
Sends some data back to the client and closes the connection.
`Object`
`request()`
Receives some data from a client once a connection has been established.

### Methods inherited from class org.jcsp.lang.AltingConnectionServer

`getAltingChannel, pending, setAltingChannel`

### Methods inherited from class org.jcsp.lang.Guard

`schedule`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### 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

## Constructor Details

### AltingConnectionServerImpl

protected AltingConnectionServerImpl(AltingChannelInput openIn, AltingChannelInput furtherRequestIn)
Constructs a new server instance. This must be called by a subclass which is responsible for creating the channels.

## Method Details

### request

public Object request() throws IllegalStateException
Receives some data from a client once a connection has been established. This will block until the client calls `request(Object)` but by establishing a connection.

Returns:
  the `Object` sent by the client.
Throws:
  `IllegalStateException`

### reply

public void reply(Object data) throws 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 call `recieve()` to receive a further request.

Parameters:
  `data` - the data to send to the client.
Throws:
  `IllegalStateException`

### reply

public void reply(Object data, boolean close) throws 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 is `true`.

Parameters:
  `data` - the data to send to the client.
  `close` - `boolean` indicating whether or not the connection should be closed.
Throws:
  `IllegalStateException`

### replyAndClose

public void replyAndClose(Object data) throws IllegalStateException
Sends some data back to the client and closes the connection. This method will not block. After calling this method, the server may call `accept()` 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 call `reply(Object)` followed by a `close()`, 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:
  `IllegalStateException`

### getServerState

protected int getServerState()