Refactor shared attributes and methods to the PEP agent super COPSPepAgent.
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / ospep / COPSPepOSAgent.java
1 package org.umu.cops.ospep;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.umu.cops.prpep.COPSPepAgent;
6 import org.umu.cops.prpep.COPSPepConnection;
7 import org.umu.cops.prpep.COPSPepReqStateMan;
8 import org.umu.cops.stack.COPSClientSI;
9 import org.umu.cops.stack.COPSException;
10 import org.umu.cops.stack.COPSHandle;
11 import org.umu.cops.stack.COPSPepId;
12
13 import java.net.Socket;
14 import java.util.List;
15
16 /**
17  * This is a outsourcing COPS PEP. Responsible for making
18  * connection to the PDP and maintaining it
19  */
20 public class COPSPepOSAgent extends COPSPepAgent {
21
22     public final static Logger logger = LoggerFactory.getLogger(COPSPepOSAgent.class);
23
24     /**
25      * Policy data processor class
26      */
27     private transient COPSPepOSDataProcess _process;
28
29     /**
30      * Creates a PEP agent
31      * @param    clientType         Client-type
32      * @param    pepID              PEP-ID
33      * @param    port               The port to begin listening
34      */
35     public COPSPepOSAgent(final short clientType, final COPSPepId pepID, final int port,
36                           final COPSPepOSDataProcess process) {
37         super(clientType, pepID, port);
38         this._process = process;
39     }
40
41     /**
42      * Adds a request state to the connection manager.
43      * @param clientSIs The client data from the outsourcing event
44      * @return  The newly created connection manager
45      * @throws COPSPepException
46      * @throws COPSException
47      */
48     public COPSPepReqStateMan addRequestState(final COPSHandle handle, final List<COPSClientSI> clientSIs)
49             throws COPSException {
50         if (_conn != null)
51             return ((COPSPepOSConnection)_conn).addRequestState(handle, _process, clientSIs);
52
53         return null;
54     }
55
56     @Override
57     protected COPSPepConnection createPepConnection(final Socket socket) {
58         return new COPSPepOSConnection(_clientType, socket);
59     }
60
61     /**
62      * Creates a new request state when the outsourcing event is detected.
63      * @param handle The COPS handle for this request
64      * @param clientSIs The client specific data for this request
65      */
66     public void dispatchEvent(final COPSHandle handle, final List<COPSClientSI> clientSIs) {
67         try {
68             addRequestState(handle, clientSIs);
69         } catch (Exception e) {
70             logger.error("Error adding request state", e);
71         }
72     }
73 }