Search in sources :

Example 1 with ProxyFactoryConfig

use of com.hazelcast.client.config.ProxyFactoryConfig in project hazelcast by hazelcast.

the class ProxyManager method init.

public void init(ClientConfig config) {
    // register defaults
    register(MapService.SERVICE_NAME, createServiceProxyFactory(MapService.class));
    if (JCacheDetector.isJCacheAvailable(config.getClassLoader())) {
        register(ICacheService.SERVICE_NAME, new ClientCacheProxyFactory(client));
    }
    register(QueueService.SERVICE_NAME, ClientQueueProxy.class);
    register(MultiMapService.SERVICE_NAME, ClientMultiMapProxy.class);
    register(ListService.SERVICE_NAME, ClientListProxy.class);
    register(SetService.SERVICE_NAME, ClientSetProxy.class);
    register(SemaphoreService.SERVICE_NAME, ClientSemaphoreProxy.class);
    register(TopicService.SERVICE_NAME, ClientTopicProxy.class);
    register(AtomicLongService.SERVICE_NAME, ClientAtomicLongProxy.class);
    register(AtomicReferenceService.SERVICE_NAME, ClientAtomicReferenceProxy.class);
    register(DistributedExecutorService.SERVICE_NAME, ClientExecutorServiceProxy.class);
    register(DistributedDurableExecutorService.SERVICE_NAME, ClientDurableExecutorServiceProxy.class);
    register(LockServiceImpl.SERVICE_NAME, ClientLockProxy.class);
    register(CountDownLatchService.SERVICE_NAME, ClientCountDownLatchProxy.class);
    register(MapReduceService.SERVICE_NAME, ClientMapReduceProxy.class);
    register(ReplicatedMapService.SERVICE_NAME, ClientReplicatedMapProxy.class);
    register(XAService.SERVICE_NAME, XAResourceProxy.class);
    register(RingbufferService.SERVICE_NAME, ClientRingbufferProxy.class);
    register(ReliableTopicService.SERVICE_NAME, new ClientProxyFactory() {

        public ClientProxy create(String id) {
            return new ClientReliableTopicProxy(id, client);
        }
    });
    register(IdGeneratorService.SERVICE_NAME, new ClientProxyFactory() {

        public ClientProxy create(String id) {
            IAtomicLong atomicLong = client.getAtomicLong(IdGeneratorService.ATOMIC_LONG_NAME + id);
            return new ClientIdGeneratorProxy(IdGeneratorService.SERVICE_NAME, id, atomicLong);
        }
    });
    register(CardinalityEstimatorService.SERVICE_NAME, ClientCardinalityEstimatorProxy.class);
    register(DistributedScheduledExecutorService.SERVICE_NAME, ClientScheduledExecutorProxy.class);
    for (ProxyFactoryConfig proxyFactoryConfig : config.getProxyFactoryConfigs()) {
        try {
            ClassLoader classLoader = config.getClassLoader();
            ClientProxyFactory clientProxyFactory = proxyFactoryConfig.getFactoryImpl();
            if (clientProxyFactory == null) {
                String className = proxyFactoryConfig.getClassName();
                clientProxyFactory = ClassLoaderUtil.newInstance(classLoader, className);
            }
            register(proxyFactoryConfig.getService(), clientProxyFactory);
        } catch (Exception e) {
            throw ExceptionUtil.rethrow(e);
        }
    }
    readProxyDescriptors();
}
Also used : ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientCacheProxyFactory(com.hazelcast.client.cache.impl.ClientCacheProxyFactory) ClientReliableTopicProxy(com.hazelcast.client.proxy.ClientReliableTopicProxy) MultiMapService(com.hazelcast.multimap.impl.MultiMapService) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) MapService(com.hazelcast.map.impl.MapService) IAtomicLong(com.hazelcast.core.IAtomicLong) HazelcastException(com.hazelcast.core.HazelcastException) ClientServiceNotFoundException(com.hazelcast.client.spi.impl.ClientServiceNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClientIdGeneratorProxy(com.hazelcast.client.proxy.ClientIdGeneratorProxy)

Example 2 with ProxyFactoryConfig

use of com.hazelcast.client.config.ProxyFactoryConfig in project hazelcast by hazelcast.

the class ProxyFactoryTest method testCustomProxy_usingFactoryClassName.

@Test
public void testCustomProxy_usingFactoryClassName() {
    ClientConfig clientConfig = new ClientConfig();
    ProxyFactoryConfig proxyFactoryConfig = new ProxyFactoryConfig();
    proxyFactoryConfig.setService(SERVICE_NAME);
    proxyFactoryConfig.setClassName(CustomProxyFactory.class.getName());
    clientConfig.addProxyFactoryConfig(proxyFactoryConfig);
    testCustomProxy(clientConfig);
}
Also used : ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ProxyFactoryConfig

use of com.hazelcast.client.config.ProxyFactoryConfig in project hazelcast by hazelcast.

the class ProxyFactoryTest method testCustomProxy_usingFactoryImplementation.

@Test
public void testCustomProxy_usingFactoryImplementation() {
    ClientConfig clientConfig = new ClientConfig();
    ProxyFactoryConfig proxyFactoryConfig = new ProxyFactoryConfig();
    proxyFactoryConfig.setService(SERVICE_NAME);
    proxyFactoryConfig.setFactoryImpl(new CustomProxyFactory());
    clientConfig.addProxyFactoryConfig(proxyFactoryConfig);
    testCustomProxy(clientConfig);
}
Also used : ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ProxyFactoryConfig

use of com.hazelcast.client.config.ProxyFactoryConfig in project hazelcast by hazelcast.

the class ProxyFactoryTest method testProxy_whenInitThrowsError.

@Test
public void testProxy_whenInitThrowsError() {
    ClientConfig clientConfig = new ClientConfig();
    ProxyFactoryConfig proxyFactoryConfig = new ProxyFactoryConfig();
    proxyFactoryConfig.setService(SERVICE_NAME);
    proxyFactoryConfig.setFactoryImpl(new ClientProxyFactory() {

        @Override
        public ClientProxy create(String id) {
            return new ClientProxy(SERVICE_NAME, id) {

                @Override
                protected void onInitialize() {
                    super.onInitialize();
                    throw new ExpectedError();
                }
            };
        }
    });
    clientConfig.addProxyFactoryConfig(proxyFactoryConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    String objectName = "custom-object";
    try {
        client.getDistributedObject(SERVICE_NAME, objectName);
        fail("Client proxy initialization should fail!");
    } catch (ExpectedError expected) {
    }
}
Also used : ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ProxyFactoryConfig

use of com.hazelcast.client.config.ProxyFactoryConfig in project hazelcast by hazelcast.

the class TestClientApplicationContext method testClient.

@Test
public void testClient() {
    assertNotNull(client);
    assertNotNull(client2);
    assertNotNull(client3);
    ClientConfig config = client.getClientConfig();
    assertEquals("13", config.getProperty("hazelcast.client.retry.count"));
    assertEquals(3, config.getNetworkConfig().getConnectionAttemptLimit());
    assertEquals(1000, config.getNetworkConfig().getConnectionTimeout());
    assertEquals(3000, config.getNetworkConfig().getConnectionAttemptPeriod());
    ClientConfig config2 = client2.getClientConfig();
    assertEquals(credentials, config2.getSecurityConfig().getCredentials());
    client.getMap("default").put("Q", "q");
    client2.getMap("default").put("X", "x");
    IMap<Object, Object> map = instance.getMap("default");
    assertEquals("q", map.get("Q"));
    assertEquals("x", map.get("X"));
    ClientConfig config3 = client3.getClientConfig();
    SerializationConfig serConf = config3.getSerializationConfig();
    assertEquals(ByteOrder.BIG_ENDIAN, serConf.getByteOrder());
    assertEquals(false, serConf.isAllowUnsafe());
    assertEquals(false, serConf.isCheckClassDefErrors());
    assertEquals(false, serConf.isEnableCompression());
    assertEquals(false, serConf.isEnableSharedObject());
    assertEquals(false, serConf.isUseNativeByteOrder());
    assertEquals(10, serConf.getPortableVersion());
    Map<Integer, String> map1 = serConf.getDataSerializableFactoryClasses();
    assertNotNull(map1);
    assertTrue(map1.containsKey(1));
    assertEquals("com.hazelcast.spring.serialization.DummyDataSerializableFactory", map1.get(1));
    Map<Integer, String> portableFactoryClasses = serConf.getPortableFactoryClasses();
    assertNotNull(portableFactoryClasses);
    assertTrue(portableFactoryClasses.containsKey(2));
    assertEquals("com.hazelcast.spring.serialization.DummyPortableFactory", portableFactoryClasses.get(2));
    Collection<SerializerConfig> serializerConfigs = serConf.getSerializerConfigs();
    assertNotNull(serializerConfigs);
    SerializerConfig serializerConfig = serializerConfigs.iterator().next();
    assertNotNull(serializerConfig);
    assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$FooXmlSerializer", serializerConfig.getClassName());
    assertEquals("com.hazelcast.nio.serialization.CustomSerializationTest$Foo", serializerConfig.getTypeClassName());
    List<ProxyFactoryConfig> proxyFactoryConfigs = config3.getProxyFactoryConfigs();
    assertNotNull(proxyFactoryConfigs);
    ProxyFactoryConfig proxyFactoryConfig = proxyFactoryConfigs.get(0);
    assertNotNull(proxyFactoryConfig);
    assertEquals("com.hazelcast.spring.DummyProxyFactory", proxyFactoryConfig.getClassName());
    assertEquals("MyService", proxyFactoryConfig.getService());
    LoadBalancer loadBalancer = config3.getLoadBalancer();
    assertNotNull(loadBalancer);
    assertTrue(loadBalancer instanceof RoundRobinLB);
    NearCacheConfig nearCacheConfig = config3.getNearCacheConfig("default");
    assertNotNull(nearCacheConfig);
    assertEquals(1, nearCacheConfig.getTimeToLiveSeconds());
    assertEquals(70, nearCacheConfig.getMaxIdleSeconds());
    assertEquals(EvictionPolicy.LRU, nearCacheConfig.getEvictionConfig().getEvictionPolicy());
    assertEquals(4000, nearCacheConfig.getEvictionConfig().getSize());
    assertEquals(true, nearCacheConfig.isInvalidateOnChange());
    assertEquals(CACHE_ON_UPDATE, nearCacheConfig.getLocalUpdatePolicy());
}
Also used : SerializationConfig(com.hazelcast.config.SerializationConfig) LoadBalancer(com.hazelcast.client.LoadBalancer) NearCacheConfig(com.hazelcast.config.NearCacheConfig) RoundRobinLB(com.hazelcast.client.util.RoundRobinLB) SerializerConfig(com.hazelcast.config.SerializerConfig) ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ProxyFactoryConfig (com.hazelcast.client.config.ProxyFactoryConfig)5 ClientConfig (com.hazelcast.client.config.ClientConfig)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 LoadBalancer (com.hazelcast.client.LoadBalancer)1 ClientCacheProxyFactory (com.hazelcast.client.cache.impl.ClientCacheProxyFactory)1 ClientIdGeneratorProxy (com.hazelcast.client.proxy.ClientIdGeneratorProxy)1 ClientReliableTopicProxy (com.hazelcast.client.proxy.ClientReliableTopicProxy)1 ClientServiceNotFoundException (com.hazelcast.client.spi.impl.ClientServiceNotFoundException)1 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IAtomicLong (com.hazelcast.core.IAtomicLong)1 MapService (com.hazelcast.map.impl.MapService)1 MultiMapService (com.hazelcast.multimap.impl.MultiMapService)1 ReplicatedMapService (com.hazelcast.replicatedmap.impl.ReplicatedMapService)1