Search in sources :

Example 6 with HazelcastClientProxy

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);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 7 with HazelcastClientProxy

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);
}
Also used : NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 8 with HazelcastClientProxy

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);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 9 with HazelcastClientProxy

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;
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConnectionManagerFactory(com.hazelcast.client.impl.ClientConnectionManagerFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 10 with HazelcastClientProxy

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;
}
Also used : DuplicateInstanceNameException(com.hazelcast.core.DuplicateInstanceNameException) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConnectionManagerFactory(com.hazelcast.client.impl.ClientConnectionManagerFactory) DefaultClientConnectionManagerFactory(com.hazelcast.client.impl.DefaultClientConnectionManagerFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) DefaultClientConnectionManagerFactory(com.hazelcast.client.impl.DefaultClientConnectionManagerFactory) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Aggregations

HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)18 ClientConfig (com.hazelcast.client.config.ClientConfig)13 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 Data (com.hazelcast.nio.serialization.Data)9 CachingProvider (javax.cache.spi.CachingProvider)9 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)8 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)7 NearCacheTestContext (com.hazelcast.internal.nearcache.NearCacheTestContext)6 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 CacheConfig (com.hazelcast.config.CacheConfig)5 NearCacheConfig (com.hazelcast.config.NearCacheConfig)5 Config (com.hazelcast.config.Config)4 Test (org.junit.Test)4 HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)3 NightlyTest (com.hazelcast.test.annotation.NightlyTest)3 CacheManager (javax.cache.CacheManager)3 ClientCacheProxy (com.hazelcast.client.cache.impl.ClientCacheProxy)2 XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2