use of com.hazelcast.internal.networking.Channel in project hazelcast by hazelcast.
the class TcpClientConnectionManager method createSocketConnection.
@SuppressWarnings("unchecked")
protected TcpClientConnection createSocketConnection(Address target) {
CandidateClusterContext currentClusterContext = clusterDiscoveryService.current();
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
Socket socket = socketChannel.socket();
bindSocketToPort(socket);
Channel channel = networking.register(currentClusterContext.getChannelInitializer(), socketChannel, true);
channel.attributeMap().put(Address.class, target);
InetSocketAddress inetSocketAddress = new InetSocketAddress(target.getInetAddress(), target.getPort());
channel.connect(inetSocketAddress, connectionTimeoutMillis);
TcpClientConnection connection = new TcpClientConnection(client, connectionIdGen.incrementAndGet(), channel);
socketChannel.configureBlocking(true);
SocketInterceptor socketInterceptor = currentClusterContext.getSocketInterceptor();
if (socketInterceptor != null) {
socketInterceptor.onConnect(socket);
}
channel.start();
return connection;
} catch (Exception e) {
closeResource(socketChannel);
logger.finest(e);
throw rethrow(e);
}
}
use of com.hazelcast.internal.networking.Channel in project hazelcast by hazelcast.
the class NioNetworking method shutdown.
@Override
public void shutdown() {
if (!started.compareAndSet(true, false)) {
return;
}
metricsRegistry.deregisterDynamicMetricsProvider(this);
// if there are any channels left, we close them.
for (Channel channel : channels) {
if (!channel.isClosed()) {
closeResource(channel);
}
}
// and clear them to prevent memory leaks.
channels.clear();
// we unregister the publish future to prevent memory leaks.
if (publishFuture != null) {
publishFuture.cancel(false);
publishFuture = null;
}
ioBalancer.stop();
if (logger.isFinestEnabled()) {
logger.finest("Shutting down IO Threads... Total: " + (inputThreads.length + outputThreads.length));
}
shutdown(inputThreads);
inputThreads = null;
shutdown(outputThreads);
outputThreads = null;
closeListenerExecutor.shutdown();
closeListenerExecutor = null;
}
use of com.hazelcast.internal.networking.Channel in project hazelcast by hazelcast.
the class NioNetworking method provideDynamicMetrics.
@Override
public void provideDynamicMetrics(MetricDescriptor descriptor, MetricsCollectionContext context) {
for (Channel channel : channels) {
String pipelineId = channel.localSocketAddress() + "->" + channel.remoteSocketAddress();
MetricDescriptor descriptorIn = descriptor.copy().withPrefix(TCP_PREFIX_CONNECTION_IN).withDiscriminator(TCP_DISCRIMINATOR_PIPELINEID, pipelineId);
context.collect(descriptorIn, channel.inboundPipeline());
MetricDescriptor descriptorOut = descriptor.copy().withPrefix(TCP_PREFIX_CONNECTION_OUT).withDiscriminator(TCP_DISCRIMINATOR_PIPELINEID, pipelineId);
context.collect(descriptorOut, channel.outboundPipeline());
}
NioThread[] inputThreads = this.inputThreads;
if (inputThreads != null) {
for (NioThread nioThread : inputThreads) {
MetricDescriptor descriptorInThread = descriptor.copy().withPrefix(TCP_PREFIX_INPUTTHREAD).withDiscriminator(TCP_DISCRIMINATOR_THREAD, nioThread.getName());
context.collect(descriptorInThread, nioThread);
}
}
NioThread[] outputThreads = this.outputThreads;
if (outputThreads != null) {
for (NioThread nioThread : outputThreads) {
MetricDescriptor descriptorOutThread = descriptor.copy().withPrefix(TCP_PREFIX_OUTPUTTHREAD).withDiscriminator(TCP_DISCRIMINATOR_THREAD, nioThread.getName());
context.collect(descriptorOutThread, nioThread);
}
}
IOBalancer ioBalancer = this.ioBalancer;
if (ioBalancer != null) {
MetricDescriptor descriptorBalancer = descriptor.copy().withPrefix(TCP_PREFIX_BALANCER);
context.collect(descriptorBalancer, ioBalancer);
}
MetricDescriptor descriptorTcp = descriptor.copy().withPrefix(TCP_PREFIX);
context.collect(descriptorTcp, this);
}
use of com.hazelcast.internal.networking.Channel in project hazelcast by hazelcast.
the class TcpServerConnectionManager method newChannel.
Channel newChannel(SocketChannel socketChannel, boolean clientMode) throws IOException {
Networking networking = server.getNetworking();
ChannelInitializer channelInitializer = channelInitializerFn.apply(endpointQualifier);
assert channelInitializer != null : "Found NULL channel initializer for endpoint-qualifier " + endpointQualifier;
Channel channel = networking.register(channelInitializer, socketChannel, clientMode);
// Advanced Network
if (endpointConfig != null) {
setChannelOptions(channel, endpointConfig);
}
acceptedChannels.add(channel);
return channel;
}
use of com.hazelcast.internal.networking.Channel in project hazelcast by hazelcast.
the class TcpServerControlTest method setup.
@Before
public void setup() throws IllegalAccessException {
HazelcastInstance hz = factory.newHazelcastInstance(createConfig());
serializationService = getSerializationService(hz);
Node node = getNode(hz);
connectionManager = (TcpServerConnectionManager) node.getServer().getConnectionManager(EndpointQualifier.resolve(protocolType, protocolIdentifier));
tcpServerControl = getFieldValueReflectively(connectionManager, "serverControl");
lifecycleListener = getFieldValueReflectively(connectionManager, "connectionLifecycleListener");
addressRegistry = node.getLocalAddressRegistry();
// setup mock channel & socket
Socket socket = mock(Socket.class);
when(socket.getRemoteSocketAddress()).thenReturn(CLIENT_SOCKET_ADDRESS);
channel = mock(Channel.class);
ConcurrentMap channelAttributeMap = new ConcurrentHashMap();
when(channel.attributeMap()).thenReturn(channelAttributeMap);
when(channel.socket()).thenReturn(socket);
when(channel.remoteSocketAddress()).thenReturn(CLIENT_SOCKET_ADDRESS);
}
Aggregations