1818import java .util .Locale ;
1919import java .util .Map ;
2020
21- // ServiceBus <-> ProtonReactor interaction handles all
22- // amqp_connection/transport related events from reactor
2321public class ConnectionHandler extends BaseHandler {
2422
2523 private static final Logger TRACE_LOGGER = LoggerFactory .getLogger (ConnectionHandler .class );
2624
2725 private final AmqpConnection amqpConnection ;
26+ private final String connectionId ;
2827
29- protected ConnectionHandler (final AmqpConnection amqpConnection ) {
28+ protected ConnectionHandler (final AmqpConnection amqpConnection , final String connectionId ) {
3029
3130 add (new Handshaker ());
3231 this .amqpConnection = amqpConnection ;
32+ this .connectionId = connectionId ;
3333 }
3434
35- static ConnectionHandler create (TransportType transportType , AmqpConnection amqpConnection ) {
35+ static ConnectionHandler create (TransportType transportType , AmqpConnection amqpConnection , String connectionId ) {
3636 switch (transportType ) {
3737 case AMQP_WEB_SOCKETS :
3838 if (WebSocketProxyConnectionHandler .shouldUseProxy (amqpConnection .getHostName ())) {
@@ -42,7 +42,7 @@ static ConnectionHandler create(TransportType transportType, AmqpConnection amqp
4242 }
4343 case AMQP :
4444 default :
45- return new ConnectionHandler (amqpConnection );
45+ return new ConnectionHandler (amqpConnection , connectionId );
4646 }
4747 }
4848
@@ -63,17 +63,18 @@ protected AmqpConnection getAmqpConnection() {
6363 @ Override
6464 public void onConnectionInit (Event event ) {
6565 if (TRACE_LOGGER .isInfoEnabled ()) {
66- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionInit hostname[%s]" , this .amqpConnection .getHostName ()));
66+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionInit hostname[%s], connectionId[%s]" ,
67+ this .amqpConnection .getHostName (), this .connectionId ));
6768 }
6869
6970 final Connection connection = event .getConnection ();
7071 final String hostName = new StringBuilder (this .amqpConnection .getHostName ())
7172 .append (":" )
72- .append (String . valueOf ( this .getProtocolPort () ))
73+ .append (this .getProtocolPort ())
7374 .toString ();
7475
7576 connection .setHostname (hostName );
76- connection .setContainer (StringUtil . getRandomString () );
77+ connection .setContainer (this . connectionId );
7778
7879 final Map <Symbol , Object > connectionProperties = new HashMap <>();
7980 connectionProperties .put (AmqpConstants .PRODUCT , ClientConstants .PRODUCT_NAME );
@@ -137,7 +138,8 @@ protected int getMaxFrameSize() {
137138 @ Override
138139 public void onConnectionBound (Event event ) {
139140 if (TRACE_LOGGER .isInfoEnabled ()) {
140- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionBound hostname[%s]" , this .amqpConnection .getHostName ()));
141+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionBound hostname[%s], connectionId[%s]" ,
142+ this .amqpConnection .getHostName (), this .connectionId ));
141143 }
142144
143145 final Transport transport = event .getTransport ();
@@ -150,8 +152,8 @@ public void onConnectionUnbound(Event event) {
150152
151153 final Connection connection = event .getConnection ();
152154 if (TRACE_LOGGER .isInfoEnabled ()) {
153- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionUnbound: hostname[%s], state[%s], remoteState[%s]" ,
154- connection .getHostname (), connection .getLocalState (), connection .getRemoteState ()));
155+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionUnbound hostname[%s], connectionId [%s], state[%s], remoteState[%s]" ,
156+ connection .getHostname (), this . connectionId , connection .getLocalState (), connection .getRemoteState ()));
155157 }
156158
157159 // if failure happened while establishing transport - nothing to free up.
@@ -167,9 +169,8 @@ public void onTransportError(Event event) {
167169 final ErrorCondition condition = transport .getCondition ();
168170
169171 if (TRACE_LOGGER .isWarnEnabled ()) {
170- TRACE_LOGGER .warn (String .format (Locale .US , "onTransportError: hostname[%s], error[%s]" ,
171- connection != null ? connection .getHostname () : "n/a" ,
172- condition != null ? condition .getDescription () : "n/a" ));
172+ TRACE_LOGGER .warn (String .format (Locale .US , "onTransportError hostname[%s], connectionId[%s], error[%s]" ,
173+ connection != null ? connection .getHostname () : "n/a" , this .connectionId , condition != null ? condition .getDescription () : "n/a" ));
173174 }
174175
175176 if (connection != null && connection .getRemoteState () != EndpointState .CLOSED ) {
@@ -192,8 +193,8 @@ public void onTransportClosed(Event event) {
192193 final ErrorCondition condition = transport .getCondition ();
193194
194195 if (TRACE_LOGGER .isInfoEnabled ()) {
195- TRACE_LOGGER .info (String .format (Locale .US , "onTransportClosed: hostname[%s], error[%s]" ,
196- connection != null ? connection .getHostname () : "n/a" , (condition != null ? condition .getDescription () : "n/a" )));
196+ TRACE_LOGGER .info (String .format (Locale .US , "onTransportClosed hostname[%s], connectionId [%s], error[%s]" ,
197+ connection != null ? connection .getHostname () : "n/a" , this . connectionId , (condition != null ? condition .getDescription () : "n/a" )));
197198 }
198199
199200 if (connection != null && connection .getRemoteState () != EndpointState .CLOSED ) {
@@ -209,19 +210,17 @@ public void onConnectionLocalOpen(Event event) {
209210 final ErrorCondition error = connection .getCondition ();
210211
211212 if (TRACE_LOGGER .isInfoEnabled ()) {
212- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionLocalOpen: hostname[%s], errorCondition[%s], errorDescription[%s]" ,
213- connection .getHostname (),
214- error != null ? error .getCondition () : "n/a" ,
215- error != null ? error .getDescription () : "n/a" ));
213+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionLocalOpen hostname[%s], connectionId[%s], errorCondition[%s], errorDescription[%s]" ,
214+ connection .getHostname (), this .connectionId , error != null ? error .getCondition () : "n/a" , error != null ? error .getDescription () : "n/a" ));
216215 }
217216 }
218217
219218 @ Override
220219 public void onConnectionRemoteOpen (Event event ) {
221220
222221 if (TRACE_LOGGER .isInfoEnabled ()) {
223- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionRemoteOpen: hostname[%s], remoteContainer[%s]" ,
224- event .getConnection ().getHostname (), event .getConnection ().getRemoteContainer ()));
222+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionRemoteOpen hostname[%s], connectionId [%s], remoteContainer[%s]" ,
223+ event .getConnection ().getHostname (), this . connectionId , event .getConnection ().getRemoteContainer ()));
225224 }
226225
227226 this .amqpConnection .onOpenComplete (null );
@@ -234,10 +233,8 @@ public void onConnectionLocalClose(Event event) {
234233 final ErrorCondition error = connection .getCondition ();
235234
236235 if (TRACE_LOGGER .isInfoEnabled ()) {
237- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionLocalClose: hostname[%s], errorCondition[%s], errorDescription[%s]" ,
238- connection .getHostname (),
239- error != null ? error .getCondition () : "n/a" ,
240- error != null ? error .getDescription () : "n/a" ));
236+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionLocalClose hostname[%s], connectionId[%s], errorCondition[%s], errorDescription[%s]" ,
237+ connection .getHostname (), this .connectionId , error != null ? error .getCondition () : "n/a" , error != null ? error .getDescription () : "n/a" ));
241238 }
242239
243240 if (connection .getRemoteState () == EndpointState .CLOSED ) {
@@ -256,10 +253,8 @@ public void onConnectionRemoteClose(Event event) {
256253 final ErrorCondition error = connection .getRemoteCondition ();
257254
258255 if (TRACE_LOGGER .isInfoEnabled ()) {
259- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionRemoteClose: hostname[%s], errorCondition[%s], errorDescription[%s]" ,
260- connection .getHostname (),
261- error != null ? error .getCondition () : "n/a" ,
262- error != null ? error .getDescription () : "n/a" ));
256+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionRemoteClose hostname[%s], connectionId[%s], errorCondition[%s], errorDescription[%s]" ,
257+ connection .getHostname (), this .connectionId , error != null ? error .getCondition () : "n/a" , error != null ? error .getDescription () : "n/a" ));
263258 }
264259
265260 this .amqpConnection .onConnectionError (error );
@@ -271,10 +266,8 @@ public void onConnectionFinal(Event event) {
271266 final ErrorCondition error = connection .getCondition ();
272267
273268 if (TRACE_LOGGER .isInfoEnabled ()) {
274- TRACE_LOGGER .info (String .format (Locale .US , "onConnectionFinal: hostname[%s], errorCondition[%s], errorDescription[%s]" ,
275- connection .getHostname (),
276- error != null ? error .getCondition () : "n/a" ,
277- error != null ? error .getDescription () : "n/a" ));
269+ TRACE_LOGGER .info (String .format (Locale .US , "onConnectionFinal hostname[%s], connectionId[%s], errorCondition[%s], errorDescription[%s]" ,
270+ connection .getHostname (), this .connectionId , error != null ? error .getCondition () : "n/a" , error != null ? error .getDescription () : "n/a" ));
278271 }
279272 }
280273}
0 commit comments