Search in sources :

Example 11 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class KeyValueJob method invoke.

@Override
protected <T> JobCompletableFuture<T> invoke(Collator collator) {
    ClusterService clusterService = nodeEngine.getClusterService();
    if (clusterService.getSize(MemberSelectors.DATA_MEMBER_SELECTOR) == 0) {
        throw new IllegalStateException("Could not register map reduce job since there are no nodes owning a partition");
    }
    String jobId = UuidUtil.newUnsecureUuidString();
    AbstractJobTracker jobTracker = (AbstractJobTracker) this.jobTracker;
    TrackableJobFuture<T> jobFuture = new TrackableJobFuture<T>(name, jobId, jobTracker, nodeEngine, collator);
    if (jobTracker.registerTrackableJob(jobFuture)) {
        return startSupervisionTask(jobFuture, jobId);
    }
    throw new IllegalStateException("Could not register map reduce job");
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) AbstractJobTracker(com.hazelcast.mapreduce.impl.AbstractJobTracker)

Example 12 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TopicService method dispatchEvent.

@Override
public void dispatchEvent(Object event, Object listener) {
    TopicEvent topicEvent = (TopicEvent) event;
    ClusterService clusterService = nodeEngine.getClusterService();
    MemberImpl member = clusterService.getMember(topicEvent.publisherAddress);
    if (member == null) {
        member = new MemberImpl(topicEvent.publisherAddress, nodeEngine.getVersion(), false);
    }
    Message message = new DataAwareMessage(topicEvent.name, topicEvent.data, topicEvent.publishTime, member, nodeEngine.getSerializationService());
    incrementReceivedMessages(topicEvent.name);
    MessageListener messageListener = (MessageListener) listener;
    messageListener.onMessage(message);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Message(com.hazelcast.core.Message) MemberImpl(com.hazelcast.instance.MemberImpl) MessageListener(com.hazelcast.core.MessageListener)

Example 13 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TransactionImpl method rollbackBackupLogs.

private void rollbackBackupLogs() {
    if (!backupLogsCreated) {
        return;
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    List<Future> futures = new ArrayList<Future>(backupAddresses.length);
    for (Address backupAddress : backupAddresses) {
        if (clusterService.getMember(backupAddress) != null) {
            Future f = operationService.invokeOnTarget(SERVICE_NAME, createRollbackTxBackupLogOperation(), backupAddress);
            futures.add(f);
        }
    }
    waitWithDeadline(futures, timeoutMillis, MILLISECONDS, rollbackTxExceptionHandler);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.nio.Address) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Example 14 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TransactionImpl method replicateTxnLog.

private void replicateTxnLog() throws InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
    if (skipBackupLogReplication()) {
        return;
    }
    OperationService operationService = nodeEngine.getOperationService();
    ClusterService clusterService = nodeEngine.getClusterService();
    List<Future> futures = new ArrayList<Future>(backupAddresses.length);
    for (Address backupAddress : backupAddresses) {
        if (clusterService.getMember(backupAddress) != null) {
            Operation op = createReplicateTxBackupLogOperation();
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, backupAddress);
            futures.add(f);
        }
    }
    waitWithDeadline(futures, timeoutMillis, MILLISECONDS, replicationTxExceptionHandler);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.nio.Address) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) PurgeTxBackupLogOperation(com.hazelcast.transaction.impl.operations.PurgeTxBackupLogOperation) ReplicateTxBackupLogOperation(com.hazelcast.transaction.impl.operations.ReplicateTxBackupLogOperation) RollbackTxBackupLogOperation(com.hazelcast.transaction.impl.operations.RollbackTxBackupLogOperation) CreateTxBackupLogOperation(com.hazelcast.transaction.impl.operations.CreateTxBackupLogOperation) Operation(com.hazelcast.spi.Operation)

Example 15 with ClusterService

use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.

the class TransactionManagerServiceImpl method pickBackupLogAddresses.

Address[] pickBackupLogAddresses(int durability) {
    if (durability == 0) {
        return EMPTY_ADDRESSES;
    }
    // This should be cleaned up because this is quite a complex approach since it depends on
    // the number of members in the cluster and creates litter.
    ClusterService clusterService = nodeEngine.getClusterService();
    List<MemberImpl> members = new ArrayList<MemberImpl>(clusterService.getMemberImpls());
    members.remove(nodeEngine.getLocalMember());
    int c = Math.min(members.size(), durability);
    shuffle(members);
    Address[] addresses = new Address[c];
    for (int i = 0; i < c; i++) {
        addresses[i] = members.get(i).getAddress();
    }
    return addresses;
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Address(com.hazelcast.nio.Address) MemberImpl(com.hazelcast.instance.MemberImpl) ArrayList(java.util.ArrayList)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)32 Member (com.hazelcast.core.Member)8 ArrayList (java.util.ArrayList)8 Node (com.hazelcast.instance.Node)7 Address (com.hazelcast.nio.Address)7 OperationService (com.hazelcast.spi.OperationService)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)5 Future (java.util.concurrent.Future)5 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 ILogger (com.hazelcast.logging.ILogger)3 Operation (com.hazelcast.spi.Operation)3 GroupConfig (com.hazelcast.config.GroupConfig)2 JobTrackerConfig (com.hazelcast.config.JobTrackerConfig)2 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 MapReduceService (com.hazelcast.mapreduce.impl.MapReduceService)2 MapReduceUtil.executeOperation (com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation)2 KeyValueJobOperation (com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation)2 StartProcessingJobOperation (com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation)2