Search in sources :

Example 1 with MutableInteger

use of com.hazelcast.internal.util.MutableInteger in project hazelcast by hazelcast.

the class CyclicWriteBehindQueue method decreaseCountIndex.

private void decreaseCountIndex(DelayedEntry entry) {
    Data key = (Data) entry.getKey();
    Map<Data, MutableInteger> index = this.index;
    MutableInteger count = index.get(key);
    if (count == null) {
        return;
    }
    count.value--;
    if (count.value == 0) {
        index.remove(key);
    } else {
        index.put(key, count);
    }
}
Also used : MutableInteger(com.hazelcast.internal.util.MutableInteger) Data(com.hazelcast.internal.serialization.Data)

Example 2 with MutableInteger

use of com.hazelcast.internal.util.MutableInteger in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method test_n_iterations.

@Test
public void test_n_iterations() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int n = 15;
    for (int i = 0; i < 10; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, n, lifecycleService);
    MutableInteger count = new MutableInteger();
    discoveryService.tryNextCluster((o, o2) -> {
        count.value++;
        return false;
    });
    assertEquals(10 * n, count.value);
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) MutableInteger(com.hazelcast.internal.util.MutableInteger) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MutableInteger

use of com.hazelcast.internal.util.MutableInteger in project hazelcast by hazelcast.

the class ConfigValidator method checkAdvancedNetworkConfig.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:booleanexpressioncomplexity" })
public static void checkAdvancedNetworkConfig(Config config) {
    if (!config.getAdvancedNetworkConfig().isEnabled()) {
        return;
    }
    EnumMap<ProtocolType, MutableInteger> serverSocketsPerProtocolType = new EnumMap<>(ProtocolType.class);
    for (ProtocolType protocolType : ProtocolType.values()) {
        serverSocketsPerProtocolType.put(protocolType, new MutableInteger());
    }
    Map<EndpointQualifier, EndpointConfig> endpointConfigs = config.getAdvancedNetworkConfig().getEndpointConfigs();
    for (EndpointConfig endpointConfig : endpointConfigs.values()) {
        if (endpointConfig instanceof ServerSocketEndpointConfig) {
            serverSocketsPerProtocolType.get(endpointConfig.getProtocolType()).getAndInc();
        }
    }
    for (ProtocolType protocolType : ProtocolType.values()) {
        int serverSocketCount = serverSocketsPerProtocolType.get(protocolType).value;
        if (serverSocketCount > protocolType.getServerSocketCardinality()) {
            throw new InvalidConfigurationException(format("Protocol type %s allows definition " + "of up to %d server sockets but %d were configured", protocolType, protocolType.getServerSocketCardinality(), serverSocketCount));
        }
    }
    // ensure there is 1 MEMBER type server socket
    if (serverSocketsPerProtocolType.get(MEMBER).value != 1) {
        throw new InvalidConfigurationException("A member-server-socket-endpoint" + " configuration is required for the cluster to form.");
    }
    // endpoint qualifiers referenced by WAN publishers must exist
    for (WanReplicationConfig wanReplicationConfig : config.getWanReplicationConfigs().values()) {
        for (WanBatchPublisherConfig wanPublisherConfig : wanReplicationConfig.getBatchPublisherConfigs()) {
            if (wanPublisherConfig.getEndpoint() != null) {
                EndpointQualifier qualifier = EndpointQualifier.resolve(WAN, wanPublisherConfig.getEndpoint());
                if (endpointConfigs.get(qualifier) == null) {
                    throw new InvalidConfigurationException(format("WAN publisher config for cluster name '%s' requires an wan-endpoint " + "config with identifier '%s' but none was found", wanPublisherConfig.getClusterName(), wanPublisherConfig.getEndpoint()));
                }
            }
        }
    }
}
Also used : WanBatchPublisherConfig(com.hazelcast.config.WanBatchPublisherConfig) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) ProtocolType(com.hazelcast.instance.ProtocolType) MutableInteger(com.hazelcast.internal.util.MutableInteger) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) EnumMap(java.util.EnumMap) EndpointConfig(com.hazelcast.config.EndpointConfig) ServerSocketEndpointConfig(com.hazelcast.config.ServerSocketEndpointConfig) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException)

Example 4 with MutableInteger

use of com.hazelcast.internal.util.MutableInteger in project hazelcast by hazelcast.

the class ClientClusterDiscoveryServiceTest method test_no_iteration_when_try_count_is_zero.

@Test
public void test_no_iteration_when_try_count_is_zero() {
    ArrayList<CandidateClusterContext> arrayList = new ArrayList<>();
    int numberOfCandidates = 10;
    for (int i = 0; i < numberOfCandidates; i++) {
        arrayList.add(createContext(i));
    }
    ClusterDiscoveryService discoveryService = new ClusterDiscoveryService(arrayList, 0, lifecycleService);
    MutableInteger count = new MutableInteger();
    for (int i = 0; i < 3; i++) {
        discoveryService.tryNextCluster((o, o2) -> {
            count.value++;
            return false;
        });
    }
    assertEquals(0, count.value);
}
Also used : CandidateClusterContext(com.hazelcast.client.impl.clientside.CandidateClusterContext) MutableInteger(com.hazelcast.internal.util.MutableInteger) ArrayList(java.util.ArrayList) ClusterDiscoveryService(com.hazelcast.client.impl.clientside.ClusterDiscoveryService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MutableInteger

use of com.hazelcast.internal.util.MutableInteger in project hazelcast by hazelcast.

the class CyclicWriteBehindQueue method addCountIndex.

private void addCountIndex(DelayedEntry entry) {
    Data key = (Data) entry.getKey();
    Map<Data, MutableInteger> index = this.index;
    MutableInteger count = index.get(key);
    if (count == null) {
        count = new MutableInteger();
    }
    count.value++;
    index.put(key, count);
}
Also used : MutableInteger(com.hazelcast.internal.util.MutableInteger) Data(com.hazelcast.internal.serialization.Data)

Aggregations

MutableInteger (com.hazelcast.internal.util.MutableInteger)6 CandidateClusterContext (com.hazelcast.client.impl.clientside.CandidateClusterContext)3 ClusterDiscoveryService (com.hazelcast.client.impl.clientside.ClusterDiscoveryService)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Data (com.hazelcast.internal.serialization.Data)2 EndpointConfig (com.hazelcast.config.EndpointConfig)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 ServerSocketEndpointConfig (com.hazelcast.config.ServerSocketEndpointConfig)1 WanBatchPublisherConfig (com.hazelcast.config.WanBatchPublisherConfig)1 WanReplicationConfig (com.hazelcast.config.WanReplicationConfig)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 ProtocolType (com.hazelcast.instance.ProtocolType)1 EnumMap (java.util.EnumMap)1