use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.
the class TestHazelcastFactory method newHazelcastClient.
public HazelcastInstance newHazelcastClient(ClientConfig config) {
if (!mockNetwork) {
return HazelcastClient.newHazelcastClient(config);
}
if (config == null) {
config = new XmlClientConfigBuilder().build();
}
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
HazelcastClientProxy proxy;
try {
if (tccl == ClassLoader.getSystemClassLoader()) {
Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
}
ClientConnectionManagerFactory clientConnectionManagerFactory = clientRegistry.createClientServiceFactory("127.0.0.1", CLIENT_PORTS);
AddressProvider testAddressProvider = createAddressProvider(config);
HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(config, clientConnectionManagerFactory, testAddressProvider);
client.start();
clients.add(client);
OutOfMemoryErrorDispatcher.registerClient(client);
proxy = new HazelcastClientProxy(client);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
return proxy;
}
use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.
the class HazelcastClientInstanceImpl method createAddressProviders.
private Collection<AddressProvider> createAddressProviders(AddressProvider externalAddressProvider) {
ClientNetworkConfig networkConfig = getClientConfig().getNetworkConfig();
final ClientAwsConfig awsConfig = networkConfig.getAwsConfig();
Collection<AddressProvider> addressProviders = new LinkedList<AddressProvider>();
addressProviders.add(new DefaultAddressProvider(networkConfig));
if (externalAddressProvider != null) {
addressProviders.add(externalAddressProvider);
}
if (discoveryService != null) {
addressProviders.add(new DiscoveryAddressProvider(discoveryService, loggingService));
}
if (awsConfig != null && awsConfig.isEnabled()) {
try {
addressProviders.add(new AwsAddressProvider(awsConfig, loggingService));
} catch (NoClassDefFoundError e) {
ILogger logger = loggingService.getLogger(HazelcastClient.class);
logger.warning("hazelcast-aws.jar might be missing!");
throw e;
}
}
return addressProviders;
}
use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.
the class TestHazelcastFactory method createAddressProvider.
private AddressProvider createAddressProvider(ClientConfig config) {
List<String> userConfiguredAddresses = config.getNetworkConfig().getAddresses();
if (!userConfiguredAddresses.contains("localhost")) {
// addresses are set explicitly, don't add more addresses
return null;
}
return new AddressProvider() {
@Override
public Collection<InetSocketAddress> loadAddresses() {
Collection<InetSocketAddress> inetAddresses = new ArrayList<InetSocketAddress>();
for (Address address : getKnownAddresses()) {
Collection<InetSocketAddress> addresses = AddressHelper.getPossibleSocketAddresses(address.getPort(), address.getHost(), 3);
inetAddresses.addAll(addresses);
}
return inetAddresses;
}
};
}
use of com.hazelcast.client.connection.AddressProvider in project hazelcast by hazelcast.
the class ClusterListenerSupport method getSocketAddresses.
private Collection<InetSocketAddress> getSocketAddresses() {
final List<InetSocketAddress> socketAddresses = new LinkedList<InetSocketAddress>();
Collection<Member> memberList = getMemberList();
for (Member member : memberList) {
socketAddresses.add(member.getSocketAddress());
}
for (AddressProvider addressProvider : addressProviders) {
socketAddresses.addAll(addressProvider.loadAddresses());
}
if (shuffleMemberList) {
Collections.shuffle(socketAddresses);
}
return socketAddresses;
}
Aggregations