Search in sources :

Example 1 with ClientConnectionManagerFactory

use of com.hazelcast.client.impl.ClientConnectionManagerFactory 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 2 with ClientConnectionManagerFactory

use of com.hazelcast.client.impl.ClientConnectionManagerFactory 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

XmlClientConfigBuilder (com.hazelcast.client.config.XmlClientConfigBuilder)2 ClientConnectionManagerFactory (com.hazelcast.client.impl.ClientConnectionManagerFactory)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)2 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)2 HazelcastClient (com.hazelcast.client.HazelcastClient)1 AddressProvider (com.hazelcast.client.connection.AddressProvider)1 DefaultClientConnectionManagerFactory (com.hazelcast.client.impl.DefaultClientConnectionManagerFactory)1 DuplicateInstanceNameException (com.hazelcast.core.DuplicateInstanceNameException)1