View Javadoc

1   package org.apache.helix;
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.List;
23  import java.util.Map;
24  
25  import org.I0Itec.zkclient.DataUpdater;
26  
27  /**
28   * Interface used to interact with Helix Data Types like IdealState, Config,
29   * LiveInstance, Message, ExternalView etc PropertyKey represent the HelixData
30   * type. See {@link PropertyKey.Builder} to get more information on building a propertyKey.
31   * 
32   * 
33   */
34  public interface HelixDataAccessor
35  {
36    /**
37     * Create a helix property only if it does not exist.
38     * 
39     * @param key
40     * @param value
41     * @return true if creation was successful. False if already exists or if it
42     *         failed to create
43     */
44  
45    <T extends HelixProperty> boolean createProperty(PropertyKey key, T value);
46  
47    /**
48     * Set a property, overwrite if it exists and creates if not exists. This api
49     * assumes the node exists and only tries to update it only if the call fail
50     * it will create the node. So there is a performance cost if always ends up
51     * creating the node.
52     * 
53     * @param key
54     * @param value
55     * @true if the operation was successful
56     */
57    <T extends HelixProperty> boolean setProperty(PropertyKey key, T value);
58  
59    /**
60     * Updates a property using newvalue.merge(oldvalue)
61     * 
62     * @param key
63     * @param value
64     * @return true if the update was successful
65     */
66    <T extends HelixProperty> boolean updateProperty(PropertyKey key, T value);
67  
68    /**
69     * Return the property value, it must be refer to a single Helix Property. i.e
70     * PropertyKey.isLeaf() must return true.
71     * 
72     * @param key
73     * @return value, Null if absent or on error
74     */
75    <T extends HelixProperty> T getProperty(PropertyKey key);
76  
77    /**
78     * Return a list of property values, each of which must be refer to a single Helix
79     * Property. Property may be bucketized.
80     * 
81     * @param keys
82     * @return
83     */
84    public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys);
85  
86    /**
87     * Removes the property
88     * 
89     * @param key
90     * @return true if removal was successful or node does not exist. false if the
91     *         node existed and failed to remove it
92     */
93    boolean removeProperty(PropertyKey key);
94  
95    /**
96     * Return the child names for a property. PropertyKey needs to refer to a
97     * collection like instances, resources. PropertyKey.isLeaf must be false
98     * 
99     * @param key
100    * @return SubPropertyNames
101    */
102   List<String> getChildNames(PropertyKey key);
103 
104   /**
105    * Get the child values for a property. PropertyKey needs to refer to just one
106    * level above the non leaf. PropertyKey.isCollection must be true.
107    * 
108    * @param key
109    * @return subPropertyValues
110    */
111   <T extends HelixProperty> List<T> getChildValues(PropertyKey key);
112 
113   /**
114    * Same as getChildValues except that it converts list into a map using the id
115    * of the HelixProperty
116    * 
117    * @param key
118    * @return
119    */
120 
121   <T extends HelixProperty> Map<String, T> getChildValuesMap(PropertyKey key);
122 
123   /**
124    * Adds multiple children to a parent.
125    * 
126    * @param keys
127    * @param children
128    * @return
129    */
130   <T extends HelixProperty> boolean[] createChildren(List<PropertyKey> keys,
131       List<T> children);
132 
133   /**
134    * Sets multiple children under one parent
135    * 
136    * @param keys
137    * @param children
138    */
139   <T extends HelixProperty> boolean[] setChildren(List<PropertyKey> keys, List<T> children);
140   
141   /**
142    * Updates multiple children under one parent
143    * TODO: change to use property-keys instead of paths
144    * 
145    * @param paths
146    * @param updaters
147    */
148   <T extends HelixProperty> boolean[] updateChildren(List<String> paths,
149       List<DataUpdater<ZNRecord>> updaters,
150       int options);
151   
152   /**
153    * Get key builder for the accessor
154    * 
155    * @return
156    */
157   PropertyKey.Builder keyBuilder();
158 
159   /**
160    * Get underlying base data accessor
161    * 
162    * @return
163    */
164   BaseDataAccessor<ZNRecord> getBaseDataAccessor();
165 }