Example usage for org.springframework.core.task AsyncTaskExecutor execute

List of usage examples for org.springframework.core.task AsyncTaskExecutor execute

Introduction

In this page you can find the example usage for org.springframework.core.task AsyncTaskExecutor execute.

Prototype

@Override
void execute(Runnable task);

Source Link

Document

Execute the given task .

Usage

From source file:org.grails.plugin.platform.events.publisher.DefaultEventsPublisher.java

@SuppressWarnings("rawtypes")
@Override//  www  .  j av a2 s . c o m
public EventReply eventAsync(final EventMessage<?> event, final Map<String, Object> params) {
    AsyncTaskExecutor taskExecutor = params != null && params.containsKey(EXECUTOR)
            ? taskExecutors.get(params.get(EXECUTOR))
            : taskExecutors.get(DEFAULT_EXECUTOR);

    Future<DefaultEventsRegistry.InvokeResult> invokeResult = taskExecutor.submit(new Callback(event));

    final WrappedFuture reply = new WrappedFuture(invokeResult, -1);

    if (params != null) {
        reply.setOnError((Closure) params.get(ON_ERROR));
        if (params.get(ON_REPLY) != null) {
            taskExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        if (params.get(TIMEOUT) != null)
                            reply.get((Long) params.get(TIMEOUT), TimeUnit.MILLISECONDS);
                        else
                            reply.get();

                        reply.throwError();
                        ((Closure) params.get(ON_REPLY)).call(reply);
                    } catch (Throwable e) {
                        reply.setCallingError(e);
                    }
                }
            });

        }
    }
    return reply;
}