本文整理汇总了Java中org.openspaces.core.executor.DistributedTask类的典型用法代码示例。如果您正苦于以下问题:Java DistributedTask类的具体用法?Java DistributedTask怎么用?Java DistributedTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DistributedTask类属于org.openspaces.core.executor包,在下文中一共展示了DistributedTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public <T extends Serializable> AsyncFuture<T> execute(Task<T> task, AsyncFutureListener<T> listener) {
if (task instanceof DistributedTask) {
return distExecute((DistributedTask) task, listener);
}
Object routing = null;
if (task instanceof TaskRoutingProvider) {
Object optionalRouting = executorMetaDataProvider.findRouting(((TaskRoutingProvider) task).getRouting());
if (optionalRouting != null) {
routing = optionalRouting;
}
}
if (routing == null) {
routing = executorMetaDataProvider.findRouting(task);
}
return execute(task, routing, listener);
}
示例2: reduce
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Reduces the provided task under access controls.
*/
public R reduce(final List<AsyncResult<T>> results) throws Exception {
AccessControlContext acc = AccessController.getContext();
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
try {
reduceResult = ((DistributedTask<T, R>) getDelegatedTask()).reduce(results);
} catch (Exception ex) {
exception = ex;
}
return null;
}
}, acc);
if (exception != null)
throw exception;
else
return reduceResult;
}
示例3: executeTask
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Executes the provided GigaSpaces {@link Task}.
* This operation must be under a {@link StoreManager} transaction.
*
* @param task The {@link Task} to execute.
* @param query The query which execute was called for.
* @return {@link Task} execution returned value.
*/
private ResultObjectProvider executeTask(Task<?> task, final StoreManagerSQLQuery query) {
// Make sure there's an active store transaction
// since we assume the task is changing data within the space
final StoreContext context = query.getStore().getContext();
context.getBroker().assertActiveTransaction();
context.beginStore();
final ISpaceProxy space = (ISpaceProxy) query.getStore().getConfiguration().getSpace();
// Get routing from annotation
final Object routing = _executorMetaDataProvider.findRouting(task);
try {
SpaceTask<?> spaceTask;
if( task instanceof DistributedTask)
spaceTask = new InternalDistributedSpaceTaskWrapper((DistributedTask) task);
else
spaceTask = new InternalSpaceTaskWrapper(task, routing);
AsyncFuture<?> future = space.execute(spaceTask, routing, query.getStore().getCurrentTransaction(), null);
Object taskResult = future.get();
List resultList = new LinkedList();
resultList.add(taskResult);
return new ListResultObjectProvider(resultList);
} catch (Exception e) {
throw new GeneralException(e);
}
}
示例4: distExecute
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public <T extends Serializable, R> AsyncFuture<R> distExecute(DistributedTask<T, R> task, AsyncFutureListener<R> listener) {
try {
Transaction tx = getCurrentTransaction();
InternalDistributedSpaceTaskWrapper<T, R> taskWrapper = new InternalDistributedSpaceTaskWrapper<T, R>(task);
return wrapFuture(space.execute(taskWrapper, taskWrapper.getRouting(), tx, wrapListener(listener, tx)), tx);
} catch (Exception e) {
throw exTranslator.translate(e);
}
}
示例5: execute
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Executes all the given tasks (asynchronously) based on their execution mode and returns a future
* allowing to retrieve the reduced operation of all the tasks.
*
* <p>The future actual result will be the reduced result of the execution, or the exception thrown during
* during the reduce operation. The moderator (assuming the reducer provided implements
* {@link com.gigaspaces.async.AsyncResultFilter}) can be used as a mechanism to listen for results as they arrive.
*
* @return a Future representing pending completion of the task,
* and whose <code>get()</code> method will return the task value upon completion.
*/
public AsyncFuture<R> execute() {
if (holders.size() == 0) {
throw new IllegalArgumentException("No tasks to execute");
}
AsyncFuture[] futures = new AsyncFuture[holders.size()];
for (int i = 0; i < futures.length; i++) {
Holder holder = holders.get(i);
if (holder.task instanceof DistributedTask) {
if (holder.routing != null) {
futures[i] = gigaSpace.execute((DistributedTask) holder.task, (Object[]) holder.routing);
} else {
futures[i] = gigaSpace.execute((DistributedTask) holder.task);
}
} else {
if (holder.routing != null) {
futures[i] = gigaSpace.execute(holder.task, holder.routing);
} else {
futures[i] = gigaSpace.execute(holder.task);
}
}
}
AsyncFuture<R> result;
if (reducer instanceof AsyncResultFilter) {
result = FutureFactory.create(futures, reducer, (AsyncResultFilter<T>) reducer);
} else {
result = FutureFactory.create(futures, reducer);
}
return gigaSpace.wrapFuture(result, gigaSpace.getCurrentTransaction());
}
示例6: observe
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Creates a lazy Observable that will execute a given DistributedTask asynchronously once subscribed to.
*
* @param task
* @param routingKey
* @return
*/
public <T extends Serializable, R> Observable<R> observe(final DistributedTask<T, R> distributedTask) {
return Observable.create(t1 -> {
usingErrorReporter(t1, serviceUnavailable()).accept(() -> {
executorService.execute(() -> {
submitDistributedTaskExecution(distributedTask, t1);
});
});
});
}
示例7: submitDistributedTaskExecution
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
private <R, T extends Serializable> void submitDistributedTaskExecution(final DistributedTask<T, R> distributedTask, Subscriber<? super R> t1) {
usingErrorReporter(t1, serviceUnavailable()).accept(() -> {
// Submit task on current thread in executorService
AsyncFuture<R> taskResult = gigaSpace.execute(distributedTask);
GsUtil.subscribe(taskResult, t1);
});
}
示例8: execute
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public static <T extends Serializable, R> CompletableFuture<R> execute(GigaSpace gigaSpace, DistributedTask<T, R> task){
return toCompletableFuture(gigaSpace.execute(task));
}
示例9: SimpleDelegatingDistributedTask
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public SimpleDelegatingDistributedTask(DistributedTask<T, R> task) {
super(task);
}
示例10: reduce
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public R reduce(List<AsyncResult<T>> asyncResults) throws Exception {
return ((DistributedTask<T, R>) getDelegatedTask()).reduce(asyncResults);
}
示例11: PrivilegedDistributedTask
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Constructs a new privileged task wrapping the actual task to execute.
*/
public PrivilegedDistributedTask(DistributedTask<T, R> task) {
super(task);
}
示例12: InternalDistributedSpaceTaskWrapper
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
public InternalDistributedSpaceTaskWrapper(DistributedTask<T, R> task) {
super(task, null);
}
示例13: reduce
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public R reduce(List<AsyncResult<T>> asyncResults) throws Exception {
return (R) ((DistributedTask) getTask()).reduce(asyncResults);
}
示例14: add
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Adds a task to be executed similarly to {@link org.openspaces.core.GigaSpace#execute(org.openspaces.core.executor.DistributedTask, Object[])}
*
* @param task The task to add
* @return The executor builder to add more tasks to or {@link #execute()}.
* @see org.openspaces.core.GigaSpace#execute(org.openspaces.core.executor.DistributedTask, Object[])
*/
public ExecutorBuilder<T, R> add(DistributedTask<T, R> task, Object... routing) {
holders.add(new Holder(task, routing));
return this;
}
示例15: execute
import org.openspaces.core.executor.DistributedTask; //导入依赖的package包/类
/**
* Executes a task on all the nodes that correspond to the list of routing values. The task is executed
* on each space node with all the results reduced by the
* {@link org.openspaces.core.executor.DistributedTask#reduce(java.util.List)} operation.
* <p/>
* <p>The routing object itself does not have to be the actual routing value, but can be a POJO
* that defined a method annotated with <code>@SpaceRouting</code> annotation (this works well
* when wanting to use entries as the routing parameters).
* <p/>
* <p>The task can optionally implement {@link com.gigaspaces.async.AsyncResultFilter} that can control
* if tasks should continue to accumulate or it should break and execute the reduce operation on the
* results received so far.
* <p/>
* <p>The future actual result will be the reduced result of the execution, or the exception thrown during
* during the reduce operation. The moderator can be used as a mechanism to listen for results as they arrive.
* <p/>
* <p>The last parameter can be of type {@link com.gigaspaces.async.AsyncFutureListener} which, this case,
* it will be used to register a listener to be notified of the result.
* <p/>
* <p>The space that the task is executed within can be accessible by marking a field with type {@link org.openspaces.core.GigaSpace}
* using the {@link org.openspaces.core.executor.TaskGigaSpace} annotation. Another option is by implementing
* the {@link org.openspaces.core.executor.TaskGigaSpaceAware} interface.
* <p/>
* <p>Resource injection can be enabled by marking the task with {@link org.openspaces.core.executor.AutowireTask}
* or with {@link org.openspaces.core.executor.AutowireTaskMarker}. Resources defined within processing unit
* (space node) the task is executed on are accessible by using either the {@link org.springframework.beans.factory.annotation.Autowired} or
* <tt>javax.annotation.Resource</tt> annotations (assuming they are enabled using <code>context:annotation-config</code>).
* Bean life cycle methods, such as {@link org.openspaces.core.cluster.ClusterInfoAware} and
* {@link org.springframework.context.ApplicationContextAware} are also available.
*
* @param task The task to execute
* @param routing A list of routing values, each resulting in an execution of the task on the space node
* it corresponds to
* @return a Future representing pending completion of the task,
* and whose <code>get()</code> method will return the task value upon completion.
*/
<T extends Serializable, R> AsyncFuture<R> execute(DistributedTask<T, R> task, Object... routing);