Search in sources :

Example 16 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class ReplicatedMapService method prepareReplicationOperation.

@Override
public Operation prepareReplicationOperation(PartitionReplicationEvent event) {
    if (nodeEngine.getLocalMember().isLiteMember()) {
        return null;
    }
    if (event.getReplicaIndex() > 0) {
        return null;
    }
    PartitionContainer container = partitionContainers[event.getPartitionId()];
    SerializationService serializationService = nodeEngine.getSerializationService();
    ReplicationOperation operation = new ReplicationOperation(serializationService, container, event.getPartitionId());
    operation.setService(this);
    return operation.isEmpty() ? null : operation;
}
Also used : SerializationService(com.hazelcast.internal.serialization.SerializationService) ReplicationOperation(com.hazelcast.replicatedmap.impl.operation.ReplicationOperation)

Example 17 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class CacheRecordStoreTestSupport method putAndSetExpiryPolicyFromRecordStore.

protected void putAndSetExpiryPolicyFromRecordStore(ICacheRecordStore cacheRecordStore, InMemoryFormat inMemoryFormat) {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    ExpiryPolicy expiryPolicy = new TouchedExpiryPolicy(Duration.ETERNAL);
    Data policyData = serializationService.toData(expiryPolicy);
    for (int i = 0; i < CACHE_RECORD_COUNT; i++) {
        Data keyData = serializationService.toData(i);
        cacheRecordStore.put(keyData, "value-" + i, null, null, -1);
        cacheRecordStore.setExpiryPolicy(Collections.singleton(keyData), policyData, null);
    }
    if (inMemoryFormat == InMemoryFormat.BINARY || inMemoryFormat == InMemoryFormat.NATIVE) {
        for (int i = 0; i < CACHE_RECORD_COUNT; i++) {
            assertTrue(Data.class.isAssignableFrom(cacheRecordStore.getExpiryPolicy(serializationService.toData(i)).getClass()));
        }
    } else if (inMemoryFormat == InMemoryFormat.OBJECT) {
        for (int i = 0; i < CACHE_RECORD_COUNT; i++) {
            assertTrue(ExpiryPolicy.class.isAssignableFrom(cacheRecordStore.getExpiryPolicy(serializationService.toData(i)).getClass()));
        }
    } else {
        throw new IllegalArgumentException("Unsupported in-memory format: " + inMemoryFormat);
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) SerializationService(com.hazelcast.internal.serialization.SerializationService) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Data(com.hazelcast.internal.serialization.Data)

Example 18 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class ClientCacheNearCacheInvalidationTest method setup.

@Before
public void setup() {
    hazelcastFactory = new TestHazelcastFactory();
    HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
    for (int i = 0; i < MEMBER_COUNT; i++) {
        // every instance should have its own getConfig() call because an existing EE test relies on this
        Config config = getConfig().setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_ENABLED.getName(), "false");
        allMembers[i] = hazelcastFactory.newHazelcastInstance(config);
    }
    waitAllForSafeState(allMembers);
    NearCacheConfig nearCacheConfig = getNearCacheConfig(inMemoryFormat);
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = createClientCachingProvider(client);
    HazelcastServerCachingProvider memberProvider = createServerCachingProvider(allMembers[0]);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
    CacheConfig<Integer, String> cacheConfig = getCacheConfig(inMemoryFormat);
    ICache<Integer, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, cacheConfig);
    ICache<Integer, String> memberCache = memberCacheManager.getCache(getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
    NearCacheManager nearCacheManager = ((ClientCacheProxy) cache).getContext().getNearCacheManager(cache.getServiceName());
    NearCache<Object, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
    SerializationService serializationService = client.getSerializationService();
    invalidationListener = createInvalidationEventHandler(cache);
    NearCacheTestContextBuilder<Integer, String, Object, String> builder = new NearCacheTestContextBuilder<>(nearCacheConfig, serializationService);
    testContext = builder.setDataInstance(allMembers[0]).setNearCacheInstance(client).setDataAdapter(new ICacheDataStructureAdapter<>(memberCache)).setNearCacheAdapter(new ICacheDataStructureAdapter<>(cache)).setMemberCacheManager(memberCacheManager).setCacheManager(cacheManager).setNearCacheManager(nearCacheManager).setNearCache(nearCache).build();
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheTestUtils.getBaseConfig(com.hazelcast.internal.nearcache.impl.NearCacheTestUtils.getBaseConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) HazelcastServerCacheManager(com.hazelcast.cache.impl.HazelcastServerCacheManager) SerializationService(com.hazelcast.internal.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NearCacheTestContextBuilder(com.hazelcast.internal.nearcache.impl.NearCacheTestContextBuilder) ICacheDataStructureAdapter(com.hazelcast.internal.adapter.ICacheDataStructureAdapter) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CacheTestSupport.createClientCachingProvider(com.hazelcast.cache.CacheTestSupport.createClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager) Before(org.junit.Before)

Example 19 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class PreJoinCacheConfig method writeFactories.

@Override
protected void writeFactories(ObjectDataOutput out) throws IOException {
    assert (out instanceof SerializationServiceSupport) : "out must implement SerializationServiceSupport";
    SerializationService serializationService = ((SerializationServiceSupport) out).getSerializationService();
    IOUtil.writeData(out, cacheLoaderFactory.getSerializedValue(serializationService));
    IOUtil.writeData(out, cacheWriterFactory.getSerializedValue(serializationService));
    IOUtil.writeData(out, expiryPolicyFactory.getSerializedValue(serializationService));
}
Also used : SerializationServiceSupport(com.hazelcast.spi.impl.SerializationServiceSupport) SerializationService(com.hazelcast.internal.serialization.SerializationService)

Example 20 with SerializationService

use of com.hazelcast.internal.serialization.SerializationService in project hazelcast by hazelcast.

the class DefaultClientExtension method createNearCacheManager.

@Override
public NearCacheManager createNearCacheManager() {
    SerializationService ss = client.getSerializationService();
    TaskScheduler taskScheduler = client.getTaskScheduler();
    ClassLoader classLoader = client.getClientConfig().getClassLoader();
    HazelcastProperties properties = client.getProperties();
    return new DefaultNearCacheManager(ss, taskScheduler, classLoader, properties);
}
Also used : HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) SerializationService(com.hazelcast.internal.serialization.SerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) DefaultNearCacheManager(com.hazelcast.internal.nearcache.impl.DefaultNearCacheManager) TaskScheduler(com.hazelcast.spi.impl.executionservice.TaskScheduler)

Aggregations

SerializationService (com.hazelcast.internal.serialization.SerializationService)170 Data (com.hazelcast.internal.serialization.Data)117 Test (org.junit.Test)100 QuickTest (com.hazelcast.test.annotation.QuickTest)99 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)59 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)50 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)43 ArrayList (java.util.ArrayList)15 SerializationConfig (com.hazelcast.config.SerializationConfig)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Node (com.hazelcast.instance.impl.Node)12 CustomSerializationTest (com.hazelcast.internal.serialization.impl.CustomSerializationTest)12 Accessors.getNode (com.hazelcast.test.Accessors.getNode)12 GenericRecord (com.hazelcast.nio.serialization.GenericRecord)11 EmployeeDTO (example.serialization.EmployeeDTO)11 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)11 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)8 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8