Search in sources :

Example 61 with Member

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) IExecutorService(com.hazelcast.core.IExecutorService) Member(com.hazelcast.core.Member) TimeInstanceAwareCallable(tasks.TimeInstanceAwareCallable)

Example 62 with Member

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);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClusterQuorumListener(listeners.ClusterQuorumListener) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) ConsoleApp(com.hazelcast.console.ConsoleApp) MapConfig(com.hazelcast.config.MapConfig) QuorumFunction(com.hazelcast.quorum.QuorumFunction) Member(com.hazelcast.core.Member)

Example 63 with Member

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Member(com.hazelcast.core.Member)

Example 64 with Member

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());
}
Also used : Partition(com.hazelcast.core.Partition) PartitionService(com.hazelcast.core.PartitionService) Member(com.hazelcast.core.Member)

Example 65 with Member

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;
}
Also used : HashMap(java.util.HashMap) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) Member(com.hazelcast.core.Member) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) InvocationTargetException(java.lang.reflect.InvocationTargetException) TestException(com.hazelcast.simulator.test.TestException)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12