Cleanup of state managers' interfaces (constructor and init).
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / COPSStateMan.java
1 package org.umu.cops;
2
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;
7
8 import java.net.Socket;
9
10 /**
11  * Abstract COPS state manager.
12  */
13 public abstract class COPSStateMan {
14
15     // TODO - place these values into an enumeration
16     /**
17      * COPS client-type that identifies the policy client
18      */
19     protected final short _clientType;
20
21     /**
22      *  COPS client handle used to uniquely identify a particular
23      *  PEP's request for a client-type
24      */
25     protected final COPSHandle _handle;
26
27     /**
28      * The socket connection. Value set when initRequestState is called
29      */
30     protected final Socket _socket;
31
32     /**
33      *  Current state of the request being managed
34      */
35     protected transient Status _status;
36
37     /**
38      * Constructor
39      * @param clientType - the client type
40      * @param clientHandle - the unique handle to the client
41      */
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;
50     }
51
52     /**
53      * Gets the client handle
54      * @return   Client's <tt>COPSHandle</tt>
55      */
56     public COPSHandle getClientHandle() {
57         return _handle;
58     }
59
60     /**
61      * Gets the client-type
62      * @return   Client-type value
63      */
64     public short getClientType() {
65         return _clientType;
66     }
67
68     /**
69      * Gets the status of the request
70      * @return      Request state value
71      */
72     public Status getStatus() {
73         return _status;
74     }
75
76     /**
77      * Called when COPS sync is completed
78      * @param    repMsg              COPS sync message
79      * @throws COPSPdpException
80      */
81     public void processSyncComplete(final COPSSyncStateMsg repMsg) throws COPSException {
82         _status = Status.ST_SYNCALL;
83         // TODO - maybe we should notifySyncComplete ...
84     }
85
86     /**
87      * The different state manager statuses
88      */
89     public enum Status {
90         NA,
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
103     }
104
105 }