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();
}
}
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();
}
}
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));
}
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();
}
}
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();
}
}
});
}
Aggregations