Skip to content

Commit

Permalink
Log handshake initiation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkerr9000 committed Apr 13, 2018
1 parent b1c0c56 commit db26e98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Expand Up @@ -46,7 +46,7 @@ public class HandshakeClientInitializer extends ChannelInitializer<SocketChannel
private final Duration timeout;
private final ProtocolInstallerRepository<ProtocolInstaller.Orientation.Client> protocolInstaller;
private final NettyPipelineBuilderFactory pipelineBuilderFactory;
private final TimeoutStrategy timeoutStrategy;
private final TimeoutStrategy handshakeDelay;
private final Log log;

public HandshakeClientInitializer( ApplicationProtocolRepository applicationProtocolRepository, ModifierProtocolRepository modifierProtocolRepository,
Expand All @@ -59,7 +59,7 @@ public HandshakeClientInitializer( ApplicationProtocolRepository applicationProt
this.timeout = handshakeTimeout;
this.protocolInstaller = protocolInstallerRepository;
this.pipelineBuilderFactory = pipelineBuilderFactory;
this.timeoutStrategy = new ExponentialBackoffStrategy( 1, 2000, MILLISECONDS );
this.handshakeDelay = new ExponentialBackoffStrategy( 1, 2000, MILLISECONDS );
}

private void installHandlers( Channel channel, HandshakeClient handshakeClient ) throws Exception
Expand All @@ -79,14 +79,16 @@ protected void initChannel( SocketChannel channel ) throws Exception
HandshakeClient handshakeClient = new HandshakeClient();
installHandlers( channel, handshakeClient );

scheduleHandshake( channel, handshakeClient, timeoutStrategy.newTimeout() );
log.info( "Scheduling handshake (and timeout) local %s remote %s", channel.localAddress(), channel.remoteAddress() );

scheduleHandshake( channel, handshakeClient, handshakeDelay.newTimeout() );
scheduleTimeout( channel, handshakeClient );
}

/**
* schedules the handshake initiation after the connection attempt
*/
private void scheduleHandshake( SocketChannel ch, HandshakeClient handshakeClient, TimeoutStrategy.Timeout timeout )
private void scheduleHandshake( SocketChannel ch, HandshakeClient handshakeClient, TimeoutStrategy.Timeout handshakeDelay )
{
ch.eventLoop().schedule( () ->
{
Expand All @@ -96,14 +98,14 @@ private void scheduleHandshake( SocketChannel ch, HandshakeClient handshakeClien
}
else if ( ch.isOpen() )
{
timeout.increment();
scheduleHandshake( ch, handshakeClient, timeout );
handshakeDelay.increment();
scheduleHandshake( ch, handshakeClient, handshakeDelay );
}
else
{
handshakeClient.failIfNotDone( "Channel closed" );
}
}, timeout.getMillis(), MILLISECONDS );
}, handshakeDelay.getMillis(), MILLISECONDS );
}

private void scheduleTimeout( SocketChannel ch, HandshakeClient handshakeClient )
Expand All @@ -118,6 +120,8 @@ private void scheduleTimeout( SocketChannel ch, HandshakeClient handshakeClient

private void initiateHandshake( Channel channel, HandshakeClient handshakeClient )
{
log.info( "Initiating handshake local %s remote %s", channel.localAddress(), channel.remoteAddress() );

SimpleNettyChannel channelWrapper = new SimpleNettyChannel( channel, log );
CompletableFuture<ProtocolStack> handshake = handshakeClient.initiate( channelWrapper, applicationProtocolRepository, modifierProtocolRepository );

Expand Down
Expand Up @@ -57,6 +57,8 @@ public HandshakeServerInitializer( ApplicationProtocolRepository applicationProt
@Override
public void initChannel( SocketChannel ch ) throws Exception
{
log.info( "Installing handshake server local %s remote %s", ch.localAddress(), ch.remoteAddress() );

pipelineBuilderFactory.server( ch, log )
.addFraming()
.add( "handshake_server_encoder", new ServerMessageEncoder() )
Expand Down

0 comments on commit db26e98

Please sign in to comment.