Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.helix.model;
  
  /*
   * 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;
 
A resource contains a set of partitions and its replicas are managed by a state model
 
 public class Resource {
   private final String _resourceName;
   private final Map<StringPartition_partitionMap;
   private String _stateModelDefRef;
   private int _bucketSize = 0;
   private boolean _batchMessageMode = false;

  
Instantiate a resource by its name

Parameters:
resourceName the name of the resource that identifies it
 
   public Resource(String resourceName) {
     this. = resourceName;
     this. = new LinkedHashMap<StringPartition>();
   }

  
Get the state model definition managing this resource

Returns:
a reference to the state model definition
 
   public String getStateModelDefRef() {
     return ;
   }

  
Set the state model definition managing this resource

Parameters:
stateModelDefRef a reference to the state model definition
 
   public void setStateModelDefRef(String stateModelDefRef) {
      = stateModelDefRef;
   }

  
Set the state model factory for this resource

Parameters:
factoryName the name of the state model factory
 
   public void setStateModelFactoryName(String factoryName) {
     if (factoryName == null) {
     } else {
        = factoryName;
     }
   }

  
Get the state model factory for this resource

Returns:
the state model factory name
 
     return ;
   }

  
Get the resource name

Returns:
the name of the resource, should be unique
 
   public String getResourceName() {
     return ;
   }

  
Get the partitions of this resource

Returns:
Partition objects
 
   public Collection<PartitiongetPartitions() {
     return .values();
   }

  
Add a partition to this resource

Parameters:
partitionName the name of the partition
  public void addPartition(String partitionName) {
    .put(partitionNamenew Partition(partitionName));
  }

  
Get a resource partition by name

Parameters:
partitionName partition name
Returns:
the partition, or the name is not present
  public Partition getPartition(String partitionName) {
    return .get(partitionName);
  }

  
Get the bucket size of this resource

Returns:
the bucket size, or 0 if not specified
  public int getBucketSize() {
    return ;
  }

  
Set the bucket size of this resource

Parameters:
bucketSize the bucket size, or 0 to disable bucketizing
  public void setBucketSize(int bucketSize) {
     = bucketSize;
  }

  
Set whether or not messages for this resource should be batch processed

Parameters:
mode true to batch process, false to disable batch processing
  public void setBatchMessageMode(boolean mode) {
     = mode;
  }

  
Get the batch message processing mode

Returns:
true if enabled, false if disabled
  public boolean getBatchMessageMode() {
    return ;
  }
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("resourceName:").append();
    sb.append(", stateModelDef:").append();
    sb.append(", bucketSize:").append();
    sb.append(", partitionStateMap:").append();
    return sb.toString();
  }
New to GrepCode? Check out our FAQ X