Search in sources :

Example 1 with MigrationAwareService

use of com.hazelcast.spi.MigrationAwareService in project hazelcast by hazelcast.

the class MigrationRequestOperation method prepareMigrationOperations.

private Collection<Operation> prepareMigrationOperations() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    PartitionReplicationEvent replicationEvent = new PartitionReplicationEvent(migrationInfo.getPartitionId(), migrationInfo.getDestinationNewReplicaIndex());
    Collection<Operation> tasks = new LinkedList<Operation>();
    for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(MigrationAwareService.class)) {
        MigrationAwareService service = (MigrationAwareService) serviceInfo.getService();
        Operation op = service.prepareReplicationOperation(replicationEvent);
        if (op != null) {
            op.setServiceName(serviceInfo.getName());
            tasks.add(op);
        }
    }
    return tasks;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) MigrationAwareService(com.hazelcast.spi.MigrationAwareService) Operation(com.hazelcast.spi.Operation) PartitionReplicationEvent(com.hazelcast.spi.PartitionReplicationEvent) LinkedList(java.util.LinkedList)

Example 2 with MigrationAwareService

use of com.hazelcast.spi.MigrationAwareService in project hazelcast by hazelcast.

the class BaseMigrationOperation method executeBeforeMigrations.

void executeBeforeMigrations() throws Exception {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    PartitionMigrationEvent event = getMigrationEvent();
    Throwable t = null;
    for (MigrationAwareService service : nodeEngine.getServices(MigrationAwareService.class)) {
        // we need to make sure all beforeMigration() methods are executed
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            getLogger().warning("Error while executing beforeMigration()", e);
            t = e;
        }
    }
    if (t != null) {
        throw ExceptionUtil.rethrow(t);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService)

Example 3 with MigrationAwareService

use of com.hazelcast.spi.MigrationAwareService in project hazelcast by hazelcast.

the class BeforePromotionOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("Running before promotion for " + getPartitionMigrationEvent());
    }
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    for (MigrationAwareService service : getMigrationAwareServices()) {
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            logger.warning("While promoting " + getPartitionMigrationEvent(), e);
        }
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService) ILogger(com.hazelcast.logging.ILogger)

Example 4 with MigrationAwareService

use of com.hazelcast.spi.MigrationAwareService in project hazelcast by hazelcast.

the class FinalizeMigrationOperation method notifyServices.

private void notifyServices(NodeEngineImpl nodeEngine) {
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    Collection<MigrationAwareService> migrationAwareServices = nodeEngine.getServices(MigrationAwareService.class);
    // knows replica is moved away from itself.
    if (nodeEngine.getThisAddress().equals(migrationInfo.getSource()) && migrationInfo.getSourceCurrentReplicaIndex() > 0) {
        // execute beforeMigration on old backup before commit/rollback
        for (MigrationAwareService service : migrationAwareServices) {
            beforeMigration(event, service);
        }
    }
    for (MigrationAwareService service : migrationAwareServices) {
        finishMigration(event, service);
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService)

Example 5 with MigrationAwareService

use of com.hazelcast.spi.MigrationAwareService in project hazelcast by hazelcast.

the class ReplicaSyncRequest method createReplicationOperations.

private List<Operation> createReplicationOperations() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    Collection<ServiceInfo> services = nodeEngine.getServiceInfos(MigrationAwareService.class);
    PartitionReplicationEvent event = new PartitionReplicationEvent(getPartitionId(), getReplicaIndex());
    List<Operation> tasks = new LinkedList<Operation>();
    for (ServiceInfo serviceInfo : services) {
        MigrationAwareService service = (MigrationAwareService) serviceInfo.getService();
        Operation op = service.prepareReplicationOperation(event);
        if (op != null) {
            op.setServiceName(serviceInfo.getName());
            tasks.add(op);
        }
    }
    return tasks;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) MigrationAwareService(com.hazelcast.spi.MigrationAwareService) PartitionAwareOperation(com.hazelcast.spi.PartitionAwareOperation) MigrationCycleOperation(com.hazelcast.internal.partition.MigrationCycleOperation) Operation(com.hazelcast.spi.Operation) PartitionReplicationEvent(com.hazelcast.spi.PartitionReplicationEvent) LinkedList(java.util.LinkedList)

Aggregations

MigrationAwareService (com.hazelcast.spi.MigrationAwareService)5 PartitionMigrationEvent (com.hazelcast.spi.PartitionMigrationEvent)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 Operation (com.hazelcast.spi.Operation)2 PartitionReplicationEvent (com.hazelcast.spi.PartitionReplicationEvent)2 ServiceInfo (com.hazelcast.spi.impl.servicemanager.ServiceInfo)2 LinkedList (java.util.LinkedList)2 MigrationCycleOperation (com.hazelcast.internal.partition.MigrationCycleOperation)1 ILogger (com.hazelcast.logging.ILogger)1 PartitionAwareOperation (com.hazelcast.spi.PartitionAwareOperation)1