Bump to odlparent 3.1.0 and yangtools 2.0.3
[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 static com.google.common.base.Preconditions.checkNotNull;
12
13 import org.pcmm.gates.IGateSpec.Direction;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import org.umu.cops.prpep.COPSPepConnection;
17 import org.umu.cops.prpep.COPSPepDataProcess;
18 import org.umu.cops.prpep.COPSPepException;
19 import org.umu.cops.prpep.COPSPepReqStateMan;
20 import org.umu.cops.stack.COPSException;
21 import org.umu.cops.stack.COPSHandle;
22
23 import java.net.Socket;
24 import java.util.Collections;
25 import java.util.Map;
26 import java.util.Set;
27
28 /**
29  * The connection object for the PCMM CMTS
30  */
31 class PcmmCmtsConnection extends COPSPepConnection {
32
33     private static final Logger logger = LoggerFactory.getLogger(COPSPepConnection.class);
34
35     private final CMTSConfig config;
36
37     /**
38      * Constructor
39      * @param clientType - the client-type
40      * @param sock - the socket connection
41      * @param config - emulator configuration
42      */
43     public PcmmCmtsConnection(final short clientType, final Socket sock, final CMTSConfig config) {
44         super(clientType, sock);
45         this.config = checkNotNull(config);
46     }
47
48     @Override
49     public COPSPepReqStateMan addRequestState(final COPSHandle clientHandle, final COPSPepDataProcess process)
50             throws COPSException {
51         final COPSPepReqStateMan manager = new CmtsPepReqStateMan(_clientType, clientHandle, (CmtsDataProcessor)process,
52                 _sock, config);
53         if (_managerMap.get(clientHandle) != null)
54             throw new COPSPepException("Duplicate Handle, rejecting " + clientHandle);
55
56         _managerMap.put(clientHandle, manager);
57         logger.info("Added state manager with key - " + clientHandle);
58         manager.initRequestState();
59         return manager;
60     }
61 }
62