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);
}
}
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);
}
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()));
}
}
}
}
}
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);
}
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);
}
Aggregations