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");
}
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);
}
}
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);
}
}
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);
}
}
}
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);
}
Aggregations