Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.helix.controller.stages;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.util.Map;
 import java.util.Set;
 
 
 
 public class ResourceCurrentState {
  
map of resource-id to map of partition-id to map of participant-id to state represent current-state for the participant
 
   private final Map<ResourceIdMap<PartitionIdMap<ParticipantIdState>>> _currentStateMap;

  
map of resource-id to map of partition-id to map of participant-id to state represent pending messages for the participant
 
   private final Map<ResourceIdMap<PartitionIdMap<ParticipantIdState>>> _pendingStateMap;

  
map of resource-id to state model definition id
 
map of resource-id to current-state config's
 
   private final Map<ResourceIdCurrentState_curStateMetaMap;

  
construct
 
   public ResourceCurrentState() {
 
   }

  
Get all the resources seen in the aggregated current state

Returns:
set of ResourceId
 
   public Set<ResourceIdgetResourceIds() {
     Set<ResourceIdallResources = Sets.newHashSet();
     allResources.addAll(.keySet());
     allResources.addAll(.keySet());
     return allResources;
   }

  

Parameters:
resourceId
stateModelDefId
 
   public void setResourceStateModelDef(ResourceId resourceIdStateModelDefId stateModelDefId) {
     .put(resourceIdstateModelDefId);
   }

  

Parameters:
resourceId
Returns:
 
     return .get(resourceId);
   }

  

Parameters:
resourceId
bucketSize
  public void setBucketSize(ResourceId resourceIdint bucketSize) {
    CurrentState curStateMeta = .get(resourceId);
    if (curStateMeta == null) {
      curStateMeta = new CurrentState(resourceId);
      .put(resourceIdcurStateMeta);
    }
    curStateMeta.setBucketSize(bucketSize);
  }

  

Parameters:
resourceId
Returns:
  public int getBucketSize(ResourceId resourceId) {
    int bucketSize = 0;
    CurrentState curStateMeta = .get(resourceId);
    if (curStateMeta != null) {
      bucketSize = curStateMeta.getBucketSize();
    }
    return bucketSize;
  }

  

Parameters:
stateMap
resourceId
partitionId
participantId
state
  static void setStateMap(Map<ResourceIdMap<PartitionIdMap<ParticipantIdState>>> stateMap,
      ResourceId resourceIdPartitionId partitionIdParticipantId participantIdState state) {
    if (!stateMap.containsKey(resourceId)) {
      stateMap.put(resourceIdnew HashMap<PartitionIdMap<ParticipantIdState>>());
    }
    if (!stateMap.get(resourceId).containsKey(partitionId)) {
      stateMap.get(resourceId).put(partitionIdnew HashMap<ParticipantIdState>());
    }
    stateMap.get(resourceId).get(partitionId).put(participantIdstate);
  }

  

Parameters:
stateMap
resourceId
partitionId
participantId
Returns:
state
      ResourceId resourceIdPartitionId partitionIdParticipantId participantId) {
    Map<PartitionIdMap<ParticipantIdState>> map = stateMap.get(resourceId);
    if (map != null) {
      Map<ParticipantIdStateinstanceStateMap = map.get(partitionId);
      if (instanceStateMap != null) {
        return instanceStateMap.get(participantId);
      }
    }
    return null;
  }

  

Parameters:
stateMap
resourceId
partitionId
Returns:
      Map<ResourceIdMap<PartitionIdMap<ParticipantIdState>>> stateMapResourceId resourceId,
      PartitionId partitionId) {
    if (stateMap.containsKey(resourceId)) {
      Map<PartitionIdMap<ParticipantIdState>> map = stateMap.get(resourceId);
      if (map.containsKey(partitionId)) {
        return map.get(partitionId);
      }
    }
    return Collections.emptyMap();
  }

  

Parameters:
resourceId
partitionId
participantId
state
  public void setCurrentState(ResourceId resourceIdPartitionId partitionId,
      ParticipantId participantIdState state) {
    setStateMap(resourceIdpartitionIdparticipantIdstate);
  }

  

Parameters:
resourceId
partitionId
participantId
state
  public void setPendingState(ResourceId resourceIdPartitionId partitionId,
      ParticipantId participantIdState state) {
    setStateMap(resourceIdpartitionIdparticipantIdstate);
  }

  
given (resource, partition, instance), returns currentState

Parameters:
resourceName
partition
instanceName
Returns:
  public State getCurrentState(ResourceId resourceIdPartitionId partitionId,
      ParticipantId participantId) {
    return getState(resourceIdpartitionIdparticipantId);
  }

  
given (resource, partition, instance), returns toState

Parameters:
resourceName
partition
instanceName
Returns:
  public State getPendingState(ResourceId resourceIdPartitionId partitionId,
      ParticipantId participantId) {
    return getState(resourceIdpartitionIdparticipantId);
  }

  

Parameters:
resourceId
partitionId
Returns:
  public Map<ParticipantIdStategetCurrentStateMap(ResourceId resourceIdPartitionId partitionId) {
    return getStateMap(resourceIdpartitionId);
  }

  
Get the partitions mapped in the current state

Parameters:
resourceId resource to look up
Returns:
set of mapped partitions, or empty set if there are none
    Map<PartitionIdMap<ParticipantIdState>> currentStateMap = .get(resourceId);
    Map<PartitionIdMap<ParticipantIdState>> pendingStateMap = .get(resourceId);
    Set<PartitionIdpartitionSet = Sets.newHashSet();
    if (currentStateMap != null) {
      partitionSet.addAll(currentStateMap.keySet());
    }
    if (pendingStateMap != null) {
      partitionSet.addAll(pendingStateMap.keySet());
    }
    return partitionSet;
  }

  

Parameters:
resourceId
partitionId
Returns:
  public Map<ParticipantIdStategetPendingStateMap(ResourceId resourceIdPartitionId partitionId) {
    return getStateMap(resourceIdpartitionId);
  }
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("current state= ").append();
    sb.append(", pending state= ").append();
    return sb.toString();
  }
New to GrepCode? Check out our FAQ X