Search in sources :

Example 1 with NamedThreadFactory

use of org.neo4j.helpers.NamedThreadFactory in project neo4j by neo4j.

the class NettyServerTest method shouldGivePortConflictErrorWithPortNumberInIt.

@Test
public void shouldGivePortConflictErrorWithPortNumberInIt() throws Throwable {
    // Given an occupied port
    int port = 16000;
    try (ServerSocketChannel ignore = ServerSocketChannel.open().bind(new InetSocketAddress("localhost", port))) {
        final ListenSocketAddress address = new ListenSocketAddress("localhost", port);
        // Expect
        exception.expect(PortBindException.class);
        exception.expectMessage("Address localhost:16000 is already in use");
        // When
        new NettyServer(new NamedThreadFactory("mythreads"), asList(protocolOnAddress(address))).start();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) NettyServer(org.neo4j.bolt.transport.NettyServer) Test(org.junit.Test)

Example 2 with NamedThreadFactory

use of org.neo4j.helpers.NamedThreadFactory in project neo4j by neo4j.

the class Cluster method start.

public void start() throws InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newCachedThreadPool(new NamedThreadFactory("cluster-starter"));
    try {
        startCoreMembers(executor);
        startReadReplicas(executor);
    } finally {
        executor.shutdown();
    }
}
Also used : NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService)

Example 3 with NamedThreadFactory

use of org.neo4j.helpers.NamedThreadFactory in project neo4j by neo4j.

the class PaxosClusterMemberEvents method init.

@Override
public void init() throws Throwable {
    serializer = new AtomicBroadcastSerializer(lenientObjectInputStream, lenientObjectOutputStream);
    cluster.addClusterListener(clusterListener);
    atomicBroadcast.addAtomicBroadcastListener(atomicBroadcastListener);
    snapshot.setSnapshotProvider(new HighAvailabilitySnapshotProvider());
    heartbeat.addHeartbeatListener(heartbeatListener = new HeartbeatListenerImpl());
    executor = Executors.newSingleThreadExecutor(new NamedThreadFactory("Paxos event notification", namedThreadFactoryMonitor));
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory)

Example 4 with NamedThreadFactory

use of org.neo4j.helpers.NamedThreadFactory in project neo4j by neo4j.

the class SenderService method start.

@Override
public synchronized void start() {
    serviceLock.writeLock().lock();
    try {
        eventLoopGroup = new NioEventLoopGroup(0, new NamedThreadFactory("sender-service"));
        bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class).handler(channelInitializer);
        senderServiceRunning = true;
    } finally {
        serviceLock.writeLock().unlock();
    }
}
Also used : NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 5 with NamedThreadFactory

use of org.neo4j.helpers.NamedThreadFactory in project neo4j by neo4j.

the class NetworkSender method send.

private synchronized void send(final Message message) {
    monitor.queuedMessage(message);
    final URI to = URI.create(message.getHeader(Message.TO));
    ExecutorService senderExecutor = senderExecutors.get(to);
    if (senderExecutor == null) {
        senderExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("Cluster Sender " + to.toASCIIString(), monitor));
        senderExecutors.put(to, senderExecutor);
    }
    senderExecutor.submit(new Runnable() {

        @Override
        public void run() {
            Channel channel = getChannel(to);
            try {
                if (channel == null) {
                    channel = openChannel(to);
                    openedChannel(to, channel);
                    // Instance could be connected to, remove any marker of it being failed
                    failedInstances.remove(to);
                }
            } catch (Exception e) {
                // Only print out failure message on first fail
                if (!failedInstances.contains(to)) {
                    msgLog.warn(e.getMessage());
                    failedInstances.add(to);
                }
                return;
            }
            try {
                // Set FROM header
                message.setHeader(Message.FROM, me.toASCIIString());
                msgLog.debug("Sending to " + to + ": " + message);
                ChannelFuture future = channel.write(message);
                future.addListener(new ChannelFutureListener() {

                    @Override
                    public void operationComplete(ChannelFuture future) throws Exception {
                        monitor.sentMessage(message);
                        if (!future.isSuccess()) {
                            msgLog.debug("Unable to write " + message + " to " + future.getChannel(), future.getCause());
                            closedChannel(future.getChannel());
                            // Try again
                            send(message);
                        }
                    }
                });
            } catch (Exception e) {
                if (Exceptions.contains(e, ClosedChannelException.class)) {
                    msgLog.warn("Could not send message, because the connection has been closed.");
                } else {
                    msgLog.warn("Could not send message", e);
                }
                channel.close();
            }
        }
    });
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) ThreadRenamingRunnable(org.jboss.netty.util.ThreadRenamingRunnable) Channel(org.jboss.netty.channel.Channel) ExecutorService(java.util.concurrent.ExecutorService) URI(java.net.URI) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) URISyntaxException(java.net.URISyntaxException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException)

Aggregations

NamedThreadFactory (org.neo4j.helpers.NamedThreadFactory)6 URI (java.net.URI)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 URISyntaxException (java.net.URISyntaxException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Channel (org.jboss.netty.channel.Channel)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 ChannelFutureListener (org.jboss.netty.channel.ChannelFutureListener)1 ThreadRenamingRunnable (org.jboss.netty.util.ThreadRenamingRunnable)1 Test (org.junit.Test)1 NettyServer (org.neo4j.bolt.transport.NettyServer)1 NetworkReceiver (org.neo4j.cluster.com.NetworkReceiver)1