1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.transport.Open;
14 
15 
16 import hunt.proton.amqp.transport.FrameBody;
17 import hunt.proton.amqp.Binary;
18 import hunt.proton.amqp.Symbol;
19 import hunt.proton.amqp.UnsignedInteger;
20 import hunt.proton.amqp.UnsignedShort;
21 import hunt.Object;
22 import hunt.logging;
23 import hunt.collection.Map;
24 import hunt.collection.LinkedHashMap;
25 import hunt.collection.List;
26 import hunt.collection.ArrayList;
27 import hunt.String;
28 
29 class Open : FrameBody
30 {
31     private String _containerId;
32     private String _hostname;
33     private UnsignedInteger _maxFrameSize;
34     private UnsignedShort _channelMax;
35     private UnsignedInteger _idleTimeOut;
36     private List!Symbol _outgoingLocales;
37     private List!Symbol _incomingLocales;
38     private List!Symbol _offeredCapabilities;
39     private List!Symbol _desiredCapabilities;
40     private Map!(Symbol,Object) _properties;
41 
42     this() {
43        _maxFrameSize =  UnsignedInteger.valueOf(0xffffffff);
44         _channelMax = UnsignedShort.valueOf(cast(short)65535);
45     }
46 
47     this(Open other)
48     {
49         this._containerId = other._containerId;
50         this._hostname = other._hostname;
51         this._maxFrameSize = other._maxFrameSize;
52         this._channelMax = other._channelMax;
53         this._idleTimeOut = other._idleTimeOut;
54         if (other._outgoingLocales !is null) {
55             this._outgoingLocales = other.getOutgoingLocales();
56         }
57         if (other._incomingLocales !is null) {
58             this._incomingLocales = other.getIncomingLocales();
59         }
60         if (other._offeredCapabilities !is null) {
61             this._offeredCapabilities = other.getOfferedCapabilities();
62         }
63         if (other._desiredCapabilities !is null) {
64             this._desiredCapabilities = other.getDesiredCapabilities();
65         }
66         if (other._properties !is null) {
67             this._properties = new LinkedHashMap!(Symbol,Object)(other.getProperties());
68         }
69     }
70 
71     public String getContainerId()
72     {
73         return _containerId;
74     }
75 
76     public void setContainerId(String containerId)
77     {
78         if( containerId is null )
79         {
80             logError("the container-id field is mandatory");
81         }
82 
83         _containerId = containerId;
84     }
85 
86     public String getHostname()
87     {
88         return _hostname;
89     }
90 
91     public void setHostname(String hostname)
92     {
93         _hostname = hostname;
94     }
95 
96     public UnsignedInteger getMaxFrameSize()
97     {
98         return _maxFrameSize;
99     }
100 
101     public void setMaxFrameSize(UnsignedInteger maxFrameSize)
102     {
103         _maxFrameSize = maxFrameSize;
104     }
105 
106     public UnsignedShort getChannelMax()
107     {
108         return _channelMax;
109     }
110 
111     public void setChannelMax(UnsignedShort channelMax)
112     {
113         _channelMax = channelMax;
114     }
115 
116     public UnsignedInteger getIdleTimeOut()
117     {
118         return _idleTimeOut;
119     }
120 
121     public void setIdleTimeOut(UnsignedInteger idleTimeOut)
122     {
123         _idleTimeOut = idleTimeOut;
124     }
125 
126     public List!Symbol getOutgoingLocales()
127     {
128         return _outgoingLocales;
129     }
130 
131     public void setOutgoingLocales(List!Symbol outgoingLocales)
132     {
133         _outgoingLocales = outgoingLocales;
134     }
135 
136     public List!Symbol getIncomingLocales()
137     {
138         return _incomingLocales;
139     }
140 
141     public void setIncomingLocales(List!Symbol incomingLocales)
142     {
143         _incomingLocales = incomingLocales;
144     }
145 
146     public List!Symbol getOfferedCapabilities()
147     {
148         return _offeredCapabilities;
149     }
150 
151     public void setOfferedCapabilities(List!Symbol offeredCapabilities)
152     {
153         _offeredCapabilities = offeredCapabilities;
154     }
155 
156     public List!Symbol getDesiredCapabilities()
157     {
158         return _desiredCapabilities;
159     }
160 
161     public void setDesiredCapabilities(List!Symbol desiredCapabilities)
162     {
163         _desiredCapabilities = desiredCapabilities;
164     }
165 
166     public Map!(Symbol,Object) getProperties()
167     {
168         return _properties;
169     }
170 
171     public void setProperties(Map!(Symbol,Object) properties)
172     {
173         _properties = properties;
174     }
175 
176 
177     public void invoke(E)(FrameBodyHandler!E handler, Binary payload, E context)
178     {
179         handler.handleOpen(this, payload, context);
180     }
181 
182 
183     public FrameBody copy()
184     {
185         return new Open(this);
186     }
187 }