Search in sources :

Example 1 with PartitionLostListener

use of com.hazelcast.partition.PartitionLostListener in project hazelcast by hazelcast.

the class AddPartitionLostListenerMessageTask method call.

@Override
protected Object call() throws Exception {
    final IPartitionService partitionService = getService(getServiceName());
    final PartitionLostListener listener = new PartitionLostListener() {

        @Override
        public void partitionLost(PartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = ClientAddPartitionLostListenerCodec.encodePartitionLostEvent(event.getPartitionId(), event.getLostBackupCount(), event.getEventSource());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    String registrationId;
    if (parameters.localOnly) {
        registrationId = partitionService.addLocalPartitionLostListener(listener);
    } else {
        registrationId = partitionService.addPartitionLostListener(listener);
    }
    endpoint.addListenerDestroyAction(getServiceName(), PARTITION_LOST_EVENT_TOPIC, registrationId);
    return registrationId;
}
Also used : PartitionLostListener(com.hazelcast.partition.PartitionLostListener) IPartitionService(com.hazelcast.spi.partition.IPartitionService) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 2 with PartitionLostListener

use of com.hazelcast.partition.PartitionLostListener 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)

Aggregations

PartitionLostListener (com.hazelcast.partition.PartitionLostListener)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 ClientListener (com.hazelcast.core.ClientListener)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 MembershipListener (com.hazelcast.core.MembershipListener)1 MigrationListener (com.hazelcast.core.MigrationListener)1 InternalMigrationListener (com.hazelcast.internal.partition.impl.InternalMigrationListener)1 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)1 PartitionLostEvent (com.hazelcast.partition.PartitionLostEvent)1 ProxyServiceImpl (com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl)1 IPartitionService (com.hazelcast.spi.partition.IPartitionService)1