use of com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore in project hazelcast by hazelcast.
the class ReplicationOperation method fillRecordStoreWithRecords.
private void fillRecordStoreWithRecords(ReplicatedMapService service) {
for (Map.Entry<String, Set<RecordMigrationInfo>> dataEntry : data.entrySet()) {
Set<RecordMigrationInfo> recordSet = dataEntry.getValue();
String name = dataEntry.getKey();
AbstractReplicatedRecordStore store = (AbstractReplicatedRecordStore) service.getReplicatedRecordStore(name, true, getPartitionId());
long version = versions.get(name);
store.putRecords(recordSet, version);
store.setLoaded(true);
}
}
use of com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore in project hazelcast by hazelcast.
the class PartitionContainer method buildConstructorFunction.
private ConstructorFunction<String, ReplicatedRecordStore> buildConstructorFunction() {
return new ConstructorFunction<String, ReplicatedRecordStore>() {
@Override
public ReplicatedRecordStore createNew(String name) {
ReplicatedMapConfig replicatedMapConfig = service.getReplicatedMapConfig(name);
InMemoryFormat inMemoryFormat = replicatedMapConfig.getInMemoryFormat();
AbstractReplicatedRecordStore replicatedRecordStorage = null;
switch(inMemoryFormat) {
case OBJECT:
replicatedRecordStorage = new ObjectReplicatedRecordStorage(name, service, partitionId);
break;
case BINARY:
replicatedRecordStorage = new DataReplicatedRecordStore(name, service, partitionId);
break;
case NATIVE:
throw new IllegalStateException("Native memory not yet supported for replicated map");
default:
throw new IllegalStateException("Unhandled in memory format:" + inMemoryFormat);
}
return replicatedRecordStorage;
}
};
}
use of com.hazelcast.replicatedmap.impl.record.AbstractReplicatedRecordStore 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.replicatedmap.impl.record.AbstractReplicatedRecordStore in project hazelcast by hazelcast.
the class SyncReplicatedMapDataOperation method run.
@Override
@SuppressWarnings("unchecked")
public void run() throws Exception {
ILogger logger = getLogger();
if (logger.isFineEnabled()) {
logger.fine("Syncing " + recordSet.size() + " records (version " + version + ") for replicated map '" + name + "' (partitionId " + getPartitionId() + ") from " + getCallerAddress() + " to " + getNodeEngine().getThisAddress());
}
ReplicatedMapService service = getService();
AbstractReplicatedRecordStore store = (AbstractReplicatedRecordStore) service.getReplicatedRecordStore(name, true, getPartitionId());
InternalReplicatedMapStorage<K, V> newStorage = new InternalReplicatedMapStorage<>();
for (RecordMigrationInfo record : recordSet) {
K key = (K) store.marshall(record.getKey());
V value = (V) store.marshall(record.getValue());
ReplicatedRecord<K, V> replicatedRecord = buildReplicatedRecord(key, value, record.getTtl());
ReplicatedRecord oldRecord = store.getReplicatedRecord(key);
if (oldRecord != null) {
replicatedRecord.setHits(oldRecord.getHits());
}
newStorage.put(key, replicatedRecord);
if (record.getTtl() > 0) {
store.scheduleTtlEntry(record.getTtl(), key, value);
}
}
newStorage.syncVersion(version);
AtomicReference<InternalReplicatedMapStorage<K, V>> storageRef = store.getStorageRef();
storageRef.set(newStorage);
store.setLoaded(true);
}
Aggregations