Search in sources :

Example 21 with Address

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

the class MigrationInfo method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    uuid = in.readUTF();
    partitionId = in.readInt();
    sourceCurrentReplicaIndex = in.readByte();
    sourceNewReplicaIndex = in.readByte();
    destinationCurrentReplicaIndex = in.readByte();
    destinationNewReplicaIndex = in.readByte();
    status = MigrationStatus.readFrom(in);
    boolean hasSource = in.readBoolean();
    if (hasSource) {
        source = new Address();
        source.readData(in);
        sourceUuid = in.readUTF();
    }
    boolean hasDestination = in.readBoolean();
    if (hasDestination) {
        destination = new Address();
        destination.readData(in);
        destinationUuid = in.readUTF();
    }
    master = new Address();
    master.readData(in);
}
Also used : Address(com.hazelcast.nio.Address)

Example 22 with Address

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

the class PartitionRuntimeState method writeData.

@SuppressWarnings("checkstyle:npathcomplexity")
@Override
public void writeData(ObjectDataOutput out) throws IOException {
    out.writeInt(version);
    if (addressToIndexes == null) {
        out.writeInt(addresses.length);
        for (int index = 0; index < addresses.length; index++) {
            Address address = addresses[index];
            address.writeData(out);
            out.writeInt(index);
        }
    } else {
        int memberCount = addressToIndexes.size();
        out.writeInt(memberCount);
        for (Map.Entry<Address, Integer> entry : addressToIndexes.entrySet()) {
            Address address = entry.getKey();
            address.writeData(out);
            int index = entry.getValue();
            out.writeInt(index);
        }
    }
    out.writeInt(minimizedPartitionTable.length);
    for (int[] indexes : minimizedPartitionTable) {
        for (int ix = 0; ix < MAX_REPLICA_COUNT; ix++) {
            out.writeInt(indexes[ix]);
        }
    }
    if (activeMigration != null) {
        out.writeBoolean(true);
        activeMigration.writeData(out);
    } else {
        out.writeBoolean(false);
    }
    if (completedMigrations != null) {
        int k = completedMigrations.size();
        out.writeInt(k);
        for (MigrationInfo migrationInfo : completedMigrations) {
            migrationInfo.writeData(out);
        }
    } else {
        out.writeInt(0);
    }
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with Address

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

the class PartitionRuntimeState method getPartitionTable.

public Address[][] getPartitionTable() {
    if (addresses == null) {
        addresses = new Address[addressToIndexes.size()];
        for (Map.Entry<Address, Integer> entry : addressToIndexes.entrySet()) {
            addresses[entry.getValue()] = entry.getKey();
        }
    }
    int length = minimizedPartitionTable.length;
    Address[][] result = new Address[length][MAX_REPLICA_COUNT];
    for (int partitionId = 0; partitionId < length; partitionId++) {
        Address[] replicas = result[partitionId];
        int[] addressIndexes = minimizedPartitionTable[partitionId];
        for (int replicaIndex = 0; replicaIndex < addressIndexes.length; replicaIndex++) {
            int index = addressIndexes[replicaIndex];
            if (index != -1) {
                Address address = addresses[index];
                assert address != null;
                replicas[replicaIndex] = address;
            }
        }
    }
    return result;
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with Address

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

the class PartitionRuntimeState method createAddressToIndexMap.

private Map<Address, Integer> createAddressToIndexMap(InternalPartition[] partitions) {
    Map<Address, Integer> map = new HashMap<Address, Integer>();
    int addressIndex = 0;
    for (InternalPartition partition : partitions) {
        for (int i = 0; i < MAX_REPLICA_COUNT; i++) {
            Address address = partition.getReplicaAddress(i);
            if (address == null) {
                continue;
            }
            if (map.containsKey(address)) {
                continue;
            }
            map.put(address, addressIndex++);
        }
    }
    return map;
}
Also used : Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap)

Example 25 with Address

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

the class PartitionTableView method writeData.

public static void writeData(PartitionTableView table, ObjectDataOutput out) throws IOException {
    Address[][] addresses = table.addresses;
    out.writeInt(addresses.length);
    for (Address[] a : addresses) {
        for (int j = 0; j < MAX_REPLICA_COUNT; j++) {
            Address address = a[j];
            boolean addressExists = address != null;
            out.writeBoolean(addressExists);
            if (addressExists) {
                address.writeData(out);
            }
        }
    }
    out.writeInt(table.version);
}
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