3 import org.umu.cops.prpdp.COPSPdpException;
4 import org.umu.cops.stack.COPSException;
5 import org.umu.cops.stack.COPSHandle;
6 import org.umu.cops.stack.COPSSyncStateMsg;
8 import java.net.Socket;
11 * Abstract COPS state manager.
13 public abstract class COPSStateMan {
15 // TODO - place these values into an enumeration
17 * COPS client-type that identifies the policy client
19 protected final short _clientType;
22 * COPS client handle used to uniquely identify a particular
23 * PEP's request for a client-type
25 protected final COPSHandle _handle;
28 * The socket connection. Value set when initRequestState is called
30 protected final Socket _socket;
33 * Current state of the request being managed
35 protected transient Status _status;
39 * @param clientType - the client type
40 * @param clientHandle - the unique handle to the client
42 protected COPSStateMan(final short clientType, final COPSHandle clientHandle, final Socket socket) {
43 if (clientHandle == null) throw new IllegalArgumentException("Client handle must not be null");
44 if (socket == null) throw new IllegalArgumentException("Socket connection must not be null");
45 if (!socket.isConnected()) throw new IllegalArgumentException("Socket connection must be connected");
46 this._clientType = clientType;
47 this._handle = clientHandle;
48 this._socket = socket;
49 this._status = Status.ST_CREATE;
53 * Gets the client handle
54 * @return Client's <tt>COPSHandle</tt>
56 public COPSHandle getClientHandle() {
61 * Gets the client-type
62 * @return Client-type value
64 public short getClientType() {
69 * Gets the status of the request
70 * @return Request state value
72 public Status getStatus() {
77 * Called when COPS sync is completed
78 * @param repMsg COPS sync message
79 * @throws COPSPdpException
81 public void processSyncComplete(final COPSSyncStateMsg repMsg) throws COPSException {
82 _status = Status.ST_SYNCALL;
83 // TODO - maybe we should notifySyncComplete ...
87 * The different state manager statuses
91 ST_CREATE, // Request State created
92 ST_INIT, // Request received
93 ST_DECS, // Decisions sent
94 ST_REPORT, // Report received
95 ST_FINAL, // Request state finalized
96 ST_NEW, // New request state solicited
97 ST_DEL, // Delete request state solicited
98 ST_SYNC, // SYNC request sent
99 ST_SYNCALL, // SYNC completed
100 ST_CCONN, // Close connection received
101 ST_NOKA, // Keep-alive timeout
102 ST_ACCT, // Accounting timeout