本文整理汇总了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);
}
}
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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.
}
示例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());
}
示例12: dispatch
import net.mostlyoriginal.api.event.common.Event; //导入依赖的package包/类
@Override
public void dispatch(Event event) {
}