Search in sources :

Example 16 with ConstructorFunction

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);
}
Also used : IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) DeployClassesOperation(com.hazelcast.internal.usercodedeployment.impl.operation.DeployClassesOperation) ClassDataFinderOperation(com.hazelcast.internal.usercodedeployment.impl.operation.ClassDataFinderOperation) ArrayDataSerializableFactory(com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction)

Example 17 with ConstructorFunction

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));
}
Also used : VersionAwareConstructorFunction(com.hazelcast.internal.util.VersionAwareConstructorFunction) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) VersionAwareConstructorFunction(com.hazelcast.internal.util.VersionAwareConstructorFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with ConstructorFunction

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);
}
Also used : VersionAwareConstructorFunction(com.hazelcast.internal.util.VersionAwareConstructorFunction) MemberVersion(com.hazelcast.version.MemberVersion) Version(com.hazelcast.version.Version) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) VersionAwareConstructorFunction(com.hazelcast.internal.util.VersionAwareConstructorFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with ConstructorFunction

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));
    }
}
Also used : EntryEventType(com.hazelcast.core.EntryEventType) Map(java.util.Map) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with ConstructorFunction

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);
}
Also used : EnumConstructor(com.hazelcast.test.starter.constructor.EnumConstructor) ConstructorFunction(com.hazelcast.internal.util.ConstructorFunction)

Aggregations

ConstructorFunction (com.hazelcast.internal.util.ConstructorFunction)20 ArrayDataSerializableFactory (com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory)16 IdentifiedDataSerializable (com.hazelcast.nio.serialization.IdentifiedDataSerializable)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 VersionAwareConstructorFunction (com.hazelcast.internal.util.VersionAwareConstructorFunction)2 MemberVersion (com.hazelcast.version.MemberVersion)2 Version (com.hazelcast.version.Version)2 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)1 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)1 CacheEventJournalSubscribeOperation (com.hazelcast.cache.impl.journal.CacheEventJournalSubscribeOperation)1 InternalEventJournalCacheEvent (com.hazelcast.cache.impl.journal.InternalEventJournalCacheEvent)1 DefaultCacheEntryView (com.hazelcast.cache.impl.merge.entry.DefaultCacheEntryView)1 AddCacheConfigOperation (com.hazelcast.cache.impl.operation.AddCacheConfigOperation)1 CacheBackupEntryProcessorOperation (com.hazelcast.cache.impl.operation.CacheBackupEntryProcessorOperation)1 CacheClearBackupOperation (com.hazelcast.cache.impl.operation.CacheClearBackupOperation)1 CacheClearOperation (com.hazelcast.cache.impl.operation.CacheClearOperation)1 CacheClearOperationFactory (com.hazelcast.cache.impl.operation.CacheClearOperationFactory)1 CacheContainsKeyOperation (com.hazelcast.cache.impl.operation.CacheContainsKeyOperation)1