use of act.app.event.SysEvent in project actframework by actframework.
the class EventBus method _emit.
private EventBus _emit(boolean asyncForAsync, boolean asyncForSync, SysEventId eventId) {
if (isTraceEnabled()) {
String s = " ";
if (asyncForAsync && asyncForSync) {
s = "asynchronously";
} else if (!asyncForAsync && !asyncForSync) {
s = "synchronously";
}
trace("emitting system event[%s] %s", eventId, s);
}
SysEvent event = lookUpSysEvent(eventId);
callOn(event, asyncSysEventListeners, true);
callOn(event, sysEventListeners, false);
return this;
}
use of act.app.event.SysEvent in project actframework by actframework.
the class EventBus method initSysEventLookup.
private SysEvent[] initSysEventLookup(App app) {
SysEventId[] ids = SysEventId.values();
int len = ids.length;
SysEvent[] events = new SysEvent[len];
for (int i = 0; i < len; ++i) {
SysEventId id = ids[i];
events[id.ordinal()] = id.of(app);
}
return events;
}
use of act.app.event.SysEvent in project actframework by actframework.
the class EventListenerClassFinder method found.
@Override
protected void found(final Class<? extends ActEventListener> target, final App app) {
final EventBus bus = app.eventBus();
ParameterizedType ptype = null;
Type superType = target.getGenericSuperclass();
while (ptype == null) {
if (superType instanceof ParameterizedType) {
ptype = (ParameterizedType) superType;
} else {
if (Object.class == superType) {
logger.warn("Event listener registration failed: cannot find generic information for %s", target.getName());
return;
}
superType = ((Class) superType).getGenericSuperclass();
}
}
Type[] ca = ptype.getActualTypeArguments();
for (Type t : ca) {
if (t instanceof Class) {
final Class<? extends EventObject> tc = $.cast(t);
if (SysEvent.class.isAssignableFrom(tc)) {
SysEvent prototype = $.cast($.newInstance(tc, app));
SysEventListener listener = $.cast(app.getInstance(target));
app.eventBus().bind(SysEventId.values()[prototype.id()], listener);
} else if (ActEvent.class.isAssignableFrom(tc)) {
SysEventId bindOn = SysEventId.START;
BindOn bindOnSpec = target.getAnnotation(BindOn.class);
if (null == bindOnSpec) {
bindOnSpec = tc.getAnnotation(BindOn.class);
}
if (null != bindOnSpec) {
bindOn = bindOnSpec.value();
}
app.eventBus().bind(bindOn, new SysEventListenerBase() {
@Override
public void on(EventObject event) throws Exception {
ActEventListener listener = app.getInstance(target);
bus.bind(tc, listener);
}
});
return;
}
}
}
}
Aggregations