Search in sources :

Example 1 with DataSerializableFactory

use of com.hazelcast.nio.serialization.DataSerializableFactory in project hazelcast by hazelcast.

the class TxnMapDeserializationTest method setup.

@Before
public void setup() {
    // Identified factory is only set to client, to make sure there is no deserialization on server.
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().addDataSerializableFactory(SampleIdentified.FACTORY_ID, new DataSerializableFactory() {

        @Override
        public IdentifiedDataSerializable create(int typeId) {
            return new SampleIdentified();
        }
    });
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    client.getMap("test").put(EXISTING_KEY, EXISTING_VALUE);
    client.getMap("test").get(EXISTING_KEY);
    context = client.newTransactionContext();
    context.beginTransaction();
    map = context.getMap("test");
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) Before(org.junit.Before)

Example 2 with DataSerializableFactory

use of com.hazelcast.nio.serialization.DataSerializableFactory in project hazelcast by hazelcast.

the class DefaultSerializationServiceBuilder method buildDataSerializableFactories.

private void buildDataSerializableFactories(Map<Integer, DataSerializableFactory> dataSerializableFactories, SerializationConfig config, ClassLoader cl) {
    for (Map.Entry<Integer, String> entry : config.getDataSerializableFactoryClasses().entrySet()) {
        int factoryId = entry.getKey();
        String factoryClassName = entry.getValue();
        if (factoryId <= 0) {
            throw new IllegalArgumentException("DataSerializableFactory factoryId must be positive! -> " + factoryClassName);
        }
        if (dataSerializableFactories.containsKey(factoryId)) {
            throw new IllegalArgumentException("DataSerializableFactory with factoryId '" + factoryId + "' is already registered!");
        }
        DataSerializableFactory factory;
        try {
            factory = ClassLoaderUtil.newInstance(cl, factoryClassName);
        } catch (Exception e) {
            throw new HazelcastSerializationException(e);
        }
        dataSerializableFactories.put(factoryId, factory);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) HashMap(java.util.HashMap) Map(java.util.Map) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException)

Example 3 with DataSerializableFactory

use of com.hazelcast.nio.serialization.DataSerializableFactory in project hazelcast by hazelcast.

the class DefaultSerializationServiceBuilder method registerDataSerializableFactories.

private void registerDataSerializableFactories(Map<Integer, DataSerializableFactory> dataSerializableFactories, SerializationConfig config) {
    for (Map.Entry<Integer, DataSerializableFactory> entry : config.getDataSerializableFactories().entrySet()) {
        int factoryId = entry.getKey();
        DataSerializableFactory factory = entry.getValue();
        if (factoryId <= 0) {
            throw new IllegalArgumentException("DataSerializableFactory factoryId must be positive! -> " + factory);
        }
        if (dataSerializableFactories.containsKey(factoryId)) {
            throw new IllegalArgumentException("DataSerializableFactory with factoryId '" + factoryId + "' is already registered!");
        }
        dataSerializableFactories.put(factoryId, factory);
    }
}
Also used : DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with DataSerializableFactory

use of com.hazelcast.nio.serialization.DataSerializableFactory in project hazelcast by hazelcast.

the class DefaultSerializationServiceBuilder method addConfigDataSerializableFactories.

private void addConfigDataSerializableFactories(Map<Integer, DataSerializableFactory> dataSerializableFactories, SerializationConfig config, ClassLoader cl) {
    registerDataSerializableFactories(dataSerializableFactories, config);
    buildDataSerializableFactories(dataSerializableFactories, config, cl);
    for (DataSerializableFactory f : dataSerializableFactories.values()) {
        if (f instanceof HazelcastInstanceAware) {
            ((HazelcastInstanceAware) f).setHazelcastInstance(hazelcastInstance);
        }
    }
}
Also used : DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 5 with DataSerializableFactory

use of com.hazelcast.nio.serialization.DataSerializableFactory in project hazelcast by hazelcast.

the class ClientAuthenticationTest method testAuthenticationWithCustomCredentials_when_singleNode.

@Test
public void testAuthenticationWithCustomCredentials_when_singleNode() {
    DataSerializableFactory factory = new CustomCredentialsIdentifiedFactory();
    // with this config, the server will authenticate any credential of type CustomCredentials
    Config config = new Config();
    config.getSerializationConfig().addDataSerializableFactory(1, factory);
    hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSecurityConfig().setCredentials(new CustomCredentials());
    // custom credentials are not supported when security is disabled on members
    expectedException.expect(IllegalStateException.class);
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(1000);
    hazelcastFactory.newHazelcastClient(clientConfig);
}
Also used : DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DataSerializableFactory (com.hazelcast.nio.serialization.DataSerializableFactory)10 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 DataSerializerHook (com.hazelcast.internal.serialization.DataSerializerHook)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 Map (java.util.Map)2 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 Config (com.hazelcast.config.Config)1 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 SerializerConfig (com.hazelcast.config.SerializerConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 AbstractLockOperation (com.hazelcast.internal.locksupport.operations.AbstractLockOperation)1 MapEventJournalSubscribeOperation (com.hazelcast.map.impl.journal.MapEventJournalSubscribeOperation)1 AwaitMapFlushOperation (com.hazelcast.map.impl.operation.AwaitMapFlushOperation)1