Skip to content

Commit fea1fe1

Browse files
committed
Add support for connection properties exchange.
Introduced the ability to set and retrieve properties in OpenFrame exchanges between local and remote endpoints. This change ensures flexible configuration and access to remote properties post-connection establishment.
1 parent 9ed0555 commit fea1fe1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/main/java/com/swiftmq/amqp/v100/client/Connection.java

+21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.swiftmq.amqp.v100.client.po.POOpen;
2626
import com.swiftmq.amqp.v100.client.po.POProtocolRequest;
2727
import com.swiftmq.amqp.v100.client.po.POSendClose;
28+
import com.swiftmq.amqp.v100.generated.transport.definitions.Fields;
2829
import com.swiftmq.amqp.v100.transport.AMQPFrame;
2930
import com.swiftmq.amqp.v100.types.AMQPString;
3031
import com.swiftmq.amqp.v100.types.AMQPSymbol;
@@ -92,6 +93,7 @@ public class Connection implements ExceptionHandler {
9293
int outputBufferExtendSize = 65536;
9394
SocketFactory socketFactory = new PlainSocketFactory();
9495
ExceptionListener exceptionListener = null;
96+
Fields properties = null;
9597

9698
/**
9799
* Creates a Connection and uses SASL for authentication.
@@ -223,6 +225,23 @@ public void setOpenHostname(String openHostname) {
223225
this.openHostname = openHostname;
224226
}
225227

228+
/**
229+
* Sets the of the OpenFrame to be sent to the remote endpoint
230+
*
231+
* @param properties Fields for the OpenFrame
232+
*/
233+
public void setProperties(Fields properties) {
234+
this.properties = properties;
235+
}
236+
237+
/**
238+
* Retrieves the properties of the OpenFrame from the remote endpoint. Available after connect
239+
*
240+
* @return Fields object representing the remote properties, or null if not available
241+
*/
242+
public Fields getRemoteProperties() {
243+
return connectionDispatcher.getRemoteProperties();
244+
}
226245
/**
227246
* Sets the idle timeout. Default is Long.MAX_VALUE.
228247
* <p/>
@@ -365,6 +384,8 @@ protected ProtocolInputHandler createInputHandler() {
365384
return connectionDispatcher.getProtocolHandler();
366385
}
367386
};
387+
if (properties != null)
388+
connectionDispatcher.setProperties(properties);
368389
connectionDispatcher.setMyConnection(this);
369390
networkConnection.start();
370391
dos = new DataStreamOutputStream(networkConnection.getOutputStream());

src/main/java/com/swiftmq/amqp/v100/client/ConnectionDispatcher.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.swiftmq.amqp.v100.generated.security.sasl.*;
2727
import com.swiftmq.amqp.v100.generated.transport.definitions.ConnectionError;
2828
import com.swiftmq.amqp.v100.generated.transport.definitions.ErrorConditionFactory;
29+
import com.swiftmq.amqp.v100.generated.transport.definitions.Fields;
2930
import com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds;
3031
import com.swiftmq.amqp.v100.generated.transport.performatives.*;
3132
import com.swiftmq.amqp.v100.transport.AMQPFrame;
@@ -76,7 +77,7 @@ public class ConnectionDispatcher
7677
POProtocolRequest protPO = null;
7778
POAuthenticate authPO = null;
7879
POOpen openPO = null;
79-
OpenFrame remoteOpen = null;
80+
volatile OpenFrame remoteOpen = null;
8081
POSendClose closePO = null;
8182
CloseFrame remoteClose = null;
8283
SaslMechanismsFrame saslMechanisms = null;
@@ -89,6 +90,7 @@ public class ConnectionDispatcher
8990
long idleTimeoutDelay = 0;
9091
SaslClient saslClient = null;
9192
volatile boolean connectionDisabled = false;
93+
Fields properties = null;
9294

9395
int maxLocalFrameSize = Integer.MAX_VALUE;
9496
int maxRemoteFrameSize = Integer.MAX_VALUE;
@@ -133,6 +135,16 @@ public int getMaxFrameSize() {
133135
return Math.max(512, Math.min(maxLocalFrameSize, maxRemoteFrameSize));
134136
}
135137

138+
public void setProperties(Fields properties) {
139+
this.properties = properties;
140+
}
141+
142+
public Fields getRemoteProperties() {
143+
if (remoteOpen != null)
144+
return remoteOpen.getProperties();
145+
return null;
146+
}
147+
136148
public void setSaslActive(boolean saslActive) {
137149
this.saslActive = saslActive;
138150
}
@@ -317,6 +329,8 @@ public void visit(POOpen po) {
317329
OpenFrame openFrame = new OpenFrame(0);
318330
openFrame.setContainerId(new AMQPString(po.getContainerId()));
319331
openFrame.setChannelMax(new AMQPUnsignedShort(po.getMaxChannel()));
332+
if (properties != null)
333+
openFrame.setProperties(properties);
320334
if (myConnection.getOpenHostname() == null)
321335
openFrame.setHostname(new AMQPString(remoteHostname));
322336
else

0 commit comments

Comments
 (0)