Search in sources :

Example 1 with CompositeClassLoader

use of com.b2international.commons.CompositeClassLoader in project snow-owl by b2ihealthcare.

the class AsyncRequest method execute.

/**
 * Executes the asynchronous request using the event bus passed in.
 * @param bus
 * @return {@link Promise}
 */
public Promise<R> execute(IEventBus bus) {
    final Promise<R> promise = new Promise<>();
    final Class<R> responseType = request.getReturnType();
    final CompositeClassLoader classLoader = new CompositeClassLoader();
    classLoader.add(request.getClassLoader());
    request.getNestedRequests().stream().map(Request::getClassLoader).forEach(classLoader::add);
    request.getNestedRequests().stream().map(r -> r.getClass().getClassLoader()).forEach(classLoader::add);
    bus.send(Request.ADDRESS, request, Request.TAG, Collections.emptyMap(), new IHandler<IMessage>() {

        @Override
        public void handle(IMessage message) {
            try {
                if (message.isSucceeded()) {
                    promise.resolve(message.body(responseType, classLoader), message.headers());
                } else {
                    promise.reject(message.body(Throwable.class, AsyncRequest.class.getClassLoader()));
                }
            } catch (Throwable e) {
                promise.reject(e);
            }
        }
    });
    return promise;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ScheduleJobRequestBuilder(com.b2international.snowowl.core.jobs.ScheduleJobRequestBuilder) Promise(com.b2international.snowowl.core.events.util.Promise) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CompositeClassLoader(com.b2international.commons.CompositeClassLoader) IEventBus(com.b2international.snowowl.eventbus.IEventBus) IMessage(com.b2international.snowowl.eventbus.IMessage) Collections(java.util.Collections) IHandler(com.b2international.snowowl.eventbus.IHandler) Promise(com.b2international.snowowl.core.events.util.Promise) IMessage(com.b2international.snowowl.eventbus.IMessage) CompositeClassLoader(com.b2international.commons.CompositeClassLoader)

Example 2 with CompositeClassLoader

use of com.b2international.commons.CompositeClassLoader in project snow-owl by b2ihealthcare.

the class BulkRequest method getClassLoader.

@Override
public ClassLoader getClassLoader() {
    final CompositeClassLoader classLoader = new CompositeClassLoader();
    classLoader.add(Request.super.getClassLoader());
    for (Request<C, ?> req : requests) {
        classLoader.add(req.getClassLoader());
    }
    return classLoader;
}
Also used : CompositeClassLoader(com.b2international.commons.CompositeClassLoader)

Aggregations

CompositeClassLoader (com.b2international.commons.CompositeClassLoader)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 Promise (com.b2international.snowowl.core.events.util.Promise)1 JobRequests (com.b2international.snowowl.core.jobs.JobRequests)1 ScheduleJobRequestBuilder (com.b2international.snowowl.core.jobs.ScheduleJobRequestBuilder)1 IEventBus (com.b2international.snowowl.eventbus.IEventBus)1 IHandler (com.b2international.snowowl.eventbus.IHandler)1 IMessage (com.b2international.snowowl.eventbus.IMessage)1 Collections (java.util.Collections)1 TimeUnit (java.util.concurrent.TimeUnit)1