use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class HazelcastTestSupport method randomNameOwnedBy.
public static String randomNameOwnedBy(HazelcastInstance instance, String prefix) {
Member localMember = instance.getCluster().getLocalMember();
PartitionService partitionService = instance.getPartitionService();
while (true) {
String id = prefix + randomString();
Partition partition = partitionService.getPartition(id);
if (comparePartitionOwnership(true, localMember, partition)) {
return id;
}
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class HazelcastTestSupport method generateKeyForPartition.
public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
Cluster cluster = instance.getCluster();
checkPartitionCountGreaterOrEqualMemberCount(instance);
Member localMember = cluster.getLocalMember();
PartitionService partitionService = instance.getPartitionService();
while (true) {
String id = randomString();
Partition partition = partitionService.getPartition(id);
if (partition.getPartitionId() == partitionId) {
return id;
}
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientConsoleApp method doExecute.
private void doExecute(boolean onKey, boolean onMember, String[] args) {
// executeOnKey <echo-string> <key>
try {
IExecutorService executorService = hazelcast.getExecutorService("default");
Echo callable = new Echo(args[1]);
Future<String> future;
if (onKey) {
String key = args[2];
future = executorService.submitToKeyOwner(callable, key);
} else if (onMember) {
int memberIndex = Integer.parseInt(args[2]);
List<Member> members = new LinkedList(hazelcast.getCluster().getMembers());
if (memberIndex >= members.size()) {
throw new IndexOutOfBoundsException("Member index: " + memberIndex + " must be smaller than " + members.size());
}
Member member = members.get(memberIndex);
future = executorService.submitToMember(callable, member);
} else {
future = executorService.submit(callable);
}
println("Result: " + future.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientCacheMetaDataFetcher method scanMembers.
@Override
protected List<InternalCompletableFuture> scanMembers(List<String> names) {
Collection<Member> members = clusterService.getMembers(DATA_MEMBER_SELECTOR);
List<InternalCompletableFuture> futures = new ArrayList<InternalCompletableFuture>(members.size());
for (Member member : members) {
Address address = member.getAddress();
ClientMessage message = encodeRequest(names, address);
ClientInvocation invocation = new ClientInvocation(clientImpl, message, address);
try {
futures.add(invocation.invoke());
} catch (Exception e) {
if (logger.isWarningEnabled()) {
logger.warning("Cant fetch invalidation meta-data from address + " + address + " + [" + e.getMessage() + "]");
}
}
}
return futures;
}
use of com.hazelcast.core.Member in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method submitToMembers.
@Override
public <T> void submitToMembers(Callable<T> task, Collection<Member> members, MultiExecutionCallback callback) {
MultiExecutionCallbackWrapper multiExecutionCallbackWrapper = new MultiExecutionCallbackWrapper(members.size(), callback);
for (Member member : members) {
final ExecutionCallbackWrapper<T> executionCallback = new ExecutionCallbackWrapper<T>(multiExecutionCallbackWrapper, member);
submitToMember(task, member, executionCallback);
}
}
Aggregations