Giriş
Şu satırı dahil ederiz
import com.hazelcast.executor.impl.ExecutorServiceProxy;
Kalıtım şöyle
java.util.concurrent.ExecutorService
IExecutorService
ExecutorServiceProxy
Runnable Alan Metodlar
Runnable alan tüm metodlar kendi içinde RunnableAdapter nesnesi yaratıyor. RunnableAdapter ise aslında bir Callable. Kod şöyle
@Override public void execute(@Nonnull Runnable command) { Callable<?> callable = createRunnableAdapter(command); submit(callable); }
Callable Alan Metodlar
Callable olduğu gibi kullanılıyor. Kod şöyle
@Nonnull @Override public <T> Future<T> submit(@Nonnull Callable<T> task) { checkNotNull(task, "task must not be null"); final int partitionId = getTaskPartitionId(task); return submitToPartitionOwner(task, partitionId); }
Diğer
submitToMember metodu
Kod şöyle. Diğer üyenin DistributedExecutorService servisine gönderiliyorprivate <T> Future<T> submitToMember(@Nonnull Data taskData, @Nonnull Member member) { NodeEngine nodeEngine = getNodeEngine(); UUID uuid = newUnsecureUUID(); Address target = member.getAddress(); MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData); InternalCompletableFuture future = nodeEngine.getOperationService() .invokeOnTarget(DistributedExecutorService.SERVICE_NAME, op, target); return new CancellableDelegatingFuture<>(future, nodeEngine, uuid, target); }
submitToPartitionOwner metodu
Kod şöyle. Bir partition'ın DistributedExecutorService servisine gönderiliyor
private <T> void submitToPartitionOwner(@Nonnull Callable<T> task, @Nullable ExecutionCallback<T> callback, int partitionId) { checkNotShutdown(); checkNotNull(task, "task must not be null"); NodeEngine nodeEngine = getNodeEngine(); Data taskData = nodeEngine.toData(task); CallableTaskOperation op = new CallableTaskOperation(name, null, taskData); OperationService operationService = nodeEngine.getOperationService(); InvocationFuture<T> future = operationService .createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, partitionId) .invoke(); if (callback != null) { future.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)) whenCompleteAsync((v, t) -> { if (t instanceof RejectedExecutionException) { callback.onFailure(t); } }); } }
Hiç yorum yok:
Yorum Gönder