本文整理汇总了Java中com.hazelcast.core.HazelcastInstance.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java HazelcastInstance.shutdown方法的具体用法?Java HazelcastInstance.shutdown怎么用?Java HazelcastInstance.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hazelcast.core.HazelcastInstance
的用法示例。
在下文中一共展示了HazelcastInstance.shutdown方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configInstanceWithName
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的package包/类
@Test
public void configInstanceWithName() {
Config config = new Config("my-test-instance");
HazelcastInstance existingHazelcastInstance = Hazelcast
.newHazelcastInstance(config);
try {
load(HazelcastConfigWithName.class,
"spring.hazelcast.config=this-is-ignored.xml");
HazelcastInstance hazelcastInstance = this.context
.getBean(HazelcastInstance.class);
assertThat(hazelcastInstance.getConfig().getInstanceName())
.isEqualTo("my-test-instance");
// Should reuse any existing instance by default.
assertThat(hazelcastInstance).isEqualTo(existingHazelcastInstance);
}
finally {
existingHazelcastInstance.shutdown();
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:HazelcastAutoConfigurationTests.java
示例2: testFailover
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的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);
}
示例3: testInstanceDown
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的package包/类
@Test
public void testInstanceDown(){
ArgumentCaptor<InstanceInfo> captor = ArgumentCaptor.forClass(InstanceInfo.class);
EurekaHttpResponse<Applications> response = generateMockResponse(Collections.<InstanceInfo>emptyList());
when(requestHandler.getApplications()).thenReturn(response);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
verify(requestHandler, timeout(5000).times(2)).register(captor.capture());
response = generateMockResponse(captor.getAllValues());
when(requestHandler.getApplications()).thenReturn(response);
hz1.shutdown();
ArgumentCaptor<String> id = ArgumentCaptor.forClass(String.class);
verify(requestHandler, timeout(5000).times(1)).cancel(anyString(), id.capture());
reset(requestHandler);
for(InstanceInfo info : captor.getAllValues()){
if(info.getId().equals(id.getValue())){
captor.getAllValues().remove(info);
break;
}
}
response = generateMockResponse(captor.getAllValues());
when(requestHandler.getApplications()).thenReturn(response);
assertClusterSizeEventually(1, hz2);
}
示例4: destroy
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的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();
}
}
示例5: lifecycleEvent
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的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();
}
}
}
示例6: testNativeClient
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的package包/类
@Test
public void testNativeClient() throws Exception {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new ClasspathXmlConfig("hazelcast-custom.xml");
HazelcastInstance main = factory.newHazelcastInstance(config);
Properties props = getDefaultProperties();
props.remove(CacheEnvironment.CONFIG_FILE_PATH_LEGACY);
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
props.setProperty(CacheEnvironment.CONFIG_FILE_PATH,"hazelcast-client-custom.xml");
HazelcastMockInstanceLoader loader = new HazelcastMockInstanceLoader();
loader.configure(props);
loader.setInstanceFactory(factory);
SessionFactory sf = createSessionFactory(props, loader);
final HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
assertTrue(hz instanceof HazelcastClientProxy);
assertEquals(1, main.getCluster().getMembers().size());
HazelcastClientProxy client = (HazelcastClientProxy) hz;
ClientConfig clientConfig = client.getClientConfig();
assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
assertTrue(clientConfig.getNetworkConfig().isSmartRouting());
assertTrue(clientConfig.getNetworkConfig().isRedoOperation());
factory.newHazelcastInstance(config);
assertEquals(2, hz.getCluster().getMembers().size());
main.shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, hz.getCluster().getMembers().size());
}
});
assertEquals(1, hz.getCluster().getMembers().size());
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(new DummyEntity(1L, "dummy", 0, new Date()));
tx.commit();
session.close();
sf.close();
factory.shutdownAll();
}
示例7: testNativeClient
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的package包/类
@Test
public void testNativeClient() throws Exception {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new ClasspathXmlConfig("hazelcast-custom.xml");
HazelcastInstance main = factory.newHazelcastInstance(config);
Properties props = getDefaultProperties();
props.remove(CacheEnvironment.CONFIG_FILE_PATH_LEGACY);
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost");
props.setProperty(CacheEnvironment.CONFIG_FILE_PATH,"hazelcast-client-custom.xml");
HazelcastMockInstanceLoader loader = new HazelcastMockInstanceLoader();
loader.configure(props);
loader.setInstanceFactory(factory);
SessionFactory sf = createSessionFactory(props, loader);
final HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
assertTrue(hz instanceof HazelcastClientProxy);
assertEquals(1, main.getCluster().getMembers().size());
HazelcastClientProxy client = (HazelcastClientProxy) hz;
ClientConfig clientConfig = client.getClientConfig();
assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
assertTrue(clientConfig.getNetworkConfig().isSmartRouting());
assertTrue(clientConfig.getNetworkConfig().isRedoOperation());
factory.newHazelcastInstance(config);
assertEquals(2, hz.getCluster().getMembers().size());
main.shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, hz.getCluster().getMembers().size());
}
});
assertEquals(1, hz.getCluster().getMembers().size());
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(new DummyEntity(1L, "dummy", 0, new Date()));
tx.commit();
session.close();
sf.close();
factory.shutdownAll();
}
示例8: testNativeClient
import com.hazelcast.core.HazelcastInstance; //导入方法依赖的package包/类
@Test
public void testNativeClient() throws Exception {
TestHazelcastFactory factory = new TestHazelcastFactory();
Config config = new ClasspathXmlConfig("hazelcast-custom.xml");
HazelcastInstance main = factory.newHazelcastInstance(config);
Properties props = getDefaultProperties();
props.remove(CacheEnvironment.CONFIG_FILE_PATH_LEGACY);
props.setProperty(Environment.CACHE_REGION_FACTORY, HazelcastCacheRegionFactory.class.getName());
props.setProperty(CacheEnvironment.USE_NATIVE_CLIENT, "true");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_GROUP, "dev-custom");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_PASSWORD, "dev-pass");
props.setProperty(CacheEnvironment.NATIVE_CLIENT_ADDRESS, "localhost");
props.setProperty(CacheEnvironment.CONFIG_FILE_PATH,"hazelcast-client-custom.xml");
HazelcastMockInstanceLoader loader = new HazelcastMockInstanceLoader();
loader.configure(props);
loader.setInstanceFactory(factory);
SessionFactory sf = createSessionFactory(props, loader);
final HazelcastInstance hz = HazelcastAccessor.getHazelcastInstance(sf);
assertTrue(hz instanceof HazelcastClientProxy);
assertEquals(1, main.getCluster().getMembers().size());
HazelcastClientProxy client = (HazelcastClientProxy) hz;
ClientConfig clientConfig = client.getClientConfig();
assertEquals("dev-custom", clientConfig.getGroupConfig().getName());
assertEquals("dev-pass", clientConfig.getGroupConfig().getPassword());
assertTrue(clientConfig.getNetworkConfig().isSmartRouting());
assertTrue(clientConfig.getNetworkConfig().isRedoOperation());
factory.newHazelcastInstance(config);
assertEquals(2, hz.getCluster().getMembers().size());
main.shutdown();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, hz.getCluster().getMembers().size());
}
});
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.save(new DummyEntity(1L, "dummy", 0, new Date()));
tx.commit();
session.close();
sf.close();
factory.shutdownAll();
}