Search in sources :

Example 16 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project hazelcast by hazelcast.

the class ClientExecutorServiceSubmitTest method submitCallable_withExecutionCallback.

@Test
public void submitCallable_withExecutionCallback() {
    IExecutorService service = client.getExecutorService(randomString());
    final CountDownLatch responseLatch = new CountDownLatch(1);
    String msg = randomString();
    Callable runnable = new AppendCallable(msg);
    MemberSelector selector = new SelectAllMembers();
    final AtomicReference<Object> result = new AtomicReference<Object>();
    service.submit(runnable, selector, new ExecutionCallback() {

        public void onResponse(Object response) {
            result.set(response);
            responseLatch.countDown();
        }

        public void onFailure(Throwable t) {
        }
    });
    assertOpenEventually("responseLatch", responseLatch);
    assertEquals(msg + AppendCallable.APPENDAGE, result.get());
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) SelectAllMembers(com.hazelcast.client.test.executor.tasks.SelectAllMembers) AtomicReference(java.util.concurrent.atomic.AtomicReference) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) CountDownLatch(java.util.concurrent.CountDownLatch) NullCallable(com.hazelcast.client.test.executor.tasks.NullCallable) Callable(java.util.concurrent.Callable) AppendCallable(com.hazelcast.client.test.executor.tasks.AppendCallable) MapPutPartitionAwareCallable(com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project hazelcast by hazelcast.

the class ClientExecutorServiceTest method testExecute_withNoMemberSelected.

@Test(expected = RejectedExecutionException.class)
public void testExecute_withNoMemberSelected() {
    IExecutorService service = client.getExecutorService(randomString());
    String mapName = randomString();
    MemberSelector selector = new SelectNoMembers();
    service.execute(new MapPutRunnable(mapName), selector);
}
Also used : SelectNoMembers(com.hazelcast.client.test.executor.tasks.SelectNoMembers) MemberSelector(com.hazelcast.cluster.MemberSelector) MapPutRunnable(com.hazelcast.client.executor.tasks.MapPutRunnable) IExecutorService(com.hazelcast.core.IExecutorService) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project sonarqube by SonarSource.

the class AppNodesClusterHostsConsistency method check.

public void check() {
    try {
        MemberSelector selector = MemberSelectors.and(NON_LOCAL_MEMBER_SELECTOR, HazelcastMemberSelectors.selectorForProcessIds(ProcessId.APP));
        hzMember.callAsync(AppNodesClusterHostsConsistency::getConfiguredClusterHosts, selector, new Callback());
    } catch (RejectedExecutionException e) {
    // no other node in the cluster yet, ignore
    }
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) DistributedCallback(org.sonar.process.cluster.hz.DistributedCallback) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 19 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project hazelcast by hazelcast.

the class PartitionStateManager method createMemberGroups.

private Collection<MemberGroup> createMemberGroups(final Set<Member> excludedMembers) {
    MemberSelector exclude = member -> !excludedMembers.contains(member);
    final MemberSelector selector = MemberSelectors.and(DATA_MEMBER_SELECTOR, exclude);
    final Collection<Member> members = node.getClusterService().getMembers(selector);
    return memberGroupFactory.createMemberGroups(members);
}
Also used : Address(com.hazelcast.cluster.Address) NodeExtension(com.hazelcast.instance.impl.NodeExtension) Member(com.hazelcast.cluster.Member) MemberGroupFactoryFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactoryFactory) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_LOCAL_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_LOCAL_PARTITION_COUNT) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_STAMP(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_STAMP) ConcurrentMap(java.util.concurrent.ConcurrentMap) ClusterService(com.hazelcast.internal.cluster.ClusterService) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) DATA_MEMBER_SELECTOR(com.hazelcast.cluster.memberselector.MemberSelectors.DATA_MEMBER_SELECTOR) ILogger(com.hazelcast.logging.ILogger) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_PARTITION_COUNT) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) HazelcastException(com.hazelcast.core.HazelcastException) PartitionReplicaInterceptor(com.hazelcast.internal.partition.PartitionReplicaInterceptor) InternalPartition(com.hazelcast.internal.partition.InternalPartition) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_ACTIVE_PARTITION_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_ACTIVE_PARTITION_COUNT) Set(java.util.Set) UUID(java.util.UUID) PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_MEMBER_GROUP_SIZE(com.hazelcast.internal.metrics.MetricDescriptorConstants.PARTITIONS_METRIC_PARTITION_REPLICA_STATE_MANAGER_MEMBER_GROUP_SIZE) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) Node(com.hazelcast.instance.impl.Node) MemberSelector(com.hazelcast.cluster.MemberSelector) ClusterState(com.hazelcast.cluster.ClusterState) MemberSelectors(com.hazelcast.cluster.memberselector.MemberSelectors) PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) Collections(java.util.Collections) PartitionStampUtil.calculateStamp(com.hazelcast.internal.partition.PartitionStampUtil.calculateStamp) MemberSelector(com.hazelcast.cluster.MemberSelector) Member(com.hazelcast.cluster.Member)

Example 20 with MemberSelector

use of com.hazelcast.cluster.MemberSelector in project hazelcast by hazelcast.

the class MemberSelectorsTest method testAndMemberSelector3.

@Test
public void testAndMemberSelector3() {
    when(member.localMember()).thenReturn(true);
    when(member.isLiteMember()).thenReturn(true);
    MemberSelector selector = MemberSelectors.and(LOCAL_MEMBER_SELECTOR, LITE_MEMBER_SELECTOR);
    assertTrue(selector.select(member));
    verify(member).localMember();
    verify(member).isLiteMember();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MemberSelector (com.hazelcast.cluster.MemberSelector)23 Test (org.junit.Test)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 IExecutorService (com.hazelcast.core.IExecutorService)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 SelectAllMembers (com.hazelcast.client.test.executor.tasks.SelectAllMembers)8 Member (com.hazelcast.cluster.Member)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)6 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AppendCallable (com.hazelcast.client.test.executor.tasks.AppendCallable)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)3 IMap (com.hazelcast.map.IMap)3 Callable (java.util.concurrent.Callable)3 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)2 MapPutPartitionAwareCallable (com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable)2 NullCallable (com.hazelcast.client.test.executor.tasks.NullCallable)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2