Skip to content

Commit

Permalink
Pass boolean to initiator method
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarW committed Sep 28, 2018
1 parent d8401e0 commit f76fae3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 39 deletions.
Expand Up @@ -46,8 +46,7 @@
import org.neo4j.logging.LogProvider;

import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.preferNativeClientConfig;
import static org.neo4j.causalclustering.net.NioBootstrapConfig.nioClientConfig;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.clientConfig;

public class CatchUpClient extends LifecycleAdapter
{
Expand All @@ -66,7 +65,7 @@ public CatchUpClient( LogProvider logProvider, Clock clock, Function<CatchUpResp
this.log = logProvider.getLog( getClass() );
this.clock = clock;
this.channelInitializer = channelInitializer;
this.bootstrapConfiguration = useNativeTransport ? preferNativeClientConfig() : nioClientConfig();
this.bootstrapConfiguration = clientConfig( useNativeTransport );
}

public <T> T makeBlockingRequest( AdvertisedSocketAddress upstream, CatchUpRequest request, CatchUpResponseCallback<T> responseHandler )
Expand Down
Expand Up @@ -22,31 +22,30 @@
*/
package org.neo4j.causalclustering.messaging;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;

import java.util.Iterator;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Stream;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;

import org.neo4j.causalclustering.net.BootstrapConfiguration;
import org.neo4j.causalclustering.protocol.handshake.ProtocolStack;
import org.neo4j.helpers.AdvertisedSocketAddress;
import org.neo4j.helpers.NamedThreadFactory;
import org.neo4j.helpers.collection.Pair;
import org.neo4j.scheduler.JobHandle;
import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider;
import org.neo4j.scheduler.JobHandle;

import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.preferNativeClientConfig;
import static org.neo4j.causalclustering.net.NioBootstrapConfig.nioClientConfig;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.clientConfig;

public class SenderService extends LifecycleAdapter implements Outbound<AdvertisedSocketAddress,Message>
{
Expand All @@ -67,7 +66,7 @@ public SenderService( ChannelInitializer channelInitializer, LogProvider logProv
this.channelInitializer = channelInitializer;
this.log = logProvider.getLog( getClass() );
this.channels = new ReconnectingChannels();
this.bootstrapConfiguration = useNativeTransport ? preferNativeClientConfig() : nioClientConfig();
this.bootstrapConfiguration = clientConfig( useNativeTransport );
}

@Override
Expand Down
Expand Up @@ -33,36 +33,36 @@

public interface BootstrapConfiguration<TYPE extends Channel>
{
static BootstrapConfiguration<? extends ServerSocketChannel> preferNativeServerConfig()
static BootstrapConfiguration<? extends ServerSocketChannel> serverConfig( boolean preferNative )
{
if ( Epoll.isAvailable() )
if ( preferNative )
{
return EpollBootstrapConfig.epollServerConfig();
}
else if ( KQueue.isAvailable() )
{
return KQueueBootsrapConfig.kQueueServerConfig();
}
else
{
return NioBootstrapConfig.nioServerConfig();
if ( Epoll.isAvailable() )
{
return EpollBootstrapConfig.epollServerConfig();
}
else if ( KQueue.isAvailable() )
{
return KQueueBootsrapConfig.kQueueServerConfig();
}
}
return NioBootstrapConfig.nioServerConfig();
}

static BootstrapConfiguration<? extends SocketChannel> preferNativeClientConfig()
static BootstrapConfiguration<? extends SocketChannel> clientConfig( boolean preferNative )
{
if ( Epoll.isAvailable() )
{
return EpollBootstrapConfig.epollClientConfig();
}
else if ( KQueue.isAvailable() )
{
return KQueueBootsrapConfig.kQueueClientConfig();
}
else
if ( preferNative )
{
return NioBootstrapConfig.nioClientConfig();
if ( Epoll.isAvailable() )
{
return EpollBootstrapConfig.epollClientConfig();
}
else if ( KQueue.isAvailable() )
{
return KQueueBootsrapConfig.kQueueClientConfig();
}
}
return NioBootstrapConfig.nioClientConfig();
}

EventLoopGroup eventLoopGroup( ThreadFactory threadFactory );
Expand Down
Expand Up @@ -39,8 +39,7 @@
import org.neo4j.logging.NullLogProvider;

import static java.lang.String.format;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.preferNativeServerConfig;
import static org.neo4j.causalclustering.net.NioBootstrapConfig.nioServerConfig;
import static org.neo4j.causalclustering.net.BootstrapConfiguration.serverConfig;

public class Server extends SuspendableLifeCycle
{
Expand All @@ -49,7 +48,7 @@ public class Server extends SuspendableLifeCycle
private final String serverName;

private final NamedThreadFactory threadFactory;
private final boolean useNativeTransport;
private final BootstrapConfiguration<? extends ServerSocketChannel> bootstrapConfiguration;
private final ChildInitializer childInitializer;
private final ChannelInboundHandler parentHandler;
private final ListenSocketAddress listenAddress;
Expand All @@ -74,7 +73,7 @@ public Server( ChildInitializer childInitializer, ChannelInboundHandler parentHa
this.userLog = userLogProvider.getLog( getClass() );
this.serverName = serverName;
this.threadFactory = new NamedThreadFactory( serverName );
this.useNativeTransport = useNativeTransport;
this.bootstrapConfiguration = serverConfig( useNativeTransport );
}

public Server( ChildInitializer childInitializer, ListenSocketAddress listenAddress, String serverName )
Expand All @@ -95,7 +94,6 @@ protected void start0()
{
return;
}
BootstrapConfiguration<? extends ServerSocketChannel> bootstrapConfiguration = useNativeTransport ? preferNativeServerConfig() : nioServerConfig();

workerGroup = bootstrapConfiguration.eventLoopGroup( threadFactory );

Expand Down

0 comments on commit f76fae3

Please sign in to comment.