use of com.hazelcast.config.ReplicatedMapConfig in project hazelcast by hazelcast.
the class ReplicatedMapEventPublishingService method dispatchEvent.
@Override
public void dispatchEvent(Object event, Object listener) {
if ((event instanceof EntryEventData)) {
EntryEventData entryEventData = (EntryEventData) event;
Member member = getMember(entryEventData);
EntryEvent entryEvent = createDataAwareEntryEvent(entryEventData, member);
EntryListener entryListener = (EntryListener) listener;
switch(entryEvent.getEventType()) {
case ADDED:
entryListener.entryAdded(entryEvent);
break;
case EVICTED:
entryListener.entryEvicted(entryEvent);
break;
case UPDATED:
entryListener.entryUpdated(entryEvent);
break;
case REMOVED:
entryListener.entryRemoved(entryEvent);
break;
default:
throw new IllegalArgumentException("event type " + entryEvent.getEventType() + " not supported");
}
String mapName = ((EntryEventData) event).getMapName();
Boolean statisticsEnabled = statisticsMap.get(mapName);
if (statisticsEnabled == null) {
ReplicatedMapConfig mapConfig = config.findReplicatedMapConfig(mapName);
statisticsEnabled = mapConfig.isStatisticsEnabled();
statisticsMap.put(mapName, statisticsEnabled);
}
if (statisticsEnabled) {
int partitionId = nodeEngine.getPartitionService().getPartitionId(entryEventData.getDataKey());
ReplicatedRecordStore recordStore = replicatedMapService.getPartitionContainer(partitionId).getRecordStore(mapName);
if (recordStore instanceof AbstractReplicatedRecordStore) {
LocalReplicatedMapStatsImpl stats = ((AbstractReplicatedRecordStore) recordStore).getStats();
stats.incrementReceivedEvents();
}
}
} else if (event instanceof MapEventData) {
MapEventData mapEventData = (MapEventData) event;
Member member = getMember(mapEventData);
MapEvent mapEvent = new MapEvent(mapEventData.getMapName(), member, mapEventData.getEventType(), mapEventData.getNumberOfEntries());
EntryListener entryListener = (EntryListener) listener;
EntryEventType type = EntryEventType.getByType(mapEventData.getEventType());
if (type == EntryEventType.CLEAR_ALL) {
entryListener.mapCleared(mapEvent);
} else {
throw new IllegalArgumentException("Unsupported EntryEventType: " + type);
}
}
}
use of com.hazelcast.config.ReplicatedMapConfig in project hazelcast by hazelcast.
the class ReplicatedMapService method createDistributedObject.
@Override
public DistributedObject createDistributedObject(String objectName, UUID source, boolean local) {
ReplicatedMapConfig replicatedMapConfig = getReplicatedMapConfig(objectName);
checkReplicatedMapConfig(replicatedMapConfig, mergePolicyProvider);
if (nodeEngine.getLocalMember().isLiteMember()) {
throw new ReplicatedMapCantBeCreatedOnLiteMemberException(nodeEngine.getThisAddress());
}
for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
PartitionContainer partitionContainer = partitionContainers[i];
if (partitionContainer == null) {
continue;
}
partitionContainer.getOrCreateRecordStore(objectName);
}
return new ReplicatedMapProxy(nodeEngine, objectName, this, replicatedMapConfig);
}
use of com.hazelcast.config.ReplicatedMapConfig in project hazelcast by hazelcast.
the class MergePolicyValidatorReplicatedMapIntegrationTest method addConfig.
@Override
void addConfig(Config config, String name, MergePolicyConfig mergePolicyConfig) {
ReplicatedMapConfig replicatedMapConfig = new ReplicatedMapConfig(name).setMergePolicyConfig(mergePolicyConfig);
config.addReplicatedMapConfig(replicatedMapConfig);
}
use of com.hazelcast.config.ReplicatedMapConfig in project hazelcast by hazelcast.
the class ConfigSearchTest method testReplicatedMapConfig_Dynamic.
@Test
public void testReplicatedMapConfig_Dynamic() {
TestCase<ReplicatedMapConfig> testCase = new TestCase<ReplicatedMapConfig>(new ReplicatedMapConfig().setName(STATIC_NAME), new ReplicatedMapConfig().setName(DYNAMIC_NAME), true) {
@Override
void addStaticConfig(Config config) {
config.addReplicatedMapConfig(this.staticConfig);
}
@Override
void addDynamicConfig(HazelcastInstance hazelcastInstance) {
hazelcastInstance.getConfig().addReplicatedMapConfig(this.dynamicConfig);
}
@Override
void asserts() {
ReplicatedMapConfig dataConfig = hazelcastInstance.getConfig().findReplicatedMapConfig(DYNAMIC_NAME);
assertThat(dataConfig.getName(), equalTo(DYNAMIC_NAME));
}
};
testTemplate(testCase);
}
use of com.hazelcast.config.ReplicatedMapConfig in project hazelcast by hazelcast.
the class ConfigSearchTest method testReplicatedMapConfig_Static.
@Test
public void testReplicatedMapConfig_Static() {
TestCase<ReplicatedMapConfig> testCase = new TestCase<ReplicatedMapConfig>(new ReplicatedMapConfig().setName(STATIC_NAME), new ReplicatedMapConfig().setName(DYNAMIC_NAME), false) {
@Override
void addStaticConfig(Config config) {
config.addReplicatedMapConfig(this.staticConfig);
}
@Override
void addDynamicConfig(HazelcastInstance hazelcastInstance) {
hazelcastInstance.getConfig().addReplicatedMapConfig(this.dynamicConfig);
}
@Override
void asserts() {
ReplicatedMapConfig dataConfig = hazelcastInstance.getConfig().findReplicatedMapConfig(DYNAMIC_NAME);
assertThat(dataConfig.getName(), equalTo(STATIC_NAME));
}
};
testTemplate(testCase);
}
Aggregations