use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class TestHazelcastFactory method newHazelcastClient.
public HazelcastInstance newHazelcastClient(ClientConfig config, String sourceIp) {
if (!mockNetwork) {
HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
registerJvmNameAndPidMetric(((HazelcastClientProxy) client).client);
return client;
}
if (config == null) {
config = new XmlClientConfigBuilder().build();
}
Thread currentThread = Thread.currentThread();
ClassLoader tccl = currentThread.getContextClassLoader();
try {
if (tccl == ClassLoader.getSystemClassLoader()) {
currentThread.setContextClassLoader(HazelcastClient.class.getClassLoader());
}
HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(getInstanceName(config), config, null, clientRegistry.createClientServiceFactory(sourceIp), createAddressProvider(config));
registerJvmNameAndPidMetric(client);
client.start();
if (clients.putIfAbsent(client.getName(), client) != null) {
throw new InvalidConfigurationException("HazelcastClientInstance with name '" + client.getName() + "' already exists!");
}
OutOfMemoryErrorDispatcher.registerClient(client);
return new HazelcastClientProxy(client);
} finally {
currentThread.setContextClassLoader(tccl);
}
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientReplicatedMapNearCacheLeakTest method createNearCacheContextBuilder.
private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder() {
ClientConfig clientConfig = getClientConfig();
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
ReplicatedMap<K, V> clientMap = client.getReplicatedMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = ((ClientReplicatedMapProxy) clientMap).getContext().getNearCacheManager(clientMap.getServiceName());
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ReplicatedMapDataStructureAdapter<K, V>(clientMap)).setNearCache(nearCache).setNearCacheManager(nearCacheManager);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class HazelcastClient method shutdown.
/**
* Shutdown the provided client and remove it from the managed list
*
* @param instance the hazelcast client instance
*/
public static void shutdown(HazelcastInstance instance) {
if (instance instanceof HazelcastClientProxy) {
final HazelcastClientProxy proxy = (HazelcastClientProxy) instance;
HazelcastClientInstanceImpl client = proxy.client;
if (client == null) {
return;
}
proxy.client = null;
CLIENTS.remove(client.getName());
try {
client.shutdown();
} catch (Throwable ignored) {
EmptyStatement.ignore(ignored);
} finally {
OutOfMemoryErrorDispatcher.deregisterClient(client);
}
}
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class HazelcastClient method constructHazelcastClient.
private static HazelcastInstance constructHazelcastClient(AddressProvider addressProvider, ClientConfig clientConfig, ClientFailoverConfig failoverConfig, String instanceName, InstanceFuture<HazelcastClientProxy> future) {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
HazelcastClientProxy proxy;
try {
Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
ClientConnectionManagerFactory factory = new DefaultClientConnectionManagerFactory();
HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(instanceName, clientConfig, failoverConfig, factory, addressProvider);
client.start();
OutOfMemoryErrorDispatcher.registerClient(client);
proxy = new HazelcastClientProxy(client);
future.set(proxy);
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
return proxy;
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class LiteMemberClientMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean loaderEnabled) {
IMapMapStore mapStore = loaderEnabled ? new IMapMapStore() : null;
Config config = getConfig(mapStore, false);
ClientConfig clientConfig = getClientConfig();
// create a Hazelcast member to hold the data
hazelcastFactory.newHazelcastInstance(config);
// create a Hazelcast client to be used in the tests
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
IMapDataStructureAdapter<K, V> dataAdapter = new IMapDataStructureAdapter<K, V>(clientMap);
// wait until the initial load is done
dataAdapter.waitUntilLoaded();
NearCacheTestContextBuilder<K, V, Data, String> builder = createNearCacheContextBuilder(mapStore);
return builder.setDataInstance(client).setDataAdapter(dataAdapter).setLoader(mapStore).build();
}
Aggregations