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 org.apache.helix.HelixProperty;
23  import org.apache.helix.ZNRecord;
24  import org.apache.log4j.Logger;
25  
26  
27  /**
28   * Instance that connects to zookeeper
29   */
30  public class LiveInstance extends HelixProperty
31  {
32    public enum LiveInstanceProperty
33    {
34      SESSION_ID,
35      HELIX_VERSION,
36      LIVE_INSTANCE,
37      ZKPROPERTYTRANSFERURL
38    }
39  
40    private static final Logger _logger = Logger.getLogger(LiveInstance.class.getName());
41  
42    public LiveInstance(String id)
43    {
44      super(id);
45    }
46  
47    public LiveInstance(ZNRecord record)
48    {
49      super(record);
50    }
51  
52    public void setSessionId(String sessionId)
53    {
54      _record.setSimpleField(LiveInstanceProperty.SESSION_ID.toString(), sessionId);
55    }
56  
57    public String getSessionId()
58    {
59      return _record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString());
60    }
61  
62    public String getInstanceName()
63    {
64      return _record.getId();
65    }
66  
67    public String getHelixVersion()
68    {
69      return _record.getSimpleField(LiveInstanceProperty.HELIX_VERSION.toString());
70    }
71  
72    public void setHelixVersion(String helixVersion)
73    {
74      _record.setSimpleField(LiveInstanceProperty.HELIX_VERSION.toString(), helixVersion);
75    }
76  
77    public String getLiveInstance()
78    {
79      return _record.getSimpleField(LiveInstanceProperty.LIVE_INSTANCE.toString());
80    }
81  
82    public void setLiveInstance(String leader)
83    {
84      _record.setSimpleField(LiveInstanceProperty.LIVE_INSTANCE.toString(), leader);
85    }
86  
87    public long getModifiedTime()
88    {
89      return _record.getModifiedTime();
90    }
91    
92    public String getWebserviceUrl()
93    {
94      return _record.getSimpleField(LiveInstanceProperty.ZKPROPERTYTRANSFERURL.toString());
95    }
96    
97    public void setWebserviceUrl(String url)
98    {
99      _record.setSimpleField(LiveInstanceProperty.ZKPROPERTYTRANSFERURL.toString(), url);
100   }
101   @Override
102   public boolean isValid()
103   {
104     if(getSessionId() == null)
105     {
106       _logger.error("liveInstance does not have session id. id:" + _record.getId());
107       return false;
108     }
109     if(getHelixVersion() == null)
110     {
111       _logger.error("liveInstance does not have CLM verion. id:" + _record.getId());
112       return false;
113     }
114     return true;
115   }
116 }