Search in sources :

Example 6 with JobManager

use of act.job.JobManager in project actframework by actframework.

the class ReflectedCommandExecutor method execute.

@Override
public Object execute(CliContext context) {
    context.handlerMethod(method);
    if (null != dateFormatPattern) {
        context.dateFormatPattern(dateFormatPattern);
    }
    context.fastjsonFeatures(features);
    context.fastjsonFilters(filters);
    context.prepare(parsingContext);
    paramLoaderService.preParseOptions(method, methodMetaInfo, context);
    final Object cmd = commanderInstance(context);
    final Object[] params = params(cmd, context);
    if (async) {
        JobManager jobManager = context.app().jobManager();
        String jobId = jobManager.prepare(new TrackableWorker() {

            @Override
            protected void run(ProgressGauge progressGauge) {
                invoke(cmd, params);
            }
        });
        context.setJobId(jobId);
        jobManager.now(jobId);
        if (null != reportProgress) {
            context.attribute(ReportProgress.CTX_ATTR_KEY, reportProgress);
            return context.progress();
        } else {
            return "Async job started: " + jobId;
        }
    }
    return invoke(cmd, params);
}
Also used : TrackableWorker(act.job.TrackableWorker) ProgressGauge(act.util.ProgressGauge) JobManager(act.job.JobManager)

Example 7 with JobManager

use of act.job.JobManager 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

JobManager (act.job.JobManager)7 AppByteCodeScanner (act.app.AppByteCodeScanner)2 AppCodeScannerManager (act.app.AppCodeScannerManager)2 TestingAppClassLoader (act.app.TestingAppClassLoader)2 TrackableWorker (act.job.TrackableWorker)2 File (java.io.File)2 Before (org.junit.Before)2 C (org.osgl.util.C)2 SysEventId (act.app.event.SysEventId)1 CliDispatcher (act.cli.CliDispatcher)1 EventBus (act.event.EventBus)1 SimpleEventListenerMetaInfo (act.event.meta.SimpleEventListenerMetaInfo)1 ReflectedHandlerInvokerInvoke (act.handler.event.ReflectedHandlerInvokerInvoke)1 ParamValueLoaderManager (act.inject.param.ParamValueLoaderManager)1 JobByteCodeScanner (act.job.bytecode.JobByteCodeScanner)1 ClassInfoRepository (act.util.ClassInfoRepository)1 ProgressGauge (act.util.ProgressGauge)1 WebSocketConnectionManager (act.ws.WebSocketConnectionManager)1 JSONException (com.alibaba.fastjson.JSONException)1 NotAppliedException (org.osgl.exception.NotAppliedException)1