@Test public void testNetworkConfig() { final ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig(); assertEquals(2, networkConfig.getConnectionAttemptLimit()); assertEquals(2, networkConfig.getAddresses().size()); assertTrue(networkConfig.getAddresses().contains("127.0.0.1")); assertTrue(networkConfig.getAddresses().contains("127.0.0.2")); assertTrue(networkConfig.isSmartRouting()); assertTrue(networkConfig.isRedoOperation()); final SocketInterceptorConfig socketInterceptorConfig = networkConfig.getSocketInterceptorConfig(); assertTrue(socketInterceptorConfig.isEnabled()); assertEquals( "com.hazelcast.examples.MySocketInterceptor", socketInterceptorConfig.getClassName()); assertEquals("bar", socketInterceptorConfig.getProperty("foo")); final ClientAwsConfig awsConfig = networkConfig.getAwsConfig(); assertTrue(awsConfig.isEnabled()); assertTrue(awsConfig.isInsideAws()); assertEquals("TEST_ACCESS_KEY", awsConfig.getAccessKey()); assertEquals("TEST_ACCESS_KEY", awsConfig.getAccessKey()); assertEquals("TEST_SECRET_KEY", awsConfig.getSecretKey()); assertEquals("us-east-1", awsConfig.getRegion()); assertEquals("ec2.amazonaws.com", awsConfig.getHostHeader()); assertEquals("type", awsConfig.getTagKey()); assertEquals("hz-nodes", awsConfig.getTagValue()); assertEquals(11, awsConfig.getConnectionTimeoutSeconds()); }
public SmartClientConnectionManager( HazelcastClient client, Authenticator authenticator, LoadBalancer loadBalancer) { this.authenticator = authenticator; this.client = client; ClientConfig config = client.getClientConfig(); router = new Router(loadBalancer); // init socketInterceptor SocketInterceptorConfig sic = config.getSocketInterceptorConfig(); if (sic != null && sic.isEnabled()) { SocketInterceptor implementation = (SocketInterceptor) sic.getImplementation(); if (implementation == null && sic.getClassName() != null) { try { implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance(); } catch (Throwable e) { logger.severe("SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e); } } if (implementation != null) { if (!(implementation instanceof MemberSocketInterceptor)) { logger.severe( "SocketInterceptor must be instance of " + MemberSocketInterceptor.class.getName()); implementation = null; } else { logger.info("SocketInterceptor is enabled"); } } if (implementation != null) { socketInterceptor = implementation; socketInterceptor.init(sic.getProperties()); } else { socketInterceptor = null; } } else { socketInterceptor = null; } poolSize = config.getConnectionPoolSize(); int connectionTimeout = config.getConnectionTimeout(); heartbeat = new HeartBeatChecker( connectionTimeout, client.getSerializationService(), client.getClientExecutionService()); socketOptions = config.getSocketOptions(); }
private SocketInterceptor initSocketInterceptor(SocketInterceptorConfig sic) { SocketInterceptor implementation = null; if (sic != null && sic.isEnabled()) { implementation = (SocketInterceptor) sic.getImplementation(); if (implementation == null && sic.getClassName() != null) { try { implementation = (SocketInterceptor) Class.forName(sic.getClassName()).newInstance(); } catch (Throwable e) { LOGGER.severe("SocketInterceptor class cannot be instantiated!" + sic.getClassName(), e); } } } if (implementation != null) { implementation.init(sic.getProperties()); } return implementation; }
@Test public void testSocketInterceptorConfig() { SocketInterceptorConfig socketInterceptorConfig = config.getNetworkConfig().getSocketInterceptorConfig(); assertNotNull(socketInterceptorConfig); assertFalse(socketInterceptorConfig.isEnabled()); assertEquals(DummySocketInterceptor.class.getName(), socketInterceptorConfig.getClassName()); assertEquals(socketInterceptor, socketInterceptorConfig.getImplementation()); }