Refactor shared attributes and methods to the PEP agent super COPSPepAgent.
[packetcable.git] / packetcable-driver / src / main / java / org / umu / cops / ospep / COPSPepOSConnection.java
1 package org.umu.cops.ospep;
2
3 import org.umu.cops.prpep.COPSPepConnection;
4 import org.umu.cops.stack.COPSClientSI;
5 import org.umu.cops.stack.COPSDecisionMsg;
6 import org.umu.cops.stack.COPSException;
7 import org.umu.cops.stack.COPSHandle;
8
9 import java.net.Socket;
10 import java.util.List;
11
12 /**
13  * COPSPepConnection represents a PEP-PDP Connection Manager.
14  * Responsible for processing messages received from PDP.
15  */
16 public class COPSPepOSConnection extends COPSPepConnection {
17
18     /**
19      * Creates a new PEP connection
20      * @param clientType    PEP's client-type
21      * @param sock          Socket connected to PDP
22      */
23     public COPSPepOSConnection(final short clientType, final Socket sock) {
24         super(clientType, sock);
25     }
26
27     @Override
28     protected void handleDecisionMsg(final COPSDecisionMsg dMsg) throws COPSException {
29         final COPSPepOSReqStateMan manager = (COPSPepOSReqStateMan)_managerMap.get(dMsg.getClientHandle());
30         manager.processDecision(dMsg);
31     }
32
33     /**
34      * Adds a new request state
35      * @param handle        Client's handle
36      * @param process       Policy data processing object
37      * @param clientSIs     Client data from the outsourcing event
38      * @return              The newly created request state manager
39      * @throws COPSException
40      */
41     protected COPSPepOSReqStateMan addRequestState(final COPSHandle handle, final COPSPepOSDataProcess process,
42                                                    final List<COPSClientSI> clientSIs) throws COPSException {
43         final COPSPepOSReqStateMan manager = new COPSPepOSReqStateMan(_clientType, handle, process, clientSIs);
44         if (_managerMap.get(handle) != null)
45             throw new COPSPepException("Duplicate Handle, rejecting " + handle.getId().str());
46         _managerMap.put(handle, manager);
47         manager.initRequestState(_sock);
48         return manager;
49     }
50
51 }