use of com.hazelcast.nio.SocketInterceptor 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.nio.SocketInterceptor in project hazelcast by hazelcast.
the class ClusterDiscoveryServiceBuilder method build.
public ClusterDiscoveryService build() {
ArrayList<CandidateClusterContext> contexts = new ArrayList<>();
for (ClientConfig config : configs) {
ClientNetworkConfig networkConfig = config.getNetworkConfig();
SocketInterceptor interceptor = initSocketInterceptor(networkConfig.getSocketInterceptorConfig());
ICredentialsFactory credentialsFactory = initCredentialsFactory(config);
if (credentialsFactory == null) {
credentialsFactory = new StaticCredentialsFactory(new UsernamePasswordCredentials(null, null));
}
credentialsFactory.configure(new ClientCallbackHandler(config));
DiscoveryService discoveryService = initDiscoveryService(config);
AddressProvider provider;
if (externalAddressProvider != null) {
provider = externalAddressProvider;
} else {
provider = createAddressProvider(config, discoveryService);
}
final SSLConfig sslConfig = networkConfig.getSSLConfig();
final SocketOptions socketOptions = networkConfig.getSocketOptions();
contexts.add(new CandidateClusterContext(config.getClusterName(), provider, discoveryService, credentialsFactory, interceptor, clientExtension.createChannelInitializer(sslConfig, socketOptions)));
}
return new ClusterDiscoveryService(unmodifiableList(contexts), configsTryCount, lifecycleService);
}
Aggregations