use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class PortableHookLoader method load.
private void load() {
try {
final Iterator<PortableHook> hooks = ServiceLoader.iterator(PortableHook.class, FACTORY_ID, classLoader);
while (hooks.hasNext()) {
PortableHook hook = hooks.next();
final PortableFactory factory = hook.createFactory();
if (factory != null) {
register(hook.getFactoryId(), factory);
}
final Collection<ClassDefinition> defs = hook.getBuiltinDefinitions();
if (defs != null && !defs.isEmpty()) {
definitions.addAll(defs);
}
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
if (configuredFactories != null) {
for (Map.Entry<Integer, ? extends PortableFactory> entry : configuredFactories.entrySet()) {
register(entry.getKey(), entry.getValue());
}
}
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method addConfigPortableFactories.
private void addConfigPortableFactories(final Map<Integer, PortableFactory> portableFactories, SerializationConfig config, ClassLoader cl) {
registerPortableFactories(portableFactories, config);
buildPortableFactories(portableFactories, config, cl);
for (PortableFactory f : portableFactories.values()) {
if (f instanceof HazelcastInstanceAware) {
((HazelcastInstanceAware) f).setHazelcastInstance(hazelcastInstance);
}
}
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class DefaultSerializationServiceBuilder method registerPortableFactories.
private void registerPortableFactories(Map<Integer, PortableFactory> portableFactories, SerializationConfig config) {
for (Map.Entry<Integer, PortableFactory> entry : config.getPortableFactories().entrySet()) {
int factoryId = entry.getKey();
PortableFactory factory = entry.getValue();
if (factoryId <= 0) {
throw new IllegalArgumentException("PortableFactory factoryId must be positive! -> " + factory);
}
if (portableFactories.containsKey(factoryId)) {
throw new IllegalArgumentException("PortableFactory with factoryId '" + factoryId + "' is already registered!");
}
portableFactories.put(factoryId, factory);
}
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class MapPortableHookTest method testPortableFactory_whenCreatingUnregisteredConstructor_thenThrowException.
@Test(expected = IndexOutOfBoundsException.class)
public void testPortableFactory_whenCreatingUnregisteredConstructor_thenThrowException() {
MapPortableHook hook = new MapPortableHook();
PortableFactory factory = hook.createFactory();
factory.create(-1);
}
use of com.hazelcast.nio.serialization.PortableFactory in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testClientPortableWithoutRegisteringToNode.
@Test
public void testClientPortableWithoutRegisteringToNode() {
hazelcastFactory.newHazelcastInstance();
final SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(5, new PortableFactory() {
public Portable create(int classId) {
return new SamplePortable();
}
});
final ClientConfig clientConfig = new ClientConfig();
clientConfig.setSerializationConfig(serializationConfig);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final IMap<Integer, SamplePortable> sampleMap = client.getMap(randomString());
sampleMap.put(1, new SamplePortable(666));
final SamplePortable samplePortable = sampleMap.get(1);
assertEquals(666, samplePortable.a);
}
Aggregations