Search in sources :

Example 11 with HazelcastInstanceAware

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

the class RunnableAdapter method setHazelcastInstance.

@Override
public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
    if (task instanceof HazelcastInstanceAware) {
        HazelcastInstanceAware instanceAwareTask = (HazelcastInstanceAware) task;
        instanceAwareTask.setHazelcastInstance(hazelcastInstance);
    }
}
Also used : HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 12 with HazelcastInstanceAware

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

the class HazelcastManagedContext method initialize.

@Override
public Object initialize(Object obj) {
    if (obj instanceof HazelcastInstanceAware) {
        HazelcastInstanceAware hazelcastInstanceAware = (HazelcastInstanceAware) obj;
        hazelcastInstanceAware.setHazelcastInstance(instance);
    }
    if (obj instanceof NodeAware) {
        NodeAware nodeAware = (NodeAware) obj;
        nodeAware.setNode(instance.node);
    }
    if (hasExternalContext) {
        return externalContext.initialize(obj);
    }
    return obj;
}
Also used : HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) NodeAware(com.hazelcast.spi.NodeAware)

Example 13 with HazelcastInstanceAware

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

the class Node method initializeListeners.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
private void initializeListeners(Config config) {
    for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
        Object listener = listenerCfg.getImplementation();
        if (listener == null) {
            try {
                listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
            } catch (Exception e) {
                logger.severe(e);
            }
        }
        if (listener instanceof HazelcastInstanceAware) {
            ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
        }
        boolean known = false;
        if (listener instanceof DistributedObjectListener) {
            final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
            proxyService.addProxyListener((DistributedObjectListener) listener);
            known = true;
        }
        if (listener instanceof MembershipListener) {
            clusterService.addMembershipListener((MembershipListener) listener);
            known = true;
        }
        if (listener instanceof MigrationListener) {
            partitionService.addMigrationListener((MigrationListener) listener);
            known = true;
        }
        if (listener instanceof PartitionLostListener) {
            partitionService.addPartitionLostListener((PartitionLostListener) listener);
            known = true;
        }
        if (listener instanceof LifecycleListener) {
            hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
            known = true;
        }
        if (listener instanceof ClientListener) {
            String serviceName = ClientEngineImpl.SERVICE_NAME;
            nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
            known = true;
        }
        if (listener instanceof InternalMigrationListener) {
            final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
            partitionService.setInternalMigrationListener((InternalMigrationListener) listener);
            known = true;
        }
        if (nodeExtension.registerListener(listener)) {
            known = true;
        }
        if (listener != null && !known) {
            final String error = "Unknown listener type: " + listener.getClass();
            Throwable t = new IllegalArgumentException(error);
            logger.warning(error, t);
        }
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener) LifecycleListener(com.hazelcast.core.LifecycleListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) ClientListener(com.hazelcast.core.ClientListener) ListenerConfig(com.hazelcast.config.ListenerConfig) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) MembershipListener(com.hazelcast.core.MembershipListener) MigrationListener(com.hazelcast.core.MigrationListener) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener)

Example 14 with HazelcastInstanceAware

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

the class ObjectMultiMapProxy method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    List<EntryListenerConfig> listenerConfigs = config.getEntryListenerConfigs();
    for (EntryListenerConfig listenerConfig : listenerConfigs) {
        EntryListener listener = null;
        if (listenerConfig.getImplementation() != null) {
            listener = listenerConfig.getImplementation();
        } else if (listenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), listenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            if (listenerConfig.isLocal()) {
                addLocalEntryListener(listener);
            } else {
                addEntryListener(listener, listenerConfig.isIncludeValue());
            }
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EntryListener(com.hazelcast.core.EntryListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) HazelcastException(com.hazelcast.core.HazelcastException)

Example 15 with HazelcastInstanceAware

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

the class AbstractCollectionProxyImpl method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    CollectionConfig config = getConfig(nodeEngine);
    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) CollectionConfig(com.hazelcast.config.CollectionConfig) 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