use of com.hazelcast.core.Member 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.Member in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method handleInitialMembershipEvent.
void handleInitialMembershipEvent(InitialMembershipEvent event) {
synchronized (initialMembershipListenerMutex) {
Set<Member> initialMembers = event.getMembers();
LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>();
for (Member initialMember : initialMembers) {
newMap.put(initialMember.getAddress(), initialMember);
}
members.set(Collections.unmodifiableMap(newMap));
fireInitialMembershipEvent(event);
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientMembershipListener method membersString.
private String membersString() {
StringBuilder sb = new StringBuilder("\n\nMembers [");
sb.append(members.size());
sb.append("] {");
for (Member member : members) {
sb.append("\n\t").append(member);
}
sb.append("\n}\n");
return sb.toString();
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method getAllScheduledFutures.
@Override
public <V> Map<Member, List<IScheduledFuture<V>>> getAllScheduledFutures() {
ClientMessage request = ScheduledExecutorGetAllScheduledFuturesCodec.encodeRequest(getName());
final ClientInvocationFuture future = new ClientInvocation(getClient(), request).invoke();
ClientMessage response;
try {
response = future.get();
} catch (Exception e) {
throw rethrow(e);
}
Collection<Map.Entry<Member, List<ScheduledTaskHandler>>> urnsPerMember = ScheduledExecutorGetAllScheduledFuturesCodec.decodeResponse(response).handlers;
Map<Member, List<IScheduledFuture<V>>> tasksMap = new HashMap<Member, List<IScheduledFuture<V>>>();
for (Map.Entry<Member, List<ScheduledTaskHandler>> entry : urnsPerMember) {
List<IScheduledFuture<V>> memberTasks = new ArrayList<IScheduledFuture<V>>();
for (ScheduledTaskHandler scheduledTaskHandler : entry.getValue()) {
memberTasks.add(new ClientScheduledFutureProxy(scheduledTaskHandler, getContext()));
}
tasksMap.put(entry.getKey(), memberTasks);
}
return tasksMap;
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientScheduledExecutorProxy method scheduleOnMembers.
@Override
public <V> Map<Member, IScheduledFuture<V>> scheduleOnMembers(Callable<V> command, Collection<Member> members, long delay, TimeUnit unit) {
checkNotNull(command, "Command is null");
checkNotNull(members, "Members is null");
checkNotNull(unit, "Unit is null");
String name = extractNameOrGenerateOne(command);
Map<Member, IScheduledFuture<V>> futures = new HashMap<Member, IScheduledFuture<V>>();
for (Member member : members) {
TaskDefinition definition = new TaskDefinition(TaskDefinition.Type.SINGLE_RUN, name, command, delay, unit);
futures.put(member, (IScheduledFuture<V>) scheduleOnMember(name, member, definition));
}
return futures;
}
Aggregations