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