use of com.hazelcast.internal.util.ConstructorFunction in project hazelcast by hazelcast.
the class UserCodeDeploymentSerializerHook method createFactory.
@Override
public DataSerializableFactory createFactory() {
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructors = new ConstructorFunction[LEN];
constructors[CLASS_DATA] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {
@Override
public IdentifiedDataSerializable createNew(Integer arg) {
return new ClassData();
}
};
constructors[CLASS_DATA_FINDER_OP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {
@Override
public IdentifiedDataSerializable createNew(Integer arg) {
return new ClassDataFinderOperation();
}
};
constructors[DEPLOY_CLASSES_OP] = new ConstructorFunction<Integer, IdentifiedDataSerializable>() {
@Override
public IdentifiedDataSerializable createNew(Integer arg) {
return new DeployClassesOperation();
}
};
return new ArrayDataSerializableFactory(constructors);
}
use of com.hazelcast.internal.util.ConstructorFunction in project hazelcast by hazelcast.
the class ArrayDataSerializableFactoryTest method testCreateWithoutVersion.
@Test
public void testCreateWithoutVersion() {
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructorFunctions = new ConstructorFunction[1];
VersionAwareConstructorFunction function = mock(VersionAwareConstructorFunction.class);
constructorFunctions[0] = function;
ArrayDataSerializableFactory factory = new ArrayDataSerializableFactory(constructorFunctions);
factory.create(0);
verify(function, times(1)).createNew(0);
verify(function, times(0)).createNew(eq(0), any(Version.class), any(Version.class));
}
use of com.hazelcast.internal.util.ConstructorFunction in project hazelcast by hazelcast.
the class ArrayDataSerializableFactoryTest method testCreateWithVersion.
@Test
public void testCreateWithVersion() throws Exception {
ConstructorFunction<Integer, IdentifiedDataSerializable>[] constructorFunctions = new ConstructorFunction[1];
VersionAwareConstructorFunction function = mock(VersionAwareConstructorFunction.class);
constructorFunctions[0] = function;
ArrayDataSerializableFactory factory = new ArrayDataSerializableFactory(constructorFunctions);
Version version = MemberVersion.of(3, 6, 0).asVersion();
Version wanProtocolVersion = MemberVersion.of(1, 0, 0).asVersion();
factory.create(0, version, wanProtocolVersion);
verify(function, times(0)).createNew(0);
verify(function, times(1)).createNew(0, version, wanProtocolVersion);
}
use of com.hazelcast.internal.util.ConstructorFunction in project hazelcast by hazelcast.
the class MapListenerAdapterTest method ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation.
@Test
public void ensure_map_listener_adapter_implements_listeners_for_all_entry_event_types_except_invalidation() {
MapListenerAdapter mapListenerAdapterInstance = new MapListenerAdapter();
Map<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> constructors = getConstructors();
for (Map.Entry<EntryEventType, ConstructorFunction<MapListener, ListenerAdapter>> entry : constructors.entrySet()) {
EntryEventType entryEventType = entry.getKey();
if (entryEventType == EntryEventType.INVALIDATION) {
// this event is used to listen near-cache invalidations.
continue;
}
assertNotNull("MapListenerAdapter misses an interface " + "to implement for entry-event-type=" + entryEventType, entry.getValue().createNew(mapListenerAdapterInstance));
}
}
use of com.hazelcast.internal.util.ConstructorFunction in project hazelcast by hazelcast.
the class HazelcastProxyFactory method construct.
private static Object construct(Class<?> clazz, Object delegate) {
ConstructorFunction<Object, Object> constructorFunction = CONSTRUCTORS.applyIfAbsent(clazz, input -> {
String className = input.getName();
Constructor<ConstructorFunction<Object, Object>> constructor = NO_PROXYING_WHITELIST.get(className);
if (constructor != null) {
try {
return constructor.newInstance(input);
} catch (Exception e) {
throw new IllegalStateException(e);
}
} else if (input.isEnum()) {
return new EnumConstructor(input);
}
throw new UnsupportedOperationException("Cannot construct target object for target " + input + " on classloader " + input.getClassLoader());
});
return constructorFunction.createNew(delegate);
}
Aggregations