use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.
the class DefaultClientExtension method createSerializationService.
@Override
public InternalSerializationService createSerializationService(byte version) {
InternalSerializationService ss;
try {
ClientConfig config = client.getClientConfig();
ClassLoader configClassLoader = config.getClassLoader();
HazelcastInstance hazelcastInstance = client;
PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
if (version > 0) {
builder.setVersion(version);
}
ss = builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(new HazelcastClientManagedContext(client, config.getManagedContext())).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).build();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
return ss;
}
use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.
the class DefaultNodeExtension method createSerializationService.
public InternalSerializationService createSerializationService() {
InternalSerializationService ss;
try {
Config config = node.getConfig();
ClassLoader configClassLoader = node.getConfigClassLoader();
HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
byte version = (byte) node.getProperties().getInteger(GroupProperty.SERIALIZATION_VERSION);
ss = (InternalSerializationService) builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(hazelcastInstance.managedContext).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setVersion(version).build();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
return ss;
}
use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.
the class AbstractSerializationService method calculatePartitionHash.
protected final int calculatePartitionHash(Object obj, PartitioningStrategy strategy) {
int partitionHash = 0;
PartitioningStrategy partitioningStrategy = strategy == null ? globalPartitioningStrategy : strategy;
if (partitioningStrategy != null) {
Object pk = partitioningStrategy.getPartitionKey(obj);
if (pk != null && pk != obj) {
final Data partitionKey = toData(pk, EMPTY_PARTITIONING_STRATEGY);
partitionHash = partitionKey == null ? 0 : partitionKey.getPartitionHash();
}
}
return partitionHash;
}
use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.
the class BasicMapStoreContext method create.
static MapStoreContext create(MapContainer mapContainer) {
final BasicMapStoreContext context = new BasicMapStoreContext();
final String mapName = mapContainer.getName();
final MapServiceContext mapServiceContext = mapContainer.getMapServiceContext();
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
final PartitioningStrategy partitioningStrategy = mapContainer.getPartitioningStrategy();
final MapConfig mapConfig = mapContainer.getMapConfig();
final MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
final ClassLoader configClassLoader = nodeEngine.getConfigClassLoader();
// create store.
final Object store = createStore(mapName, mapStoreConfig, configClassLoader);
final MapStoreWrapper storeWrapper = new MapStoreWrapper(mapName, store);
storeWrapper.instrument(nodeEngine);
setStoreImplToWritableMapStoreConfig(nodeEngine, mapName, store);
context.setMapName(mapName);
context.setMapStoreConfig(mapStoreConfig);
context.setPartitioningStrategy(partitioningStrategy);
context.setMapServiceContext(mapServiceContext);
context.setStoreWrapper(storeWrapper);
final MapStoreManager mapStoreManager = createMapStoreManager(context);
context.setMapStoreManager(mapStoreManager);
// todo this is user code. it may also block map store creation.
callLifecycleSupportInit(context);
return context;
}
use of com.hazelcast.core.PartitioningStrategy in project hazelcast by hazelcast.
the class LazyEntryViewFromRecordTest method createDefaultEntryView.
/**
* Returns an entry-view instance populated with default values of fields.
*/
private EntryView createDefaultEntryView() {
PartitioningStrategy mockPartitioningStrategy = mock(PartitioningStrategy.class);
MapConfig mapConfig = new MapConfig();
serializationService = new DefaultSerializationServiceBuilder().build();
DataRecordFactory dataRecordFactory = new DataRecordFactory(mapConfig, serializationService, mockPartitioningStrategy);
recordInstance = dataRecordFactory.newRecord(value);
((AbstractRecord) recordInstance).setKey(serializationService.toData(key));
return new LazyEntryViewFromRecord(recordInstance, serializationService);
}
Aggregations