use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientConsoleApp method executeOnMembers.
private void executeOnMembers(String[] args) {
// executeOnMembers <echo-string>
try {
IExecutorService executorService = hazelcast.getExecutorService("default");
Echo task = new Echo(args[1]);
Map<Member, Future<String>> results = executorService.submitToAllMembers(task);
for (Future f : results.values()) {
println(f.get());
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientConsoleApp method handleExecutorSimulate.
private void handleExecutorSimulate(String[] args) {
String first = args[0];
int threadCount = Integer.parseInt(first.substring(1, first.indexOf(".")));
if (threadCount < 1 || threadCount > MAX_THREAD_COUNT) {
throw new RuntimeException("threadcount can't be smaller than 1 or larger than 16");
}
int taskCount = Integer.parseInt(args[1]);
int durationSec = Integer.parseInt(args[2]);
long startMs = System.currentTimeMillis();
IExecutorService executor = hazelcast.getExecutorService(executorNamespace + ' ' + threadCount);
List<Future> futures = new LinkedList<Future>();
List<Member> members = new LinkedList<Member>(hazelcast.getCluster().getMembers());
int totalThreadCount = hazelcast.getCluster().getMembers().size() * threadCount;
int latchId = 0;
for (int k = 0; k < taskCount; k++) {
Member member = members.get(k % members.size());
if (taskCount % totalThreadCount == 0) {
latchId = taskCount / totalThreadCount;
hazelcast.getCountDownLatch("latch" + latchId).trySetCount(totalThreadCount);
}
Future f = executor.submitToMember(new SimulateLoadTask(durationSec, k + 1, "latch" + latchId), member);
futures.add(f);
}
for (Future f : futures) {
try {
f.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
long durationMs = System.currentTimeMillis() - startMs;
println(format("Executed %s tasks in %s ms", taskCount, durationMs));
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientConnectionTest method testAsyncConnectionCreationInAsyncMethods.
@Test
public void testAsyncConnectionCreationInAsyncMethods() throws ExecutionException, InterruptedException {
hazelcastFactory.newHazelcastInstance();
CountDownLatch countDownLatch = new CountDownLatch(1);
ClientConfig config = new ClientConfig();
WaitingCredentials credentials = new WaitingCredentials("dev", "dev-pass", countDownLatch);
config.setCredentials(credentials);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
final IExecutorService executorService = client.getExecutorService(randomString());
credentials.waitFlag.set(true);
final HazelcastInstance secondInstance = hazelcastFactory.newHazelcastInstance();
final AtomicReference<Future> atomicReference = new AtomicReference<Future>();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Member secondMember = secondInstance.getCluster().getLocalMember();
Future future = executorService.submitToMember(new DummySerializableCallable(), secondMember);
atomicReference.set(future);
}
});
thread.start();
try {
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(atomicReference.get());
}
}, 30);
} finally {
thread.interrupt();
thread.join();
countDownLatch.countDown();
}
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientMaxAllowedInvocationTest method testMaxAllowed_withUnfinishedCallback.
@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withUnfinishedCallback() throws ExecutionException, InterruptedException {
int MAX_ALLOWED = 10;
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
String name = randomString();
IMap map = client.getMap(name);
IExecutorService executorService = client.getExecutorService(randomString());
for (int i = 0; i < MAX_ALLOWED - 1; i++) {
executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
}
ClientDelegatingFuture future = (ClientDelegatingFuture) executorService.submit(new SleepyProcessor(2000));
CountDownLatch countDownLatch = new CountDownLatch(1);
future.andThenInternal(new SleepyCallback(countDownLatch), false);
future.get();
try {
map.get(1);
} catch (HazelcastOverloadException e) {
throw e;
} finally {
countDownLatch.countDown();
}
}
use of com.hazelcast.core.IExecutorService in project hazelcast by hazelcast.
the class ClientMaxAllowedInvocationTest method testMaxAllowed_withSyncOperation.
@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withSyncOperation() {
int MAX_ALLOWED = 10;
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
IMap map = client.getMap(randomString());
IExecutorService executorService = client.getExecutorService(randomString());
for (int i = 0; i < MAX_ALLOWED; i++) {
executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
}
map.get(2);
}
Aggregations