当前位置: 首页>>代码示例>>Java>>正文


Java StaticApplicationContext.publishEvent方法代码示例

本文整理汇总了Java中org.springframework.context.support.StaticApplicationContext.publishEvent方法的典型用法代码示例。如果您正苦于以下问题:Java StaticApplicationContext.publishEvent方法的具体用法?Java StaticApplicationContext.publishEvent怎么用?Java StaticApplicationContext.publishEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.context.support.StaticApplicationContext的用法示例。


在下文中一共展示了StaticApplicationContext.publishEvent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ApplicationContextEventTests.java

示例2: 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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:ApplicationContextEventTests.java

示例3: 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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ApplicationContextEventTests.java

示例4: listenerAndBroadcasterWithCircularReference

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void listenerAndBroadcasterWithCircularReference() {
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("broadcaster", new RootBeanDefinition(BeanThatBroadcasts.class));
	RootBeanDefinition listenerDef = new RootBeanDefinition(BeanThatListens.class);
	listenerDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("broadcaster"));
	context.registerBeanDefinition("listener", listenerDef);
	context.refresh();

	BeanThatBroadcasts broadcaster = context.getBean("broadcaster", BeanThatBroadcasts.class);
	context.publishEvent(new MyEvent(context));
	assertEquals("The event was not received by the listener", 2, broadcaster.receivedCount);

	context.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:ApplicationContextEventTests.java

示例5: innerBeanAsListener

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void innerBeanAsListener() {
	StaticApplicationContext context = new StaticApplicationContext();
	RootBeanDefinition listenerDef = new RootBeanDefinition(TestBean.class);
	listenerDef.getPropertyValues().add("friends", new RootBeanDefinition(BeanThatListens.class));
	context.registerBeanDefinition("listener", listenerDef);
	context.refresh();

	context.publishEvent(new MyEvent(this));
	context.publishEvent(new MyEvent(this));
	TestBean listener = context.getBean(TestBean.class);
	assertEquals(3, ((BeanThatListens) listener.getFriends().iterator().next()).getEventCount());

	context.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:ApplicationContextEventTests.java

示例6: fruCacheEventTest

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
/**
 * Test Server FRU Component Cache Event Publisher
 */
@Test
public void fruCacheEventTest()
{

    HmsDataCache cache = new HmsDataCache();

    FruCacheUpdateListener listener = new FruCacheUpdateListener();
    listener.setHmsDataCache( cache );

    StaticApplicationContext context = new StaticApplicationContext();
    context.addApplicationListener( listener );

    context.refresh();

    // Adding dummy CPU Information
    List<CpuInfo> listCpu = new ArrayList<CpuInfo>();
    CpuInfo cpu1 = new CpuInfo();
    ComponentIdentifier cpuIdentifier1 = new ComponentIdentifier();
    cpuIdentifier1.setManufacturer( "INTEL" );
    cpuIdentifier1.setProduct( "Intel Xeon Processor" );
    cpu1.setComponentIdentifier( cpuIdentifier1 );
    cpu1.setId( "1" );
    cpu1.setCpuFrequencyInHertz( 2600 );
    cpu1.setNumOfCores( 4 );
    listCpu.add( cpu1 );

    FruDataChangeMessage event =
        new FruDataChangeMessage( (List<FruComponent>) (List<?>) listCpu, "TestNode", ServerComponent.CPU );
    context.publishEvent( event );

    assertNotNull( listener.getHmsDataCache().getServerInfoMap().containsKey( "TestNode" ) );
    // assertNotNull(listener.getHmsDataCache().getServerInfoMap().get("TestNode").getCpuInfo().get(0).getComponentIdentifier().getManufacturer());

    context.close();
    context.destroy();

}
 
开发者ID:vmware,项目名称:OHMS,代码行数:41,代码来源:HmsCacheEventTest.java

示例7: listenersInApplicationContext

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
@Test
public void listenersInApplicationContext() {
	StaticApplicationContext context = new StaticApplicationContext();
	context.registerBeanDefinition("listener1", new RootBeanDefinition(MyOrderedListener1.class));
	RootBeanDefinition listener2 = new RootBeanDefinition(MyOrderedListener2.class);
	listener2.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("listener1"));
	listener2.setLazyInit(true);
	context.registerBeanDefinition("listener2", listener2);
	context.refresh();
	assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));

	MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
	MyOtherEvent event1 = new MyOtherEvent(context);
	context.publishEvent(event1);
	assertFalse(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
	MyEvent event2 = new MyEvent(context);
	context.publishEvent(event2);
	assertTrue(context.getDefaultListableBeanFactory().containsSingleton("listener2"));
	MyEvent event3 = new MyEvent(context);
	context.publishEvent(event3);
	MyOtherEvent event4 = new MyOtherEvent(context);
	context.publishEvent(event4);
	assertTrue(listener1.seenEvents.contains(event1));
	assertTrue(listener1.seenEvents.contains(event2));
	assertTrue(listener1.seenEvents.contains(event3));
	assertTrue(listener1.seenEvents.contains(event4));

	listener1.seenEvents.clear();
	context.publishEvent(event1);
	context.publishEvent(event2);
	context.publishEvent(event3);
	context.publishEvent(event4);
	assertTrue(listener1.seenEvents.contains(event1));
	assertTrue(listener1.seenEvents.contains(event2));
	assertTrue(listener1.seenEvents.contains(event3));
	assertTrue(listener1.seenEvents.contains(event4));

	AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
	assertEquals(2, multicaster.retrieverCache.size());

	context.close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:ApplicationContextEventTests.java

示例8: serverCacheEventTest

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
/**
 * Test Server Cache Event Publisher
 */
@Test
public void serverCacheEventTest()
{

    HmsDataCache cache = new HmsDataCache();

    ServerCacheUpdateListener listener = new ServerCacheUpdateListener();
    listener.setHmsDataCache( cache );

    StaticApplicationContext context = new StaticApplicationContext();
    context.addApplicationListener( listener );

    context.refresh();

    // Adding dummy Server Information
    ServerInfo serverInfo = new ServerInfo();
    ComponentIdentifier serverComponentIdentifier = new ComponentIdentifier();
    serverComponentIdentifier.setManufacturer( "Testware" );
    serverComponentIdentifier.setProduct( "VM360" );
    serverComponentIdentifier.setPartNumber( "JFD32254" );
    serverComponentIdentifier.setSerialNumber( "32355567" );
    serverInfo.setComponentIdentifier( serverComponentIdentifier );
    serverInfo.setFruId( "53543454" );
    serverInfo.setInBandIpAddress( "127.0.0.1" );
    serverInfo.setLocation( "2U" );
    serverInfo.setManagementIpAddress( "127.0.0.1" );
    serverInfo.setNodeId( "TestNode" );
    serverInfo.setOperationalStatus( FruOperationalStatus.Operational );

    ServerDataChangeMessage event = new ServerDataChangeMessage( serverInfo, ServerComponent.SERVER );

    context.publishEvent( event );

    assertNotNull( listener.getHmsDataCache().getServerInfoMap().containsKey( "TestNode" ) );
    assertNotNull( listener.getHmsDataCache().getServerInfoMap().get( "TestNode" ).getNodeId() );

    context.close();
    context.destroy();

}
 
开发者ID:vmware,项目名称:OHMS,代码行数:44,代码来源:HmsCacheEventTest.java

示例9: switchCacheEventTest

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
/**
 * Test Switch Cache Event Publisher
 */
@Test
public void switchCacheEventTest()
{

    HmsDataCache cache = new HmsDataCache();

    SwitchCacheUpdateListener listener = new SwitchCacheUpdateListener();
    listener.setHmsDataCache( cache );

    StaticApplicationContext context = new StaticApplicationContext();
    context.addApplicationListener( listener );

    context.refresh();

    // Adding dummy Switch Information
    NBSwitchInfo switchInfo = new NBSwitchInfo();
    ComponentIdentifier switchComponentIdentifier = new ComponentIdentifier();
    switchComponentIdentifier.setManufacturer( "Testware" );
    switchComponentIdentifier.setProduct( "VM-Switch" );
    switchComponentIdentifier.setPartNumber( "5435GFFGF" );
    switchComponentIdentifier.setSerialNumber( "6546547" );
    switchInfo.setComponentIdentifier( switchComponentIdentifier );
    switchInfo.setFirmwareName( "firmwareTest" );
    switchInfo.setFirmwareVersion( "dsd2321" );
    switchInfo.setLocation( "3U" );
    switchInfo.setFruId( "443254576" );
    switchInfo.setOperationalStatus( FruOperationalStatus.Operational );
    switchInfo.setSwitchId( "TestSwitch" );
    // switchInfo.setRole(SwitchRoleType.MANAGEMENT);

    SwitchDataChangeMessage event = new SwitchDataChangeMessage( switchInfo, SwitchComponentEnum.SWITCH );

    context.publishEvent( event );

    assertNotNull( listener.getHmsDataCache().getServerInfoMap().containsKey( "TestSwitch" ) );
    assertNotNull( listener.getHmsDataCache().getSwitchInfoMap().get( "TestSwitch" ).getSwitchId() );

    context.close();
    context.destroy();

}
 
开发者ID:vmware,项目名称:OHMS,代码行数:45,代码来源:HmsCacheEventTest.java

示例10: fruHmsEventCacheEventTest

import org.springframework.context.support.StaticApplicationContext; //导入方法依赖的package包/类
/**
 * Test HMS Event Publisher to refresh the cache on Event
 */
@Test
public void fruHmsEventCacheEventTest()
{

    HmsDataCache cache = new HmsDataCache();

    FruEventDataUpdateListener listener = new FruEventDataUpdateListener();
    listener.setHmsDataCache( cache );

    StaticApplicationContext context = new StaticApplicationContext();
    context.addApplicationListener( listener );

    context.refresh();

    List<Event> events = new ArrayList<Event>();
    Event event = new Event();
    Body body = new Body();
    Header header = new Header();
    Map<EventComponent, String> componentIdentifier = new HashMap<EventComponent, String>();
    componentIdentifier.put( EventComponent.SERVER, "N9" );

    // Adding dummy Event
    body.setDescription( "CPU for rack EVO:RACK node N5 and CPU processor 1 has shutdown due to POST Failure." );
    header.setAgent( "HMS" );
    header.setEventName( EventCatalog.CPU_POST_FAILURE );
    header.setSeverity( EventSeverity.CRITICAL );
    header.setVersion( "1.0" );
    header.addComponentIdentifier( componentIdentifier );

    event.setBody( body );
    event.setHeader( header );

    events.add( event );

    FruEventStateChangeMessage eventMessage = new FruEventStateChangeMessage( events, ServerComponent.CPU );
    context.publishEvent( eventMessage );

    assertNotNull( listener.getHmsDataCache().getServerInfoMap().containsKey( "TestNode" ) );

    context.close();
    context.destroy();

}
 
开发者ID:vmware,项目名称:OHMS,代码行数:47,代码来源:HmsCacheEventTest.java


注:本文中的org.springframework.context.support.StaticApplicationContext.publishEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。