本文整理汇总了Java中com.hazelcast.core.Hazelcast.getHazelcastInstanceByName方法的典型用法代码示例。如果您正苦于以下问题:Java Hazelcast.getHazelcastInstanceByName方法的具体用法?Java Hazelcast.getHazelcastInstanceByName怎么用?Java Hazelcast.getHazelcastInstanceByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hazelcast.core.Hazelcast
的用法示例。
在下文中一共展示了Hazelcast.getHazelcastInstanceByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("balance");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("balance");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.icthh.xm.ms.balance.domain.*", initializeDomainMapConfig(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
示例2: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("dashboard");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("dashboard");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.icthh.xm.ms.dashboard.domain.*", initializeDomainMapConfig(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
示例3: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("gate");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("gate");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.icthh.xm.gate.domain.*", initializeDomainMapConfig(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
示例4: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
@Primary
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("entity");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("entity");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.icthh.xm.ms.entity.domain.*", initializeDomainMapConfig(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
示例5: getOrCreateHzInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
private HazelcastInstance getOrCreateHzInstance(Map<String, Object> parameters) {
// Query param named 'hazelcastInstance' (if exists) overrides the instance that was set
HazelcastInstance hzInstance = resolveAndRemoveReferenceParameter(parameters, HAZELCAST_INSTANCE_PARAM, HazelcastInstance.class);
// check if an already created instance is given then just get instance by its name.
if (hzInstance == null && parameters.get(HAZELCAST_INSTANCE_NAME_PARAM) != null) {
hzInstance = Hazelcast.getHazelcastInstanceByName((String) parameters.get(HAZELCAST_INSTANCE_NAME_PARAM));
}
// Now create onw instance component
if (hzInstance == null) {
if (hazelcastInstance == null) {
createOwnInstance = true;
hazelcastInstance = createOwnInstance();
}
hzInstance = hazelcastInstance;
}
return hzInstance;
}
示例6: testFailover
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Test(timeout = 80000)
public void testFailover() throws Exception {
CookieStore cookieStore = new BasicCookieStore();
String value = executeRequest("read", SERVER_PORT_1, cookieStore);
assertEquals("null", value);
executeRequest("write", SERVER_PORT_1, cookieStore);
instance1.stop();
HazelcastInstance hzInstance1 = Hazelcast.getHazelcastInstanceByName("hzInstance1");
if (hzInstance1 != null) {
hzInstance1.shutdown();
}
value = executeRequest("read", SERVER_PORT_2, cookieStore);
assertEquals("value", value);
}
示例7: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
public HazelcastInstance hazelcastInstance(JHipsterProperties jHipsterProperties) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance = Hazelcast.getHazelcastInstanceByName("uaa");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("uaa");
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().setPortAutoIncrement(true);
// In development, remove multicast auto-configuration
if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)) {
System.setProperty("hazelcast.local.localAddress", "127.0.0.1");
config.getNetworkConfig().getJoin().getAwsConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(false);
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.icthh.xm.uaa.domain.*", initializeDomainMapConfig(jHipsterProperties));
// Uncomment if session needed
//config.getMapConfigs().put("clustered-http-sessions", initializeClusteredSession(jHipsterProperties));
return Hazelcast.newHazelcastInstance(config);
}
示例8: getStatistics
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Override
protected CacheStatistics[] getStatistics() {
final List<CacheStatistics> statsList = new ArrayList<>();
final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
LOGGER.debug("Locating hazelcast instance [{}]...", hz.getCluster().getInstanceName());
final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hz.getCluster().getInstanceName());
instance.getConfig().getMapConfigs().keySet().forEach(key -> {
final IMap map = instance.getMap(key);
LOGGER.debug("Starting to collect hazelcast statistics for map [{}] identified by key [{}]...", map, key);
statsList.add(new HazelcastStatistics(map, hz.getCluster().getMembers().size()));
});
return statsList.toArray(new CacheStatistics[statsList.size()]);
}
示例9: fillModel
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(INSTANCE_NAME);
if (instance != null) {
IMap<String, byte[]> taskCache = instance.getMap(TASK_CACHE_NAME);
LocalMapStats statistics = taskCache.getLocalMapStats();
model.put("statistics", statistics);
}
}
示例10: hazelcastInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Bean
public HazelcastInstance hazelcastInstance(MessageServerConfig serverConfig) {
log.debug("Configuring Hazelcast");
HazelcastInstance hazelCastInstance =
Hazelcast.getHazelcastInstanceByName("message-server");
if (hazelCastInstance != null) {
log.debug("Hazelcast already initialized");
return hazelCastInstance;
}
Config config = new Config();
config.setInstanceName("message-server");
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
if (this.registration == null) {
log.warn("No discovery service is set up, Hazelcast cannot create a cluster.");
} else {
// The serviceId is by default the application's name, see Spring Boot's
// eureka.instance.appname property
String serviceId = registration.getServiceId();
log.debug("Configuring Hazelcast clustering for instanceId: {}", serviceId);
config.getNetworkConfig().setPort(5701);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
String clusterMember = instance.getHost() + ":5701";
log.debug("Adding Hazelcast (prod) cluster member " + clusterMember);
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(clusterMember);
}
}
config.getMapConfigs().put("default", initializeDefaultMapConfig());
config.getMapConfigs().put("com.blt.talk.domain.*",
initializeDomainMapConfig(serverConfig));
return Hazelcast.newHazelcastInstance(config);
}
示例11: SiddhiManager
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
public SiddhiManager(SiddhiConfiguration siddhiConfiguration) {
if (siddhiConfiguration.isDistributedProcessing()) {
HazelcastInstance hazelcastInstance = Hazelcast.getHazelcastInstanceByName(siddhiConfiguration.getInstanceIdentifier());
if (hazelcastInstance == null) {
this.siddhiContext = new SiddhiContext(siddhiConfiguration.getQueryPlanIdentifier(), SiddhiContext.ProcessingState.ENABLE_INTERNAL);
Config hazelcastConf = new Config();
//hazelcastConf.setProperty("hazelcast.logging.type", "log4j");
hazelcastConf.setConfigurationFile(new File("/opt/rb/etc/rb-bi/siddhi-hazelcast.xml"));
//hazelcastConf.getGroupConfig().setName(siddhiConfiguration.getQueryPlanIdentifier());
//hazelcastConf.setInstanceName(siddhiConfiguration.getInstanceIdentifier());
hazelcastInstance = Hazelcast.newHazelcastInstance(hazelcastConf);
} else {
this.siddhiContext = new SiddhiContext(siddhiConfiguration.getQueryPlanIdentifier(), SiddhiContext.ProcessingState.ENABLE_EXTERNAL);
}
siddhiContext.setHazelcastInstance(hazelcastInstance);
siddhiContext.setGlobalIndexGenerator(new GlobalIndexGenerator(siddhiContext));
} else {
this.siddhiContext = new SiddhiContext(siddhiConfiguration.getQueryPlanIdentifier(), SiddhiContext.ProcessingState.DISABLED);
}
this.siddhiContext.setEventBatchSize(siddhiConfiguration.getEventBatchSize());
this.siddhiContext.setAsyncProcessing(siddhiConfiguration.isAsyncProcessing());
this.siddhiContext.setSiddhiExtensions(siddhiConfiguration.getSiddhiExtensions());
this.siddhiContext.setThreadBarrier(new ThreadBarrier());
this.siddhiContext.setThreadPoolExecutor(new ThreadPoolExecutor(siddhiConfiguration.getThreadExecutorCorePoolSize(),
siddhiConfiguration.getThreadExecutorMaxPoolSize(),
50,
TimeUnit.MICROSECONDS,
new LinkedBlockingQueue<Runnable>(),
new SiddhiThreadFactory("Executor")));
this.siddhiContext.setScheduledExecutorService(Executors.newScheduledThreadPool(siddhiConfiguration.getThreadSchedulerCorePoolSize(), new SiddhiThreadFactory("Scheduler")));
this.siddhiContext.setSnapshotService(new SnapshotService(siddhiContext));
this.siddhiContext.setPersistenceService(new PersistenceService(siddhiContext));
this.siddhiContext.setEventMonitorService(new EventMonitorService(siddhiContext));
}
示例12: destroy
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
/**
* Destroys currently allocated instance.
*/
public void destroy() {
log.info("Shutting down Hazelcast instance [{}]..", hcInstanceName);
final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(
hcInstanceName);
if (instance != null) {
instance.shutdown();
}
}
示例13: loadInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Override
public HazelcastInstance loadInstance() throws CacheException {
if (existingInstanceName != null) {
instance = Hazelcast.getHazelcastInstanceByName(existingInstanceName);
if (instance == null) {
throw new CacheException("No instance with name [" + existingInstanceName + "] could be found.");
}
} else {
instance = Hazelcast.newHazelcastInstance(config);
}
return instance;
}
示例14: loadExistingInstance
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
private static HazelcastInstance loadExistingInstance(ClusteredSessionService sessionService, String instanceName)
throws ServletException {
LOGGER.info("Using existing Hazelcast instance with name [" + instanceName + "] for session replication");
HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(instanceName);
if (instance == null) {
throw new ServletException("Hazelcast instance with name [" + instanceName + "] could not be found.");
}
instance.getLifecycleService().addLifecycleListener(new ClientLifecycleListener(sessionService));
return instance;
}
示例15: lifecycleEvent
import com.hazelcast.core.Hazelcast; //导入方法依赖的package包/类
@Override
public void lifecycleEvent(LifecycleEvent event) {
String shutdown = System.getProperty("hazelcast.tomcat.shutdown_hazelcast_instance");
if (getConfigLocation() == null) {
setConfigLocation("hazelcast-default.xml");
}
if ("start".equals(event.getType())) {
try {
config = ConfigLoader.load(getConfigLocation());
} catch (IOException e) {
throw new RuntimeException("failed to load Config:", e);
}
if (config == null) {
throw new RuntimeException("failed to find configLocation:" + getConfigLocation());
}
if (config.getInstanceName() == null) {
config.setInstanceName(SessionManager.DEFAULT_INSTANCE_NAME);
}
Hazelcast.getOrCreateHazelcastInstance(config);
} else if ("stop".equals(event.getType()) && !"false".equals(shutdown)) {
HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(SessionManager.DEFAULT_INSTANCE_NAME);
if (instance != null) {
instance.shutdown();
}
}
}