本文整理汇总了Java中org.springframework.context.support.StaticApplicationContext.close方法的典型用法代码示例。如果您正苦于以下问题:Java StaticApplicationContext.close方法的具体用法?Java StaticApplicationContext.close怎么用?Java StaticApplicationContext.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.support.StaticApplicationContext
的用法示例。
在下文中一共展示了StaticApplicationContext.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGoodConnection
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testGoodConnection() throws MqttException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例2: taskExecutorByBeanType
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void taskExecutorByBeanType() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
context.registerBeanDefinition("postProcessor", processorDefinition);
BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
context.registerBeanDefinition("myExecutor", executorDefinition);
BeanDefinition targetDefinition =
new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
context.registerBeanDefinition("target", targetDefinition);
context.refresh();
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertTrue(asyncThread.getName().startsWith("testExecutor"));
context.close();
}
示例3: listenersInApplicationContextWithPayloadEvents
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void listenersInApplicationContextWithPayloadEvents() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("listener", new RootBeanDefinition(MyPayloadListener.class));
context.refresh();
MyPayloadListener listener = context.getBean("listener", MyPayloadListener.class);
context.publishEvent("event1");
context.publishEvent("event2");
context.publishEvent("event3");
context.publishEvent("event4");
assertTrue(listener.seenPayloads.contains("event1"));
assertTrue(listener.seenPayloads.contains("event2"));
assertTrue(listener.seenPayloads.contains("event3"));
assertTrue(listener.seenPayloads.contains("event4"));
AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
assertEquals(2, multicaster.retrieverCache.size());
context.close();
}
示例4: listenersInApplicationContextWithNestedChild
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void listenersInApplicationContextWithNestedChild() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition nestedChild = new RootBeanDefinition(StaticApplicationContext.class);
nestedChild.getPropertyValues().add("parent", context);
nestedChild.setInitMethodName("refresh");
context.registerBeanDefinition("nestedChild", nestedChild);
RootBeanDefinition listener1Def = new RootBeanDefinition(MyOrderedListener1.class);
listener1Def.setDependsOn("nestedChild");
context.registerBeanDefinition("listener1", listener1Def);
context.refresh();
MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
MyEvent event1 = new MyEvent(context);
context.publishEvent(event1);
assertTrue(listener1.seenEvents.contains(event1));
SimpleApplicationEventMulticaster multicaster = context.getBean(
AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
SimpleApplicationEventMulticaster.class);
assertFalse(multicaster.getApplicationListeners().isEmpty());
context.close();
assertTrue(multicaster.getApplicationListeners().isEmpty());
}
示例5: nonSingletonListenerInApplicationContext
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void nonSingletonListenerInApplicationContext() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition listener = new RootBeanDefinition(MyNonSingletonListener.class);
listener.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
context.registerBeanDefinition("listener", listener);
context.refresh();
MyEvent event1 = new MyEvent(context);
context.publishEvent(event1);
MyOtherEvent event2 = new MyOtherEvent(context);
context.publishEvent(event2);
MyEvent event3 = new MyEvent(context);
context.publishEvent(event3);
MyOtherEvent event4 = new MyOtherEvent(context);
context.publishEvent(event4);
assertTrue(MyNonSingletonListener.seenEvents.contains(event1));
assertTrue(MyNonSingletonListener.seenEvents.contains(event2));
assertTrue(MyNonSingletonListener.seenEvents.contains(event3));
assertTrue(MyNonSingletonListener.seenEvents.contains(event4));
MyNonSingletonListener.seenEvents.clear();
context.close();
}
示例6: testMqttConnectOptionsAutomaticReconnectDefaultServerAvailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectDefaultServerAvailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
// simulate a lost connection
CRUSHER_PROXY.reopen();
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1000);
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(1, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例7: testMqttConnectOptionsAutomaticReconnectFalseServerAvailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectFalseServerAvailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.getMqttConnectOptions().setAutomaticReconnect(false);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
// simulate a lost connection
CRUSHER_PROXY.reopen();
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1000);
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(1, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例8: testMqttConnectOptionsAutomaticReconnectTrueServerAvailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectTrueServerAvailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.getMqttConnectOptions().setAutomaticReconnect(true);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
// simulate a lost connection
CRUSHER_PROXY.reopen();
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1100);
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
Assert.assertEquals(2, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(1, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例9: testMqttConnectOptionsAutomaticReconnectDefaultServerUnavailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectDefaultServerUnavailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
CRUSHER_PROXY.close();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
Assert.assertFalse(service.start());
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1000);
CRUSHER_PROXY.open();
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1100);
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Assert.assertEquals(0, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(1, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例10: testMqttConnectOptionsAutomaticReconnectFalseServerUnavailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectFalseServerUnavailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
CRUSHER_PROXY.close();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.getMqttConnectOptions().setAutomaticReconnect(false);
Assert.assertFalse(service.start());
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1000);
CRUSHER_PROXY.open();
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1100);
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Assert.assertEquals(0, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(1, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例11: testMqttConnectOptionsAutomaticReconnectTrueServerUnavailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMqttConnectOptionsAutomaticReconnectTrueServerUnavailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
CRUSHER_PROXY.close();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.getMqttConnectOptions().setAutomaticReconnect(true);
Assert.assertFalse(service.start());
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1000);
CRUSHER_PROXY.open();
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Thread.sleep(1100);
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1100);
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
Assert.assertEquals(0, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(1, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例12: testReconnectDetailsSetServerAvailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testReconnectDetailsSetServerAvailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
Assert.assertTrue(service.start());
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
// simulate a lost connection
CRUSHER_PROXY.reopen();
Assert.assertFalse(service.isStarted());
Assert.assertFalse(service.isConnected());
Thread.sleep(1100);
Assert.assertTrue(service.isStarted());
Assert.assertTrue(service.isConnected());
Assert.assertEquals(2, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(1, clientLostConnectionCount.get());
Assert.assertEquals(0, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例13: testReconnectDetailsSetServerUnavailableAtStartup
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testReconnectDetailsSetServerUnavailableAtStartup()
throws MqttException, InterruptedException
{
StaticApplicationContext applicationContext = getStaticApplicationContext();
CRUSHER_PROXY.close();
TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
null);
service.setApplicationEventPublisher(applicationContext);
service.setInboundMessageChannel(inboundMessageChannel);
service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
MqttQualityOfService.QOS_0);
service.getMqttConnectOptions().setCleanSession(true);
service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
Assert.assertFalse(service.start());
Assert.assertFalse(service.isConnected());
Assert.assertFalse(service.isStarted());
CRUSHER_PROXY.open();
Thread.sleep(3100);
Assert.assertTrue(service.isConnected());
Assert.assertTrue(service.isStarted());
Assert.assertEquals(1, clientConnectedCount.get());
Assert.assertEquals(0, clientDisconnectedCount.get());
Assert.assertEquals(0, clientLostConnectionCount.get());
Assert.assertEquals(1, clientFailedConnectionCount.get());
service.stop();
service.close();
applicationContext.close();
}
示例14: taskExecutorByBeanName
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void taskExecutorByBeanName() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
context.registerBeanDefinition("postProcessor", processorDefinition);
BeanDefinition executorDefinition = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
executorDefinition.getPropertyValues().add("threadNamePrefix", "testExecutor");
context.registerBeanDefinition("myExecutor", executorDefinition);
BeanDefinition executorDefinition2 = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
executorDefinition2.getPropertyValues().add("threadNamePrefix", "testExecutor2");
context.registerBeanDefinition("taskExecutor", executorDefinition2);
BeanDefinition targetDefinition =
new RootBeanDefinition(AsyncAnnotationBeanPostProcessorTests.TestBean.class);
context.registerBeanDefinition("target", targetDefinition);
context.refresh();
ITestBean testBean = context.getBean("target", ITestBean.class);
testBean.test();
testBean.await(3000);
Thread asyncThread = testBean.getThread();
assertTrue(asyncThread.getName().startsWith("testExecutor2"));
context.close();
}
示例15: testMethodValidationPostProcessor
import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void testMethodValidationPostProcessor() {
StaticApplicationContext ac = new StaticApplicationContext();
ac.registerSingleton("mvpp", MethodValidationPostProcessor.class);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("beforeExistingAdvisors", false);
ac.registerSingleton("aapp", AsyncAnnotationBeanPostProcessor.class, pvs);
ac.registerSingleton("bean", MyValidBean.class);
ac.refresh();
doTestProxyValidation(ac.getBean("bean", MyValidInterface.class));
ac.close();
}