Search in sources :

Example 1 with PartitionLostEvent

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

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

the class PartitionEventManager method onPartitionLost.

public void onPartitionLost(IPartitionLostEvent event) {
    assert event instanceof PartitionLostEvent;
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, PARTITION_LOST_EVENT_TOPIC);
    eventService.publishEvent(SERVICE_NAME, registrations, event, event.getPartitionId());
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) IPartitionLostEvent(com.hazelcast.internal.partition.IPartitionLostEvent) PartitionLostEvent(com.hazelcast.partition.PartitionLostEvent) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

PartitionLostEvent (com.hazelcast.partition.PartitionLostEvent)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 IPartitionLostEvent (com.hazelcast.internal.partition.IPartitionLostEvent)1 PartitionLostListener (com.hazelcast.partition.PartitionLostListener)1 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)1 EventService (com.hazelcast.spi.impl.eventservice.EventService)1 IPartitionService (com.hazelcast.spi.partition.IPartitionService)1