Moved emulator classes out of driver module.
[packetcable.git] / packetcable-emulator / src / main / java / org / pcmm / rcd / impl / PcmmCmtsConnection.java
1 /*
2  * (c) 2015 Cable Television Laboratories, Inc.  All rights reserved.
3  */
4
5 package org.pcmm.rcd.impl;
6
7 import org.pcmm.gates.IGateSpec.Direction;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10 import org.umu.cops.prpep.COPSPepConnection;
11 import org.umu.cops.prpep.COPSPepDataProcess;
12 import org.umu.cops.prpep.COPSPepException;
13 import org.umu.cops.prpep.COPSPepReqStateMan;
14 import org.umu.cops.stack.COPSException;
15 import org.umu.cops.stack.COPSHandle;
16
17 import java.net.Socket;
18 import java.util.Collections;
19 import java.util.Map;
20 import java.util.Set;
21
22 /**
23  * The connection object for the PCMM CMTS
24  */
25 class PcmmCmtsConnection extends COPSPepConnection {
26
27     private final static Logger logger = LoggerFactory.getLogger(COPSPepConnection.class);
28
29     /**
30      * The configured gates
31      */
32     private final Map<Direction, Set<String>> gateConfig;
33
34     /**
35      * The connected CMTSs and whether or not they are up
36      */
37     private final Map<String, Boolean> cmStatus;
38
39     /**
40      * Constructor
41      * @param clientType - the client-type
42      * @param sock - the socket connection
43      * @param gateConfig - the configured gates
44      * @param cmStatus - the configured CMs and whether or each is connected
45      */
46     public PcmmCmtsConnection(final short clientType, final Socket sock, final Map<Direction, Set<String>> gateConfig,
47                               final Map<String, Boolean> cmStatus) {
48         super(clientType, sock);
49         this.gateConfig = Collections.unmodifiableMap(gateConfig);
50         this.cmStatus = Collections.unmodifiableMap(cmStatus);
51     }
52
53     @Override
54     public COPSPepReqStateMan addRequestState(final COPSHandle clientHandle, final COPSPepDataProcess process)
55             throws COPSException {
56         final COPSPepReqStateMan manager = new CmtsPepReqStateMan(_clientType, clientHandle, (CmtsDataProcessor)process,
57                 _sock, gateConfig, cmStatus);
58         if (_managerMap.get(clientHandle) != null)
59             throw new COPSPepException("Duplicate Handle, rejecting " + clientHandle);
60
61         _managerMap.put(clientHandle, manager);
62         logger.info("Added state manager with key - " + clientHandle);
63         manager.initRequestState();
64         return manager;
65     }
66 }
67