Search in sources :

Example 11 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class CollectionEvent method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    name = in.readString();
    eventType = ItemEventType.getByType(in.readInt());
    caller = new Address();
    caller.readData(in);
    data = IOUtil.readData(in);
}
Also used : Address(com.hazelcast.cluster.Address)

Example 12 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class AbstractMember method getSocketAddress.

@Override
public InetSocketAddress getSocketAddress(EndpointQualifier qualifier) {
    Address addr = addressMap.get(qualifier);
    if (addr == null && !qualifier.getType().equals(ProtocolType.MEMBER)) {
        addr = addressMap.get(MEMBER);
    }
    checkNotNull(addr);
    try {
        return addr.getInetSocketAddress();
    } catch (UnknownHostException e) {
        if (getLogger() != null) {
            getLogger().warning(e);
        }
        return null;
    }
}
Also used : Address(com.hazelcast.cluster.Address) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Example 13 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class ExecutorServiceProxy method submitToMember.

private <T> void submitToMember(@Nonnull Data taskData, @Nonnull Member member, @Nullable ExecutionCallback<T> callback) {
    checkNotNull(member, "member must not be null");
    checkNotShutdown();
    NodeEngine nodeEngine = getNodeEngine();
    UUID uuid = newUnsecureUUID();
    MemberCallableTaskOperation op = new MemberCallableTaskOperation(name, uuid, taskData);
    OperationService operationService = nodeEngine.getOperationService();
    Address address = member.getAddress();
    InvocationFuture<T> future = operationService.createInvocationBuilder(DistributedExecutorService.SERVICE_NAME, op, address).invoke();
    if (callback != null) {
        future.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        });
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 14 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class ClusterJoinManager method checkIfUsingAnExistingMemberUuid.

private boolean checkIfUsingAnExistingMemberUuid(JoinMessage joinMessage) {
    Member member = clusterService.getMember(joinMessage.getUuid());
    Address target = joinMessage.getAddress();
    if (member != null && !member.getAddress().equals(joinMessage.getAddress())) {
        if (clusterService.isMaster() && !isMastershipClaimInProgress()) {
            String message = "There's already an existing member " + member + " with the same UUID. " + target + " is not allowed to join.";
            logger.warning(message);
        } else {
            sendMasterAnswer(target);
        }
        return true;
    }
    return false;
}
Also used : Address(com.hazelcast.cluster.Address) Member(com.hazelcast.cluster.Member)

Example 15 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class ClusterJoinManager method handleMasterResponse.

/**
 * Set master address, if required.
 *
 * @param masterAddress address of cluster's master, as provided in {@link MasterResponseOp}
 * @param callerAddress address of node that sent the {@link MasterResponseOp}
 * @see MasterResponseOp
 */
public void handleMasterResponse(Address masterAddress, Address callerAddress) {
    clusterServiceLock.lock();
    try {
        if (logger.isFineEnabled()) {
            logger.fine(format("Handling master response %s from %s", masterAddress, callerAddress));
        }
        if (clusterService.isJoined()) {
            if (logger.isFineEnabled()) {
                logger.fine(format("Ignoring master response %s from %s, this node is already joined", masterAddress, callerAddress));
            }
            return;
        }
        if (node.getThisAddress().equals(masterAddress)) {
            logger.warning("Received my address as master address from " + callerAddress);
            return;
        }
        Address currentMaster = clusterService.getMasterAddress();
        if (currentMaster == null || currentMaster.equals(masterAddress)) {
            setMasterAndJoin(masterAddress);
            return;
        }
        if (currentMaster.equals(callerAddress)) {
            logger.warning(format("Setting master to %s since %s says it is not master anymore", masterAddress, currentMaster));
            setMasterAndJoin(masterAddress);
            return;
        }
        Connection conn = node.getServer().getConnectionManager(MEMBER).get(currentMaster);
        if (conn != null && conn.isAlive()) {
            logger.info(format("Ignoring master response %s from %s since this node has an active master %s", masterAddress, callerAddress, currentMaster));
            sendJoinRequest(currentMaster);
        } else {
            logger.warning(format("Ambiguous master response! Received master response %s from %s. " + "This node has a master %s, but does not have an active connection to it. " + "Master field will be unset now.", masterAddress, callerAddress, currentMaster));
            clusterService.setMasterAddress(null);
        }
    } finally {
        clusterServiceLock.unlock();
    }
}
Also used : Address(com.hazelcast.cluster.Address) ServerConnection(com.hazelcast.internal.server.ServerConnection) Connection(com.hazelcast.internal.nio.Connection)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32