Search in sources :

Example 1 with CLIENT

use of com.hazelcast.instance.EndpointQualifier.CLIENT in project hazelcast by hazelcast.

the class ClusterViewListenerService method getPartitions.

/**
 * If any partition does not have an owner, this method returns empty collection
 *
 * @param partitionTableView will be converted to address->partitions mapping
 * @return address->partitions mapping, where address is the client address of the member
 */
public Map<UUID, List<Integer>> getPartitions(PartitionTableView partitionTableView) {
    Map<UUID, List<Integer>> partitionsMap = new HashMap<>();
    int partitionCount = partitionTableView.length();
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        PartitionReplica owner = partitionTableView.getReplica(partitionId, 0);
        if (owner == null || owner.uuid() == null) {
            partitionsMap.clear();
            return partitionsMap;
        }
        partitionsMap.computeIfAbsent(owner.uuid(), k -> new LinkedList<>()).add(partitionId);
    }
    return partitionsMap;
}
Also used : Address(com.hazelcast.cluster.Address) CancelledKeyException(java.nio.channels.CancelledKeyException) Member(com.hazelcast.cluster.Member) MembershipManager(com.hazelcast.internal.cluster.impl.MembershipManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) EmptyStatement(com.hazelcast.internal.util.EmptyStatement) ExecutionService(com.hazelcast.spi.impl.executionservice.ExecutionService) ArrayList(java.util.ArrayList) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) MembersView(com.hazelcast.internal.cluster.impl.MembersView) LinkedList(java.util.LinkedList) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CoalescingDelayedTrigger(com.hazelcast.internal.util.scheduler.CoalescingDelayedTrigger) NodeEngine(com.hazelcast.spi.impl.NodeEngine) Connection(com.hazelcast.internal.nio.Connection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientAddClusterViewListenerCodec(com.hazelcast.client.impl.protocol.codec.ClientAddClusterViewListenerCodec) UUID(java.util.UUID) TimeUnit(java.util.concurrent.TimeUnit) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Example 2 with CLIENT

use of com.hazelcast.instance.EndpointQualifier.CLIENT in project hazelcast by hazelcast.

the class HttpGetCommandProcessor method handleCluster.

/**
 * Sets the HTTP response to a string containing basic cluster information:
 * <ul>
 * <li>Member list</li>
 * <li>Client connection count</li>
 * <li>Connection count</li>
 * </ul>
 *
 * @param command the HTTP request
 */
private void handleCluster(HttpGetCommand command) {
    Node node = textCommandService.getNode();
    Server server = node.getServer();
    ClusterServiceImpl clusterService = node.getClusterService();
    JsonArray membersArray = new JsonArray();
    clusterService.getMembers().stream().map(m -> new JsonObject().add("address", m.getAddress().toString()).add("liteMember", m.isLiteMember()).add("localMember", m.localMember()).add("uuid", m.getUuid().toString()).add("memberVersion", m.getVersion().toString())).forEach(membersArray::add);
    ServerConnectionManager cm = server.getConnectionManager(CLIENT);
    int clientCount = cm == null ? 0 : cm.connectionCount(ServerConnection::isClient);
    JsonObject response = new JsonObject().add("members", membersArray).add("connectionCount", clientCount).add("allConnectionCount", server.connectionCount());
    prepareResponse(command, response);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Address(com.hazelcast.cluster.Address) LoggingServiceImpl(com.hazelcast.logging.impl.LoggingServiceImpl) ServerConnection(com.hazelcast.internal.server.ServerConnection) JsonArray(com.hazelcast.internal.json.JsonArray) Level(java.util.logging.Level) Json(com.hazelcast.internal.json.Json) ClusterService(com.hazelcast.internal.cluster.ClusterService) SC_500(com.hazelcast.internal.ascii.rest.HttpStatusCode.SC_500) CPGroup(com.hazelcast.cp.CPGroup) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) StringUtil.equalsIgnoreCase(com.hazelcast.internal.util.StringUtil.equalsIgnoreCase) CPSession(com.hazelcast.cp.session.CPSession) JsonObject(com.hazelcast.internal.json.JsonObject) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) CPGroupId(com.hazelcast.cp.CPGroupId) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) TextCommandService(com.hazelcast.internal.ascii.TextCommandService) StringUtil(com.hazelcast.internal.util.StringUtil) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) Collection(java.util.Collection) Server(com.hazelcast.internal.server.Server) NodeState(com.hazelcast.instance.impl.NodeState) MAP(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.MAP) Node(com.hazelcast.instance.impl.Node) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) CompletionStage(java.util.concurrent.CompletionStage) CPMember(com.hazelcast.cp.CPMember) ClusterState(com.hazelcast.cluster.ClusterState) CPSubsystem(com.hazelcast.cp.CPSubsystem) QUEUE(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.QUEUE) Server(com.hazelcast.internal.server.Server) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

Address (com.hazelcast.cluster.Address)2 CLIENT (com.hazelcast.instance.EndpointQualifier.CLIENT)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientAddClusterViewListenerCodec (com.hazelcast.client.impl.protocol.codec.ClientAddClusterViewListenerCodec)1 ClusterState (com.hazelcast.cluster.ClusterState)1 Member (com.hazelcast.cluster.Member)1 CPGroup (com.hazelcast.cp.CPGroup)1 CPGroupId (com.hazelcast.cp.CPGroupId)1 CPMember (com.hazelcast.cp.CPMember)1 CPSubsystem (com.hazelcast.cp.CPSubsystem)1 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)1 CPSession (com.hazelcast.cp.session.CPSession)1 Node (com.hazelcast.instance.impl.Node)1 NodeState (com.hazelcast.instance.impl.NodeState)1 TextCommandService (com.hazelcast.internal.ascii.TextCommandService)1 SC_500 (com.hazelcast.internal.ascii.rest.HttpStatusCode.SC_500)1 MAP (com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.MAP)1 QUEUE (com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.QUEUE)1