Search in sources :

Example 1 with SysEventListenerBase

use of act.event.SysEventListenerBase in project act-ebean by actframework.

the class EbeanDaoInjectionListener method onInjection.

@Override
public void onInjection(Object injectee, BeanSpec spec) {
    final EbeanDao dao = $.cast(injectee);
    if (dao.ebeanServerProvided()) {
        return;
    }
    List<Type> typeParameters = spec.typeParams();
    if (typeParameters.isEmpty()) {
        typeParameters = Generics.typeParamImplementations(spec.rawType(), EbeanDao.class);
    }
    if (null == typeParameters) {
        logger.warn("No type parameter information provided");
        return;
    }
    final $.T2<Class, String> resolved = resolve(typeParameters);
    DbService dbService = App.instance().dbServiceManager().dbService(resolved._2);
    if (dbService instanceof EbeanService) {
        final EbeanService service = $.cast(dbService);
        Act.eventBus().bind(SysEventId.DB_SVC_LOADED, new SysEventListenerBase() {

            @Override
            public void on(EventObject eventObject) throws Exception {
                dao.ebean(service.ebean());
                dao.modelType(resolved._1);
            }
        });
    }
}
Also used : org.osgl.$(org.osgl.$) DbService(act.db.DbService) SysEventListenerBase(act.event.SysEventListenerBase) EventObject(java.util.EventObject) Type(java.lang.reflect.Type)

Example 2 with SysEventListenerBase

use of act.event.SysEventListenerBase in project actframework by actframework.

the class SubTypeFinder method applyTo.

@Override
public final void applyTo(final App app) {
    app.eventBus().bind(bindingEvent, new SysEventListenerBase() {

        @Override
        public void on(EventObject event) throws Exception {
            ClassInfoRepository repo = app.classLoader().classInfoRepository();
            ClassNode parent = repo.node(targetType.getName());
            parent.visitPublicNotAbstractTreeNodes(new $.Visitor<ClassNode>() {

                @Override
                public void visit(ClassNode classNode) throws $.Break {
                    final Class<T> c = $.classForName(classNode.name(), app.classLoader());
                    found(c, app);
                }
            });
        }
    });
}
Also used : org.osgl.$(org.osgl.$) SysEventListenerBase(act.event.SysEventListenerBase) EventObject(java.util.EventObject)

Example 3 with SysEventListenerBase

use of act.event.SysEventListenerBase in project actframework by actframework.

the class Job method run.

@Override
public void run() {
    invokeParallelJobs();
    runPrecedenceJobs();
    try {
        if (Act.isDev() && app.isStarted()) {
            app.checkUpdates(false);
        }
        doJob();
    } catch (Throwable e) {
        boolean isFatal = FATAL_EXCEPTIONS.contains(e.getClass());
        Throwable cause = e;
        if (!isFatal) {
            cause = e.getCause();
            while (null != cause) {
                isFatal = FATAL_EXCEPTIONS.contains(cause.getClass());
                if (isFatal) {
                    break;
                }
                cause = cause.getCause();
            }
        }
        if (isFatal) {
            if (Act.isDev()) {
                app.setBlockIssue(e);
            } else {
                Act.shutdown(App.instance());
                destroy();
                if (App.instance().isMainThread()) {
                    if (cause instanceof RuntimeException) {
                        throw (RuntimeException) cause;
                    }
                    throw E.unexpected(e);
                } else {
                    logger.fatal(cause, "Fatal error executing job %s", id());
                }
            }
            return;
        }
        // TODO inject Job Exception Handling mechanism here
        logger.warn(e, "error executing job %s", id());
    } finally {
        if (!isDestroyed()) {
            executed = true;
            if (isOneTime()) {
                App app = App.instance();
                if (app.isStarted()) {
                    manager.removeJob(this);
                } else {
                    app.eventBus().bind(SysEventId.POST_START, new SysEventListenerBase() {

                        @Override
                        public void on(EventObject event) throws Exception {
                            manager.removeJob(Job.this);
                        }
                    });
                }
            }
            progress.destroy();
        }
    }
    runFollowingJobs();
}
Also used : App(act.app.App) SysEventListenerBase(act.event.SysEventListenerBase) NotAppliedException(org.osgl.exception.NotAppliedException) DuplicateRouteMappingException(act.route.DuplicateRouteMappingException) UnexpectedException(org.osgl.exception.UnexpectedException) ConfigurationException(org.osgl.exception.ConfigurationException)

Aggregations

SysEventListenerBase (act.event.SysEventListenerBase)3 EventObject (java.util.EventObject)2 org.osgl.$ (org.osgl.$)2 App (act.app.App)1 DbService (act.db.DbService)1 DuplicateRouteMappingException (act.route.DuplicateRouteMappingException)1 Type (java.lang.reflect.Type)1 ConfigurationException (org.osgl.exception.ConfigurationException)1 NotAppliedException (org.osgl.exception.NotAppliedException)1 UnexpectedException (org.osgl.exception.UnexpectedException)1