Search in sources :

Example 1 with HazelcastInstanceAware

use of com.hazelcast.core.HazelcastInstanceAware in project hazelcast by hazelcast.

the class QueueProxySupport method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
    for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
        ItemListener listener = itemListenerConfig.getImplementation();
        if (listener == null && itemListenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            addItemListener(listener, itemListenerConfig.isIncludeValue());
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListener(com.hazelcast.core.ItemListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 2 with HazelcastInstanceAware

use of com.hazelcast.core.HazelcastInstanceAware in project hazelcast by hazelcast.

the class DefaultNodeExtension method registerListener.

@Override
public boolean registerListener(Object listener) {
    if (listener instanceof HazelcastInstanceAware) {
        ((HazelcastInstanceAware) listener).setHazelcastInstance(node.hazelcastInstance);
    }
    if (listener instanceof ClusterVersionListener) {
        ClusterVersionListener clusterVersionListener = (ClusterVersionListener) listener;
        clusterVersionListeners.add(clusterVersionListener);
        // on registration, invoke once the listening method so version is properly initialized on the listener
        clusterVersionListener.onClusterVersionChange(getClusterOrNodeVersion());
        return true;
    }
    return false;
}
Also used : HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener)

Example 3 with HazelcastInstanceAware

use of com.hazelcast.core.HazelcastInstanceAware 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 4 with HazelcastInstanceAware

use of com.hazelcast.core.HazelcastInstanceAware in project hazelcast by hazelcast.

the class DefaultSerializationServiceBuilder method build.

@Override
public InternalSerializationService build() {
    initVersions();
    if (config != null) {
        addConfigDataSerializableFactories(dataSerializableFactories, config, classLoader);
        addConfigPortableFactories(portableFactories, config, classLoader);
        classDefinitions.addAll(config.getClassDefinitions());
    }
    InputOutputFactory inputOutputFactory = createInputOutputFactory();
    InternalSerializationService ss = createSerializationService(inputOutputFactory);
    registerSerializerHooks(ss);
    if (config != null) {
        if (config.getGlobalSerializerConfig() != null) {
            GlobalSerializerConfig globalSerializerConfig = config.getGlobalSerializerConfig();
            Serializer serializer = globalSerializerConfig.getImplementation();
            if (serializer == null) {
                try {
                    serializer = ClassLoaderUtil.newInstance(classLoader, globalSerializerConfig.getClassName());
                } catch (Exception e) {
                    throw new HazelcastSerializationException(e);
                }
            }
            if (serializer instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) serializer).setHazelcastInstance(hazelcastInstance);
            }
            ((AbstractSerializationService) ss).registerGlobal(serializer, globalSerializerConfig.isOverrideJavaSerialization());
        }
    }
    return ss;
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) InputOutputFactory(com.hazelcast.internal.serialization.InputOutputFactory) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 5 with HazelcastInstanceAware

use of com.hazelcast.core.HazelcastInstanceAware in project hazelcast by hazelcast.

the class EntryBackupOperation method innerBeforeRun.

@Override
public void innerBeforeRun() throws Exception {
    super.innerBeforeRun();
    if (entryProcessor instanceof HazelcastInstanceAware) {
        HazelcastInstance hazelcastInstance = getNodeEngine().getHazelcastInstance();
        ((HazelcastInstanceAware) entryProcessor).setHazelcastInstance(hazelcastInstance);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Aggregations

HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)16 NodeEngine (com.hazelcast.spi.NodeEngine)6 ItemListenerConfig (com.hazelcast.config.ItemListenerConfig)2 ItemListener (com.hazelcast.core.ItemListener)2 MessageListener (com.hazelcast.core.MessageListener)2 Serializer (com.hazelcast.nio.serialization.Serializer)2 CollectionConfig (com.hazelcast.config.CollectionConfig)1 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 ClientListener (com.hazelcast.core.ClientListener)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 EntryListener (com.hazelcast.core.EntryListener)1 HazelcastException (com.hazelcast.core.HazelcastException)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 Member (com.hazelcast.core.Member)1 MembershipListener (com.hazelcast.core.MembershipListener)1 MigrationListener (com.hazelcast.core.MigrationListener)1 ClusterVersionListener (com.hazelcast.internal.cluster.ClusterVersionListener)1