@Override public void callEvent(Event event) throws EventException { if (event.isAsynchronous()) { super.callEvent(event); return; } count++; Class<? extends Event> newEventClass = event.getClass(); if (this.eventClass == null) { this.eventClass = newEventClass; } else if (!this.eventClass.equals(newEventClass)) { multiple = true; this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class); } long start = System.nanoTime(); super.callEvent(event); totalTime += System.nanoTime() - start; }
/** * Calls an event with the given details. * <p> * This method only synchronizes when the event is not asynchronous. * * @param event Event details */ public void callEvent(Event event) { if (event.isAsynchronous()) { if (Thread.holdsLock(this)) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code."); } if (server.isPrimaryThread()) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread."); } fireEvent(event); } else { synchronized (this) { fireEvent(event); } } }
if (event.isAsynchronous()) { server.getPluginManager().callEvent(event); return event;
private void checkSafety(Event eventType) { //async executing of sync event String eventName = eventType.getEventName(); if (!eventType.isAsynchronous()) { actionManager.checkThreadSafety(eventName); } } }
@Override public void callEvent(Event event) throws EventException { if (event.isAsynchronous()) { super.callEvent(event); return; } count++; Class<? extends Event> newEventClass = event.getClass(); if (this.eventClass == null) { this.eventClass = newEventClass; } else if (!this.eventClass.equals(newEventClass)) { multiple = true; this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class); } long start = System.nanoTime(); super.callEvent(event); totalTime += System.nanoTime() - start; }
public void execute(Listener listener, Event event) throws EventException { try { if (!eventClass.isAssignableFrom(event.getClass())) { return; } // Spigot start boolean isAsync = event.isAsynchronous(); if (!isAsync) timings.startTiming(); method.invoke(listener, event); if (!isAsync) timings.stopTiming(); // Spigot end } catch (InvocationTargetException ex) { throw new EventException(ex.getCause()); } catch (Throwable t) { throw new EventException(t); } } };
@Override // 计算调用次数和花费总时间以及花费最多的时间 public void execute(Listener listener, Event e) throws EventException { if (e.isAsynchronous()) { this.eventExecutor.execute(listener, e); } else { long startTime = System.nanoTime(); try { this.eventExecutor.execute(listener, e); } finally { long endTime = System.nanoTime(); long executeTime = endTime - startTime; this.record(e.getEventName(), executeTime); } } }
/** * Calls an event with the given details. * <p> * This method only synchronizes when the event is not asynchronous. * * @param event Event details */ public void callEvent(Event event) { if (event.isAsynchronous()) { if (Thread.holdsLock(this)) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from inside synchronized code."); } if (server.isPrimaryThread()) { throw new IllegalStateException(event.getEventName() + " cannot be triggered asynchronously from primary server thread."); } fireEvent(event); } else { synchronized (this) { fireEvent(event); } } }