View Javadoc

1   package org.apache.helix.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collection;
23  import java.util.LinkedHashMap;
24  import java.util.Map;
25  
26  import org.apache.helix.HelixConstants;
27  import org.apache.log4j.Logger;
28  
29  
30  /**
31   * A resource contains a set of partitions
32   */
33  public class Resource
34  {
35    private static Logger LOG = Logger.getLogger(Resource.class);
36  
37    private final String _resourceName;
38    private final Map<String, Partition> _partitionMap;
39    private String _stateModelDefRef;
40    private String _stateModelFactoryName;
41    private int _bucketSize = 0;
42    private boolean _batchMessageMode = false;
43  
44    public Resource(String resourceName)
45    {
46      this._resourceName = resourceName;
47      this._partitionMap = new LinkedHashMap<String, Partition>();
48    }
49  
50    public String getStateModelDefRef()
51    {
52      return _stateModelDefRef;
53    }
54  
55    public void setStateModelDefRef(String stateModelDefRef)
56    {
57      _stateModelDefRef = stateModelDefRef;
58    }
59  
60    public void setStateModelFactoryName(String factoryName)
61    {
62      if (factoryName == null)
63      {
64        _stateModelFactoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
65      } else
66      {
67        _stateModelFactoryName = factoryName;
68      }
69    }
70  
71    public String getStateModelFactoryname()
72    {
73      return _stateModelFactoryName;
74    }
75  
76    public String getResourceName()
77    {
78      return _resourceName;
79    }
80  
81    public Collection<Partition> getPartitions()
82    {
83      return _partitionMap.values();
84    }
85  
86    public void addPartition(String partitionName)
87    {
88      _partitionMap.put(partitionName, new Partition(partitionName));
89    }
90  
91    public Partition getPartition(String partitionName)
92    {
93      return _partitionMap.get(partitionName);
94    }
95  
96    public int getBucketSize()
97    {
98      return _bucketSize;
99    }
100   
101   public void setBucketSize(int bucketSize)
102   {
103     _bucketSize = bucketSize;
104   }
105 
106   public void setBatchMessageMode(boolean mode)
107   {
108     _batchMessageMode = mode;
109   }
110   
111   public boolean getBatchMessageMode()
112   {
113     return _batchMessageMode;
114   }
115   
116   @Override
117   public String toString()
118   {
119     StringBuilder sb = new StringBuilder();
120     sb.append("resourceName:").append(_resourceName);
121     sb.append(", stateModelDef:").append(_stateModelDefRef);
122     sb.append(", bucketSize:").append(_bucketSize);
123     sb.append(", partitionStateMap:").append(_partitionMap);
124 
125     return sb.toString();
126   }
127 }