Search in sources :

Example 1 with PartitioningStrategy

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;
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SerializationConfig(com.hazelcast.config.SerializationConfig) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 2 with PartitioningStrategy

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;
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationServiceBuilder(com.hazelcast.internal.serialization.SerializationServiceBuilder) DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationConfig(com.hazelcast.config.SerializationConfig) Config(com.hazelcast.config.Config) SerializationConfig(com.hazelcast.config.SerializationConfig) DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) VersionMismatchException(com.hazelcast.internal.cluster.impl.VersionMismatchException)

Example 3 with PartitioningStrategy

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;
}
Also used : PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.nio.serialization.Data)

Example 4 with PartitioningStrategy

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;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapStoreWrapper(com.hazelcast.map.impl.MapStoreWrapper) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 5 with PartitioningStrategy

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);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) AbstractRecord(com.hazelcast.map.impl.record.AbstractRecord) MapConfig(com.hazelcast.config.MapConfig) DataRecordFactory(com.hazelcast.map.impl.record.DataRecordFactory)

Aggregations

PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)12 StringPartitioningStrategy (com.hazelcast.partition.strategy.StringPartitioningStrategy)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 PartitioningStrategyConfig (com.hazelcast.config.PartitioningStrategyConfig)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)4 Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 SerializationConfig (com.hazelcast.config.SerializationConfig)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2 DefaultPartitioningStrategy (com.hazelcast.partition.strategy.DefaultPartitioningStrategy)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 VersionMismatchException (com.hazelcast.internal.cluster.impl.VersionMismatchException)1 HeapData (com.hazelcast.internal.serialization.impl.HeapData)1 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1