use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method createNearCacheTest.
protected NearCacheTestContext createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig cacheConfig) {
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
//noinspection unchecked
ICache<Object, String> cache = cacheManager.createCache(cacheName, cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
return new NearCacheTestContext(client, cacheManager, nearCacheManager, cache, nearCache);
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new IMapDataStructureAdapter<K, V>(clientMap), new IMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
use of com.hazelcast.client.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientReplicatedMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
Config config = getConfig();
config.getReplicatedMapConfig(DEFAULT_NEAR_CACHE_NAME).setInMemoryFormat(nearCacheConfig.getInMemoryFormat());
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
ReplicatedMap<K, V> memberMap = member.getReplicatedMap(DEFAULT_NEAR_CACHE_NAME);
ReplicatedMap<K, V> clientMap = client.getReplicatedMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ReplicatedMapDataStructureAdapter<K, V>(clientMap), new ReplicatedMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
use of com.hazelcast.client.impl.HazelcastClientProxy 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.impl.HazelcastClientProxy in project hazelcast by hazelcast.
the class HazelcastClientManager method newHazelcastClient.
@SuppressWarnings("unchecked")
public static HazelcastInstance newHazelcastClient(ClientConfig config, HazelcastClientFactory hazelcastClientFactory) {
if (config == null) {
config = new XmlClientConfigBuilder().build();
}
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
HazelcastClientProxy proxy;
try {
Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
ClientConnectionManagerFactory clientConnectionManagerFactory = new DefaultClientConnectionManagerFactory();
final HazelcastClientInstanceImpl client = hazelcastClientFactory.createHazelcastInstanceClient(config, clientConnectionManagerFactory);
client.start();
OutOfMemoryErrorDispatcher.registerClient(client);
proxy = hazelcastClientFactory.createProxy(client);
if (INSTANCE.clients.putIfAbsent(client.getName(), proxy) != null) {
throw new DuplicateInstanceNameException("HazelcastClientInstance with name '" + client.getName() + "' already exists!");
}
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
return proxy;
}
Aggregations