use of com.hazelcast.partition.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);
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.partition.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.partition.PartitioningStrategy in project hazelcast by hazelcast.
the class WriteMapP method init.
@Override
public void init(@Nonnull Outbox outbox, @Nonnull Context context) {
map = instance().getMap(mapName);
boolean hasCustomSerializers = serializationService instanceof DelegatingSerializationService && ((DelegatingSerializationService) serializationService).hasAddedSerializers();
boolean hasNearCache = map instanceof NearCachedMapProxyImpl;
if (hasNearCache && hasCustomSerializers) {
// See https://github.com/hazelcast/hazelcast-jet/issues/3046
throw new JetException("Writing into IMap with both near cache and custom serializers not supported");
}
if (!hasCustomSerializers) {
addToBuffer = item -> buffer.add(new SimpleEntry<>(key(item), value(item)));
} else if (map instanceof MapProxyImpl) {
PartitioningStrategy<?> partitionStrategy = ((MapProxyImpl<K, V>) map).getPartitionStrategy();
addToBuffer = item -> {
Data key = serializationService.toData(key(item), partitionStrategy);
Data value = serializationService.toData(value(item));
buffer.add(new SimpleEntry<>(key, value));
};
} else if (map instanceof ClientMapProxy) {
// TODO: add strategy/unify after https://github.com/hazelcast/hazelcast/issues/13950 is fixed
addToBuffer = item -> {
Data key = serializationService.toData(key(item));
Data value = serializationService.toData(value(item));
buffer.add(new SimpleEntry<>(key, value));
};
} else {
throw new RuntimeException("Unexpected map class: " + map.getClass().getName());
}
}
use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.
the class DefaultClientExtension method createSerializationService.
@Override
public InternalSerializationService createSerializationService(byte version) {
try {
ClientConfig config = client.getClientConfig();
ClassLoader configClassLoader = config.getClassLoader();
HazelcastInstance hazelcastInstance = client;
PartitioningStrategy partitioningStrategy = getPartitioningStrategy(configClassLoader);
SerializationConfig serializationConfig = config.getSerializationConfig() != null ? config.getSerializationConfig() : new SerializationConfig();
SerializationServiceBuilder builder = new DefaultSerializationServiceBuilder();
if (version > 0) {
builder.setVersion(version);
}
return builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(new HazelcastClientManagedContext(client, config.getManagedContext())).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setNotActiveExceptionSupplier(HazelcastClientNotActiveException::new).setSchemaService(client.getSchemaService()).build();
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.partition.PartitioningStrategy in project hazelcast by hazelcast.
the class DefaultNodeExtension method createSerializationService.
/**
* Creates a serialization service. The {@code isCompatibility} parameter defines
* whether the serialization format used by the service will conform to the
* 3.x or the 4.x format.
*
* @param isCompatibility {@code true} if the serialized format should conform to the
* 3.x serialization format, {@code false} otherwise
* @return the serialization service
*/
private InternalSerializationService createSerializationService(boolean isCompatibility) {
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(ClusterProperty.SERIALIZATION_VERSION);
ss = builder.setClassLoader(configClassLoader).setConfig(serializationConfig).setManagedContext(hazelcastInstance.managedContext).setPartitioningStrategy(partitioningStrategy).setHazelcastInstance(hazelcastInstance).setVersion(version).setSchemaService(node.memberSchemaService).setNotActiveExceptionSupplier(new Supplier<RuntimeException>() {
@Override
public RuntimeException get() {
return new HazelcastInstanceNotActiveException();
}
}).isCompatibility(isCompatibility).build();
} catch (Exception e) {
throw rethrow(e);
}
return ss;
}
Aggregations