2 * Copyright (c) 2014, 2015 Cable Television Laboratories, Inc. and others. All rights reserved.
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
9 package org.pcmm.messages.impl;
11 import org.umu.cops.stack.*;
12 import org.umu.cops.stack.COPSHeader.OPCode;
14 import java.io.IOException;
15 import java.io.OutputStream;
16 import java.net.Socket;
17 import java.util.List;
19 import java.util.concurrent.ConcurrentHashMap;
22 * COPS Decision Message
27 public class COPSDecisionMsgEX extends COPSMsg {
29 /* COPSHeader coming from base class */
30 private final COPSHandle _clientHandle;
31 private final COPSError _error;
32 private final COPSIntegrity _integrity;
33 // private COPSContext _decContext;
34 private final COPSClientSI clientSI;
35 private final Map<COPSContext, List<COPSDecision>> _decisions;
37 public COPSDecisionMsgEX(final short clientType, final COPSHandle _clientHandle, final COPSError _error,
38 final COPSIntegrity _integrity, final COPSClientSI clientSI,
39 final Map<COPSContext, List<COPSDecision>> _decisions) {
40 super(new COPSHeader(OPCode.DEC, clientType));
41 this._clientHandle = _clientHandle;
43 this._integrity = _integrity;
44 this.clientSI = clientSI;
45 this._decisions = new ConcurrentHashMap<>(_decisions);
49 protected int getDataLength() {
51 if (_clientHandle != null) out += _clientHandle.getDataLength();
52 if (_error != null) out += _error.getDataLength();
55 // Display any local decisions
56 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
57 out += entry.getKey().getDataLength();
58 for (final COPSDecision decision : entry.getValue()) {
59 out += decision.getDataLength();
62 if (clientSI != null) out += clientSI.getDataLength();
63 if (_integrity != null) out += _integrity.getDataLength();
68 protected void writeBody(final Socket socket) throws IOException {
69 if (_clientHandle != null)
70 _clientHandle.writeData(socket);
72 _error.writeData(socket);
75 // Display any local decisions
76 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
78 final COPSContext context = entry.getKey();
79 final List<COPSDecision> decisions = entry.getValue();
80 context.writeData(socket);
82 for (final COPSDecision decision : decisions) {
83 decision.writeData(socket);
87 clientSI.writeData(socket);
88 if (_integrity != null)
89 _integrity.writeData(socket);
93 * Method getClientHandle
95 * @return a COPSHandle
98 public COPSHandle getClientHandle() {
102 public COPSClientSI getClientSI() {
107 protected void dumpBody(final OutputStream os) throws IOException {
108 if (_clientHandle != null)
109 _clientHandle.dump(os);
113 // Display any local decisions
114 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
115 final COPSContext context = entry.getKey();
116 final List<COPSDecision> v = entry.getValue();
119 for (final COPSDecision decision : v) {
123 if (clientSI != null)
125 if (_integrity != null) {