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


Java Event类代码示例

本文整理汇总了Java中net.mostlyoriginal.api.event.common.Event的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Event类属于net.mostlyoriginal.api.event.common包,在下文中一共展示了Event类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/**
 * Dispatch event to registered listeners.
 * Events are called on the call stack, avoid deeply nested or circular event calls.
 */
@Override
public void dispatch( Event event )
{
    if ( event == null ) throw new NullPointerException("Event required.");

    // fetch relevant listeners, sorted by order.
    final ImmutableBag<EventListener> relevantListeners = getRelevantListeners(event);

    // iterate over applicable listeners.
    for(int i=0, s=relevantListeners.size(); i<s; i++ )
    {
        final EventListener listener = relevantListeners.get(i);
        if ( listener != null ) {
            listener.handle(event);
        }
    }

}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:23,代码来源:BasicEventDispatcher.java

示例2: getRelevantListeners

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/** Get listeners that are subscribed to the event. */
protected ImmutableBag<EventListener> getRelevantListeners(Event event) {

    final Bag<EventListener> relevantListeners = new Bag<>();

 // resort listeners when we need to.
 if (sortDirty) {
  sortDirty=false;
  BagUtils.sort(listeners);
 }

 // who needs efficiency! not us!
    for(int i=0, s=listeners.size(); i<s; i++) {
        final EventListener listener = listeners.get(i);
        if ( listener != null ) {
            if ( canHandle(listener, event))
            {
                relevantListeners.add(listener);
            }
        }
    }

 return relevantListeners;
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:25,代码来源:BasicEventDispatcher.java

示例3: process

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public void process() {
	Object[] eventsToDispatch = eventQueue.getData();

	int i = 0;
	int s = eventQueue.size();

	while (i < s) {
		for (; i < s; i++) {
			Event event = (Event) eventsToDispatch[i];
			super.dispatch(event);
		}

		// we may end up having more events to dispatch at this point
		//  - some event handlers could dispatch more events
		s = eventQueue.size();
	}
	
	eventQueue.clear();
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:21,代码来源:PollingEventDispatcher.java

示例4: process

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public void process() {
	Object[] eventsToDispatch = eventQueue.getData();

	int i = 0;
	int s = eventQueue.size();

	while (i < s) {
		for (; i < s; i++) {
			Event event = (Event) eventsToDispatch[i];
			super.dispatch(event);
			pools.free(event);
		}

		// we may end up having more events to dispatch at this point
		//  - some event handlers could dispatch more events
		s = eventQueue.size();
	}

	eventQueue.clear();
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:22,代码来源:PollingPooledEventDispatcher.java

示例5: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/**
 * Dispatch event to registered listeners.
 * Events are called on the call stack, avoid deeply nested or circular event calls.
 */
@Override
public void dispatch(Event event) {
	if ( event == null ) throw new NullPointerException("Event required.");

	final Bag<EventListener> listeners = getListenersForHierarchical(event.getClass());

	/** Fetch hierarchical list of listeners. */
	Object[] data = listeners.getData();
	for (int i = 0, s = listeners.size(); i < s; i++) {
		final EventListener listener = (EventListener) data[i];
		if (listener != null) {
			listener.handle(event);
		}
	}
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:20,代码来源:FastEventDispatcher.java

示例6: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/** Dispatch wrapper. */
@Override
protected void dispatch(Event event) {
	try {
		dispatcher.dispatch(event);

		// this dispatcher processes after a world tick.
		if (!isProcessing) {
			// prevent call of process() in subsequent event
			isProcessing = true;
			dispatcher.process();
			isProcessing = false;
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:18,代码来源:PollingEventDispatcherTest.java

示例7: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/** Dispatch wrapper. */
@Override
protected void dispatch(Event event) {
	try {
		dispatcher.dispatch(event.getClass());

		// this dispatcher processes after a world tick.
		if (!isProcessing) {
			// prevent call of process() in subsequent event
			isProcessing = true;
			dispatcher.process();
			isProcessing = false;
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:18,代码来源:PollingPooledEventDispatcherTest.java

示例8: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public <T extends Event> T dispatch(Class<T> type) {
	T event;
	try {
		event = (T)ClassReflection.newInstance(type);
		this.dispatch(event);
	}
	catch (ReflectionException e) {
		String error = "Couldn't instantiate object of type " + type.getName();
		throw new RuntimeException(error, e);
	}
	
	return event;
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:15,代码来源:PollingEventDispatcher.java

示例9: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public <T extends Event> T dispatch(Class<T> type) {
	T event = pools.obtain(type);
	eventQueue.add(event);

	return event;
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:8,代码来源:PollingPooledEventDispatcher.java

示例10: Instance_MethodWithEventInterfaceParameter_Exception

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void Instance_MethodWithEventInterfaceParameter_Exception() throws ReflectionException {
	class ListenerPojo {
		public void validListener(Event event) {
		}
	}
	ListenerPojo pojo = new ListenerPojo();
	new EventListener(pojo, findMethod(pojo, "validListener", Event.class));
	// Event is an interface and cannot be called.
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:11,代码来源:EventListenerTest.java

示例11: canHandle

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
/** Check if listener can handle event. */
public boolean canHandle(EventListener listener, Event event) {
    final Class listenerEventType = ReflectionHelper.getFirstParameterType(listener.getMethod());
    return listenerEventType != null && ClassReflection.isAssignableFrom(listenerEventType, event.getClass());
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:6,代码来源:BasicEventDispatcher.java

示例12: dispatch

import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public void dispatch(Event event) {
}
 
开发者ID:DaanVanYperen,项目名称:artemis-odb-contrib,代码行数:4,代码来源:BaselineDispatcherBenchmark.java


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