com.guicedee.guicedhazelcast.implementations.HazelcastClientProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-hazelcast Show documentation
Show all versions of guiced-hazelcast Show documentation
An integration library for Hazelcast and Guice utilizing a GuiceContext Injector.
package com.guicedee.guicedhazelcast.implementations;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import com.guicedee.guicedinjection.interfaces.IGuicePreDestroy;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.config.InvalidConfigurationException;
import com.hazelcast.core.HazelcastInstance;
import org.apache.commons.lang3.RandomUtils;
import java.util.Random;
import static com.guicedee.guicedhazelcast.services.HazelcastClientPreStartup.*;
public class HazelcastClientProvider
implements Provider, IGuicePreDestroy
{
@Override
public HazelcastInstance get()
{
//Only start a client instance if i didn't start a local one
if (ModuleLayer.boot()
.findModule("za.co.bayport.jpms.caching")
.isEmpty())
{
try
{
clientInstance = HazelcastClient.newHazelcastClient(config);
}catch (ProvisionException | InvalidConfigurationException pe)
{
config.setInstanceName(config.getInstanceName() + "_" + RandomUtils.nextInt(1, 100));
clientInstance = HazelcastClient.newHazelcastClient(config);
}
}
return clientInstance;
}
@Override
public void onDestroy()
{
if (clientInstance != null)
{
clientInstance.shutdown();
clientInstance = null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy