Java 类com.hazelcast.core.ExecutionCallback 实例源码

项目:j1st-mqtt    文件:HazelcastApplicationCommunicator.java   
/**
 * Send internal message to hazelcast ring
 *
 * @param ring    Hazelcast RingBuffer
 * @param message Internal Message
 */
protected void sendMessage(Ringbuffer<InternalMessage> ring, InternalMessage message) {
    ring.addAsync(message, OverflowPolicy.OVERWRITE).andThen(new ExecutionCallback<Long>() {
        @Override
        public void onResponse(Long response) {
            if (response > 0) {
                logger.debug("Communicator succeed: Successful add message {} to ring buffer {}", message.getMessageType(), ring.getName());
            } else {
                logger.debug("Communicator failed: Failed to add message {} to ring buffer {}: no space", message.getMessageType(), ring.getName());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            logger.warn("Communicator failed: Failed to add message {} to ring buffer {}: ", message.getMessageType(), ring.getName(), t);
        }
    });
}
项目:j1st-mqtt    文件:HazelcastHttpCommunicator.java   
/**
 * Send internal message to hazelcast ring
 *
 * @param ring    Hazelcast RingBuffer
 * @param message Internal Message
 */
protected void sendMessage(Ringbuffer<InternalMessage> ring, InternalMessage message) {
    ring.addAsync(message, OverflowPolicy.OVERWRITE).andThen(new ExecutionCallback<Long>() {
        @Override
        public void onResponse(Long response) {
            if (response > 0) {
                logger.debug("Communicator succeed: Successful add message {} to ring buffer {}", message.getMessageType(), ring.getName());
            } else {
                logger.debug("Communicator failed: Failed to add message {} to ring buffer {}: no space", message.getMessageType(), ring.getName());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            logger.warn("Communicator failed: Failed to add message {} to ring buffer {}: ", message.getMessageType(), ring.getName(), t);
        }
    });
}
项目:j1st-mqtt    文件:HazelcastBrokerCommunicator.java   
/**
 * Send internal message to hazelcast ring
 *
 * @param ring    Hazelcast RingBuffer
 * @param message Internal Message
 */
protected void sendMessage(Ringbuffer<InternalMessage> ring, InternalMessage message) {
    ring.addAsync(message, OverflowPolicy.OVERWRITE).andThen(new ExecutionCallback<Long>() {
        @Override
        public void onResponse(Long response) {
            if (response > 0) {
                logger.debug("Communicator succeed: Successful add message {} to ring buffer {}", message.getMessageType(), ring.getName());
            } else {
                logger.debug("Communicator failed: Failed to add message {} to ring buffer {}: no space", message.getMessageType(), ring.getName());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            logger.warn("Communicator failed: Failed to add message {} to ring buffer {}: ", message.getMessageType(), ring.getName(), t);
        }
    });
}
项目:jpoint-2016-computing-talk    文件:MasterMember.java   
public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IExecutorService executor = hz.getExecutorService("executor");
    ExecutionCallback<Long> executionCallback = new ExecutionCallback<Long>() {
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }

        public void onResponse(Long response) {
            System.out.println("Result: " + response);
        }
    };
    executor.submit(new FibonacciCallable(10), executionCallback);
    System.out.println("Fibonacci task submitted");
}
项目:concursus    文件:HazelcastCommandExecutor.java   
@Override
public void accept(Command command, CompletableFuture<CommandResult> commandResultCompletableFuture) {
    executorService.submitToKeyOwner(
            RemoteCommand.processing(command),
            command.getAggregateId().getId(),
            new ExecutionCallback<CommandResult>() {
        @Override
        public void onResponse(CommandResult commandResult) {
            commandResultCompletableFuture.complete(commandResult);
        }

        @Override
        public void onFailure(Throwable throwable) {
            commandResultCompletableFuture.completeExceptionally(throwable);
        }
    });
}
项目:hazelcast-simulator    文件:AsyncMapStreamerTest.java   
@Test(timeout = DEFAULT_TIMEOUT, expected = IllegalArgumentException.class)
@SuppressWarnings("unchecked")
public void testAwait_withExceptionInFuture() {
    when(map.putAsync(anyInt(), anyString())).thenReturn(future);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            ExecutionCallback<String> callback = (ExecutionCallback<String>) arguments[0];

            Exception exception = new IllegalArgumentException("expected exception");
            callback.onFailure(exception);
            return null;
        }
    }).when(future).andThen(any(ExecutionCallback.class));

    streamer.pushEntry(1, "value");
    streamer.await();
}
项目:hazelcast-simulator    文件:AsyncCacheStreamerTest.java   
@Test(timeout = DEFAULT_TIMEOUT, expected = IllegalArgumentException.class)
@SuppressWarnings("unchecked")
public void testAwait_withExceptionInFuture() {
    when(cache.putAsync(anyInt(), anyString())).thenReturn(future);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            ExecutionCallback<String> callback = (ExecutionCallback<String>) arguments[0];

            Exception exception = new IllegalArgumentException("expected exception");
            callback.onFailure(exception);
            return null;
        }
    }).when(future).andThen(any(ExecutionCallback.class));

    streamer.pushEntry(1, "value");
    streamer.await();
}
项目:ravikumaran201504    文件:SMap.java   
/**
 * {@inheritDoc}
 *
 * @deprecated not implemented yet
 * @throws UnsupportedOperationException not implemented yet
 */
@Deprecated
@SuppressWarnings("rawtypes")
@Override
public void submitToKey(K key, EntryProcessor entryProcessor,
        ExecutionCallback callback) {
    throw new UnsupportedOperationException();
}
项目:hazelcast-jet    文件:ClientJobProxy.java   
@Override
public void andThen(ExecutionCallback<Void> callback) {
    future.andThen(new ExecutionCallback<T>() {
        @Override
        public void onResponse(T response) {
            callback.onResponse(null);
        }

        @Override
        public void onFailure(Throwable t) {
            callback.onFailure(t);
        }
    });
}
项目:hazelcast-jet    文件:ClientJobProxy.java   
@Override
public void andThen(ExecutionCallback<Void> callback, Executor executor) {
    future.andThen(new ExecutionCallback<T>() {
        @Override
        public void onResponse(T response) {
            callback.onResponse(null);
        }

        @Override
        public void onFailure(Throwable t) {
            callback.onFailure(t);
        }
    }, executor);
}
项目:hazelcast-jet    文件:MasterContext.java   
private void invokeStartExecution() {
    jobStatus.set(RUNNING);
    logger.fine("Executing " + jobIdString());

    long executionId = this.executionId;

    AtomicBoolean cancellation = new AtomicBoolean();
    ExecutionCallback<Object> callback = new ExecutionCallback<Object>() {
        @Override
        public void onResponse(Object response) {
        }

        @Override
        public void onFailure(Throwable t) {
            if (cancellation.compareAndSet(false, true)) {
                cancelExecute(jobId, executionId);
            }
        }
    };

    cancellationFuture.whenComplete(withTryCatch(logger, (r, e) -> {
        if (e instanceof CancellationException) {
            callback.onFailure(e);
        }
    }));

    Function<ExecutionPlan, Operation> operationCtor = plan -> new StartExecutionOperation(jobId, executionId);
    invoke(operationCtor, this::onExecuteStepCompleted, callback);

    if (isSnapshottingEnabled()) {
        coordinationService.scheduleSnapshot(jobId, executionId);
    }
}
项目:hazelcast-jet    文件:Util.java   
/**
 * This method will generate an {@link ExecutionCallback} which
 * allows to asynchronously get notified when the execution is completed,
 * either successfully or with error by calling {@code onResponse} on success
 * and {@code onError} on error respectively.
 *
 * @param onResponse function to call when execution is completed successfully
 * @param onError function to call when execution is completed with error
 * @param <T> type of the response
 * @return {@link ExecutionCallback}
 */
public static <T> ExecutionCallback<T> callbackOf(Consumer<T> onResponse, Consumer<Throwable> onError) {
    return new ExecutionCallback<T>() {
        @Override
        public void onResponse(T o) {
            onResponse.accept(o);
        }

        @Override
        public void onFailure(Throwable throwable) {
            onError.accept(throwable);
        }
    };
}
项目:bucket4j    文件:HazelcastProxy.java   
private <T extends Serializable> CompletableFuture<CommandResult<T>> invokeAsync(K key, JCacheEntryProcessor<K, T> entryProcessor) {
    CompletableFuture<CommandResult<T>> future = new CompletableFuture<>();
    cache.submitToKey(key, adoptEntryProcessor(entryProcessor), new ExecutionCallback() {
        @Override
        public void onResponse(Object response) {
            future.complete((CommandResult<T>) response);
        }

        @Override
        public void onFailure(Throwable t) {
            future.completeExceptionally(t);
        }
    });
    return future;
}
项目:hz-map-reduce    文件:MapReduceDemo.java   
private static ExecutionCallback<Map<String, Long>> buildCallback() {
    return new ExecutionCallback<Map<String, Long>>() {
        @Override
        public void onResponse(Map<String, Long> stringLongMap) {
            System.out.println("Calculation finished! :)");
        }

        @Override
        public void onFailure(Throwable throwable) {
            throwable.printStackTrace();
        }
    };
}
项目:hazelcast-simulator    文件:AsyncMapStreamerTest.java   
@Test(timeout = DEFAULT_TIMEOUT)
@SuppressWarnings("unchecked")
public void testAwait() {
    when(map.putAsync(anyInt(), anyString())).thenReturn(future);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            ExecutionCallback<String> callback = (ExecutionCallback<String>) arguments[0];

            callback.onResponse("value");
            return null;
        }
    }).when(future).andThen(any(ExecutionCallback.class));

    Thread thread = new Thread() {
        @Override
        public void run() {
            for (int i = 0; i < 5000; i++) {
                streamer.pushEntry(i, "value");
            }
        }
    };
    thread.start();

    streamer.await();
    joinThread(thread);
}
项目:hazelcast-simulator    文件:AsyncCacheStreamerTest.java   
@Test(timeout = DEFAULT_TIMEOUT)
@SuppressWarnings("unchecked")
public void testAwait() {
    when(cache.putAsync(anyInt(), anyString())).thenReturn(future);
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            ExecutionCallback<String> callback = (ExecutionCallback<String>) arguments[0];

            callback.onResponse("value");
            return null;
        }
    }).when(future).andThen(any(ExecutionCallback.class));

    Thread thread = new Thread() {
        @Override
        public void run() {
            for (int i = 0; i < 5000; i++) {
                streamer.pushEntry(i, "value");
            }
        }
    };
    thread.start();

    streamer.await();
    joinThread(thread);
}
项目:jpoint-2016-computing-talk    文件:WordCountExample.java   
public static void main(String[] args)
    throws Exception {

    // Prepare Hazelcast cluster
    HazelcastInstance hazelcastInstance = buildCluster(3);

    try {

        // Read data
        fillMapWithData(hazelcastInstance);

        JobTracker tracker = hazelcastInstance.getJobTracker(TRACKER_NAME);

        IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
        KeyValueSource<String, String> source = KeyValueSource.fromMap(map);

        Job<String, String> job = tracker.newJob(source);

        final JobCompletableFuture<List<Map.Entry<String, Integer>>> future = job
            .mapper(new TokenizerMapper())
            // Activate Combiner to add combining phase!
            // .combiner(new WordcountCombinerFactory())
            .reducer(new WordcountReducerFactory())
            //                .submit();
            // add collator for sorting and top10
            .submit(new WordcountCollator());

        future.andThen(new ExecutionCallback<List<Map.Entry<String, Integer>>>() {
            @Override public void onResponse(List<Map.Entry<String, Integer>> response) {
                System.out.println(ToStringPrettyfier.toString(response));
            }

            @Override public void onFailure(Throwable t) {

            }
        });

        //System.out.println(ToStringPrettyfier.toString(future.get()));

    } finally {
        // Shutdown cluster
        //Hazelcast.shutdownAll();
    }
}
项目:hazelcast-jet    文件:MapDecorator.java   
@Override
public void submitToKey(K key, EntryProcessor entryProcessor, ExecutionCallback callback) {
    map.submitToKey(key, entryProcessor, callback);
}
项目:hazelcast-simulator    文件:TestContainer_TimeStep_AsyncSupportTest.java   
@Override
public void andThen(ExecutionCallback<Object> executionCallback) {
    executionCallback.onResponse(null);
}
项目:hazelcast-simulator    文件:TestContainer_TimeStep_AsyncSupportTest.java   
@Override
public void andThen(ExecutionCallback<Object> executionCallback, Executor executor) {
    throw new UnsupportedOperationException("not implemented");
}
项目:hazel-local-cache    文件:LocalCacheProxy.java   
@Override
public void submitToKey(Object key, EntryProcessor entryProcessor, ExecutionCallback callback) {

}
项目:hazelcast-archive    文件:InnerFutureTask.java   
ExecutionCallback<V> getExecutionCallback();
项目:health-and-care-developer-network    文件:InnerFutureTask.java   
ExecutionCallback<V> getExecutionCallback();