Search in sources :

Example 1 with SysEventId

use of act.app.event.SysEventId 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;
}
Also used : SysEventId(act.app.event.SysEventId) SysEvent(act.app.event.SysEvent)

Example 2 with SysEventId

use of act.app.event.SysEventId 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;
            }
        }
    }
}
Also used : EventObject(java.util.EventObject) ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SysEventId(act.app.event.SysEventId) SysEventListener(act.app.event.SysEventListener) SysEvent(act.app.event.SysEvent)

Example 3 with SysEventId

use of act.app.event.SysEventId in project actframework by actframework.

the class SimpleEventListenerByteCodeScanner method scanFinished.

@Override
public void scanFinished(String className) {
    if (!metaInfoList.isEmpty()) {
        final EventBus eventBus = app().eventBus();
        JobManager jobManager = app().jobManager();
        for (final SimpleEventListenerMetaInfo metaInfo : metaInfoList) {
            SysEventId hookOn = metaInfo.beforeAppStart() ? SysEventId.DEPENDENCY_INJECTOR_PROVISIONED : SysEventId.PRE_START;
            jobManager.on(hookOn, new Runnable() {

                @Override
                public void run() {
                    for (final Object event : metaInfo.events()) {
                        final boolean isStatic = metaInfo.isStatic();
                        eventBus.bind(event, new ReflectedSimpleEventListener(metaInfo.className(), metaInfo.methodName(), metaInfo.paramTypes(), isStatic));
                    }
                }
            });
        }
    }
}
Also used : SysEventId(act.app.event.SysEventId) JobManager(act.job.JobManager) SimpleEventListenerMetaInfo(act.event.meta.SimpleEventListenerMetaInfo)

Aggregations

SysEventId (act.app.event.SysEventId)3 SysEvent (act.app.event.SysEvent)2 SysEventListener (act.app.event.SysEventListener)1 SimpleEventListenerMetaInfo (act.event.meta.SimpleEventListenerMetaInfo)1 JobManager (act.job.JobManager)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 EventObject (java.util.EventObject)1