use of com.hazelcast.core.Member in project microservices by pwillhan.
the class ExecutionOnMemberExample method main.
public static void main(String[] args) throws Exception {
Config conf = new Config();
HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
Member thisMember = hz.getCluster().getLocalMember();
IExecutorService exec = hz.getExecutorService("exec");
Callable<String> timeTask = new TimeInstanceAwareCallable();
Member member = thisMember;
Future<String> specificTask = exec.submitToMember(timeTask, member);
String timeFromSpecificMember = specificTask.get(10, TimeUnit.SECONDS);
System.err.println(timeFromSpecificMember);
}
use of com.hazelcast.core.Member in project microservices by pwillhan.
the class QuorumExample method main.
public static void main(String[] args) throws Exception {
QuorumConfig quorumConf = new QuorumConfig();
quorumConf.setName("atLeastTwoNodesWithMajority");
quorumConf.setEnabled(true);
quorumConf.setType(QuorumType.WRITE);
quorumConf.addListenerConfig(new QuorumListenerConfig(new ClusterQuorumListener()));
final int expectedClusterSize = 5;
quorumConf.setQuorumFunctionImplementation(new QuorumFunction() {
@Override
public boolean apply(Collection<Member> members) {
return members.size() >= 2 && members.size() > expectedClusterSize / 2;
}
});
MapConfig mapConf = new MapConfig();
mapConf.setName("default");
mapConf.setQuorumName("atLeastTwoNodesWithMajority");
Config conf = new Config();
conf.addQuorumConfig(quorumConf);
conf.addMapConfig(mapConf);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
new ConsoleApp(hz).start(args);
}
use of com.hazelcast.core.Member in project openmeetings by apache.
the class Application method updateJpaAddresses.
@Override
public void updateJpaAddresses() {
StringBuilder sb = new StringBuilder();
String delim = "";
for (Member m : hazelcast.getCluster().getMembers()) {
sb.append(delim).append(m.getAddress().getHost());
delim = ";";
}
if (Strings.isEmpty(delim)) {
sb.append("localhost");
}
try {
cfgDao.updateClusterAddresses(sb.toString());
} catch (UnknownHostException e) {
log.error("Uexpected exception while updating JPA addresses", e);
throw new WicketRuntimeException(e);
}
}
use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.
the class KeyUtils method isLocalKey.
/**
* Checks if a key is located on a Hazelcast instance.
*
* @param instance the HazelcastInstance the key should belong to
* @param key the key to check
* @return <tt>true</tt> if the key belongs to the Hazelcast instance, <tt>false</tt> otherwise
*/
public static boolean isLocalKey(HazelcastInstance instance, Object key) {
PartitionService partitionService = instance.getPartitionService();
Partition partition = partitionService.getPartition(key);
Member owner;
while (true) {
owner = partition.getOwner();
if (owner != null) {
break;
}
sleepSeconds(1);
}
return owner.equals(instance.getLocalEndpoint());
}
use of com.hazelcast.core.Member in project hazelcast-simulator by hazelcast.
the class HazelcastTestUtils method getOperationCount.
public static Map<Member, Long> getOperationCount(HazelcastInstance hz) {
IExecutorService executorService = hz.getExecutorService("operationCountExecutor");
Map<Member, Future<Long>> futures = new HashMap<Member, Future<Long>>();
for (Member member : hz.getCluster().getMembers()) {
Future<Long> future = executorService.submitToMember(new GetOperationCount(), member);
futures.put(member, future);
}
Map<Member, Long> result = new HashMap<Member, Long>();
for (Map.Entry<Member, Future<Long>> entry : futures.entrySet()) {
try {
Member member = entry.getKey();
Long value = entry.getValue().get();
if (value == null) {
value = 0L;
}
result.put(member, value);
} catch (Exception e) {
throw rethrow(e);
}
}
return result;
}
Aggregations