4 package org.pcmm.messages.impl;
6 import org.umu.cops.stack.*;
7 import org.umu.cops.stack.COPSHeader.OPCode;
9 import java.io.IOException;
10 import java.io.OutputStream;
11 import java.net.Socket;
12 import java.util.List;
14 import java.util.concurrent.ConcurrentHashMap;
17 * COPS Decision Message
22 public class COPSDecisionMsgEX extends COPSMsg {
24 /* COPSHeader coming from base class */
25 private final COPSHandle _clientHandle;
26 private final COPSError _error;
27 private final COPSIntegrity _integrity;
28 // private COPSContext _decContext;
29 private final COPSClientSI clientSI;
30 private final Map<COPSContext, List<COPSDecision>> _decisions;
32 public COPSDecisionMsgEX(final short clientType, final COPSHandle _clientHandle, final COPSError _error,
33 final COPSIntegrity _integrity, final COPSClientSI clientSI,
34 final Map<COPSContext, List<COPSDecision>> _decisions) {
35 super(new COPSHeader(OPCode.DEC, clientType));
36 this._clientHandle = _clientHandle;
38 this._integrity = _integrity;
39 this.clientSI = clientSI;
40 this._decisions = new ConcurrentHashMap<>(_decisions);
44 protected int getDataLength() {
46 if (_clientHandle != null) out += _clientHandle.getDataLength();
47 if (_error != null) out += _error.getDataLength();
50 // Display any local decisions
51 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
52 out += entry.getKey().getDataLength();
53 for (final COPSDecision decision : entry.getValue()) {
54 out += decision.getDataLength();
57 if (clientSI != null) out += clientSI.getDataLength();
58 if (_integrity != null) out += _integrity.getDataLength();
63 protected void writeBody(final Socket socket) throws IOException {
64 if (_clientHandle != null)
65 _clientHandle.writeData(socket);
67 _error.writeData(socket);
70 // Display any local decisions
71 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
73 final COPSContext context = entry.getKey();
74 final List<COPSDecision> decisions = entry.getValue();
75 context.writeData(socket);
77 for (final COPSDecision decision : decisions) {
78 decision.writeData(socket);
82 clientSI.writeData(socket);
83 if (_integrity != null)
84 _integrity.writeData(socket);
88 * Method getClientHandle
90 * @return a COPSHandle
93 public COPSHandle getClientHandle() {
97 public COPSClientSI getClientSI() {
102 protected void dumpBody(final OutputStream os) throws IOException {
103 if (_clientHandle != null)
104 _clientHandle.dump(os);
108 // Display any local decisions
109 for (final Map.Entry<COPSContext, List<COPSDecision>> entry : _decisions.entrySet()) {
110 final COPSContext context = entry.getKey();
111 final List<COPSDecision> v = entry.getValue();
114 for (final COPSDecision decision : v) {
118 if (clientSI != null)
120 if (_integrity != null) {