import org.slf4j.LoggerFactory;
/**
- * oneshot listener - once connection is ready, initiate handshake (if not already started by device)
+ * Oneshot listener - once connection is ready, initiate handshake (if not already started by device).
*/
public class ConnectionReadyListenerImpl implements ConnectionReadyListener {
private static final Logger LOG = LoggerFactory.getLogger(ConnectionReadyListenerImpl.class);
- private ConnectionContext connectionContext;
- private HandshakeContext handshakeContext;
+ private final ConnectionContext connectionContext;
+ private final HandshakeContext handshakeContext;
/**
- * @param connectionContext
- * @param handshakeContext
+ * Constructor.
+ *
+ * @param connectionContext - connection context
+ * @param handshakeContext - handshake context
*/
- public ConnectionReadyListenerImpl(ConnectionContext connectionContext,
- HandshakeContext handshakeContext) {
- this.connectionContext = connectionContext;
- this.handshakeContext = handshakeContext;
+ public ConnectionReadyListenerImpl(ConnectionContext connectionContext, HandshakeContext handshakeContext) {
+ this.connectionContext = connectionContext;
+ this.handshakeContext = handshakeContext;
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void onConnectionReady() {
- if(LOG.isDebugEnabled()) {
+ if (LOG.isDebugEnabled()) {
LOG.debug("device is connected and ready-to-use (pipeline prepared): {}",
connectionContext.getConnectionAdapter().getRemoteAddress());
}
final Future<?> handshakeResult = handshakeContext.getHandshakePool().submit(handshakeStepWrapper);
try {
- // as we run not in netty thread, need to remain in sync lock until initial handshake step processed
+ // As we run not in netty thread,
+ // need to remain in sync lock until initial handshake step processed.
handshakeResult.get();
} catch (Exception e) {
- LOG.error("failed to process onConnectionReady event on device {}, reason {}",
+ LOG.error("failed to process onConnectionReady event on device {}",
connectionContext.getConnectionAdapter().getRemoteAddress(),
e);
connectionContext.closeConnection(false);
- try {
- handshakeContext.close();
- } catch (Exception e1) {
- LOG.error("failed to close handshake context for device {}, reason {}",
- connectionContext.getConnectionAdapter().getRemoteAddress(),
- e1
- );
- }
+ handshakeContext.close();
}
} else {
LOG.debug("already touched by hello message from device {} after second check",