Search in sources :

Example 66 with Address

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

the class ReplicatedMapSplitBrainHandlerService method prepareMergeRunnable.

@Override
public Runnable prepareMergeRunnable() {
    HashMap<String, Collection<ReplicatedRecord>> recordMap = new HashMap<String, Collection<ReplicatedRecord>>();
    Address thisAddress = service.getNodeEngine().getThisAddress();
    List<Integer> partitions = nodeEngine.getPartitionService().getMemberPartitions(thisAddress);
    for (Integer partition : partitions) {
        PartitionContainer partitionContainer = service.getPartitionContainer(partition);
        ConcurrentMap<String, ReplicatedRecordStore> stores = partitionContainer.getStores();
        for (ReplicatedRecordStore store : stores.values()) {
            String name = store.getName();
            Collection<ReplicatedRecord> records = recordMap.get(name);
            if (records == null) {
                records = new ArrayList<ReplicatedRecord>();
            }
            Iterator<ReplicatedRecord> iterator = store.recordIterator();
            while (iterator.hasNext()) {
                ReplicatedRecord record = iterator.next();
                records.add(record);
            }
            recordMap.put(name, records);
            store.reset();
        }
    }
    return new Merger(recordMap);
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) ReplicatedRecordStore(com.hazelcast.replicatedmap.impl.record.ReplicatedRecordStore) Collection(java.util.Collection)

Example 67 with Address

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

the class InboundResponseHandler method handle.

@Override
public void handle(Packet packet) throws Exception {
    Response response = serializationService.toObject(packet);
    Address sender = packet.getConn().getEndPoint();
    try {
        if (response instanceof NormalResponse) {
            NormalResponse normalResponse = (NormalResponse) response;
            notifyNormalResponse(normalResponse.getCallId(), normalResponse.getValue(), normalResponse.getBackupAcks(), sender);
        } else if (response instanceof BackupAckResponse) {
            notifyBackupComplete(response.getCallId());
        } else if (response instanceof CallTimeoutResponse) {
            notifyCallTimeout(response.getCallId(), sender);
        } else if (response instanceof ErrorResponse) {
            ErrorResponse errorResponse = (ErrorResponse) response;
            notifyErrorResponse(errorResponse.getCallId(), errorResponse.getCause(), sender);
        } else {
            logger.severe("Unrecognized response: " + response);
        }
    } catch (Throwable e) {
        logger.severe("While processing response...", e);
    }
}
Also used : CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Response(com.hazelcast.spi.impl.operationservice.impl.responses.Response) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) Address(com.hazelcast.nio.Address) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 68 with Address

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

the class Invocation method toString.

@Override
public String toString() {
    String connectionStr = null;
    Address invTarget = this.invTarget;
    if (invTarget != null) {
        ConnectionManager connectionManager = context.connectionManager;
        Connection connection = connectionManager.getConnection(invTarget);
        connectionStr = connection == null ? null : connection.toString();
    }
    return "Invocation{" + "op=" + op + ", tryCount=" + tryCount + ", tryPauseMillis=" + tryPauseMillis + ", invokeCount=" + invokeCount + ", callTimeoutMillis=" + callTimeoutMillis + ", firstInvocationTimeMs=" + firstInvocationTimeMillis + ", firstInvocationTime='" + timeToString(firstInvocationTimeMillis) + '\'' + ", lastHeartbeatMillis=" + lastHeartbeatMillis + ", lastHeartbeatTime='" + timeToString(lastHeartbeatMillis) + '\'' + ", target=" + invTarget + ", pendingResponse={" + pendingResponse + '}' + ", backupsAcksExpected=" + backupsAcksExpected + ", backupsAcksReceived=" + backupsAcksReceived + ", connection=" + connectionStr + '}';
}
Also used : ConnectionManager(com.hazelcast.nio.ConnectionManager) Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) Connection(com.hazelcast.nio.Connection) StringUtil.timeToString(com.hazelcast.util.StringUtil.timeToString)

Example 69 with Address

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

the class OperationServiceImpl method invokeOnPartitions.

@Override
public Map<Integer, Object> invokeOnPartitions(String serviceName, OperationFactory operationFactory, Collection<Integer> partitions) throws Exception {
    Map<Address, List<Integer>> memberPartitions = new HashMap<Address, List<Integer>>(3);
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    for (int partition : partitions) {
        Address owner = partitionService.getPartitionOwnerOrWait(partition);
        if (!memberPartitions.containsKey(owner)) {
            memberPartitions.put(owner, new ArrayList<Integer>());
        }
        memberPartitions.get(owner).add(partition);
    }
    InvokeOnPartitions invokeOnPartitions = new InvokeOnPartitions(this, serviceName, operationFactory, memberPartitions);
    return invokeOnPartitions.invoke();
}
Also used : Address(com.hazelcast.nio.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) List(java.util.List) ArrayList(java.util.ArrayList) CollectionUtil.toIntegerList(com.hazelcast.util.CollectionUtil.toIntegerList)

Example 70 with Address

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

the class Registration method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    id = in.readUTF();
    serviceName = in.readUTF();
    topic = in.readUTF();
    subscriber = new Address();
    subscriber.readData(in);
    filter = in.readObject();
}
Also used : Address(com.hazelcast.nio.Address)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13