helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kisho...@apache.org
Subject svn commit: r1489023 [15/15] - in /incubator/helix/site-content: ./ apidocs/reference/org/apache/helix/ helix-admin-webapp/ helix-agent/ helix-core/ involved/ mockservice/ recipes/ recipes/distributed-lock-manager/ recipes/rabbitmq-consumer-group/ reci...
Date Mon, 03 Jun 2013 15:17:57 GMT
Modified: incubator/helix/site-content/xref/org/apache/helix/manager/zk/ZKHelixManager.html
URL: http://svn.apache.org/viewvc/incubator/helix/site-content/xref/org/apache/helix/manager/zk/ZKHelixManager.html?rev=1489023&r1=1489022&r2=1489023&view=diff
==============================================================================
--- incubator/helix/site-content/xref/org/apache/helix/manager/zk/ZKHelixManager.html (original)
+++ incubator/helix/site-content/xref/org/apache/helix/manager/zk/ZKHelixManager.html Mon Jun  3 15:17:52 2013
@@ -579,531 +579,527 @@
 <a class="jxr_linenumber" name="569" href="#569">569</a> 
 <a class="jxr_linenumber" name="570" href="#570">570</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> createClient(String zkServers) <strong class="jxr_keyword">throws</strong> Exception
 <a class="jxr_linenumber" name="571" href="#571">571</a>   {
-<a class="jxr_linenumber" name="572" href="#572">572</a>     String propertyStorePath =
-<a class="jxr_linenumber" name="573" href="#573">573</a>         PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, _clusterName);
-<a class="jxr_linenumber" name="574" href="#574">574</a> 
-<a class="jxr_linenumber" name="575" href="#575">575</a>     <em class="jxr_comment">// by default use ZNRecordStreamingSerializer except for paths within the property</em>
-<a class="jxr_linenumber" name="576" href="#576">576</a>     <em class="jxr_comment">// store which expects raw byte[] serialization/deserialization</em>
-<a class="jxr_linenumber" name="577" href="#577">577</a>     <a href="../../../../../org/apache/helix/manager/zk/PathBasedZkSerializer.html">PathBasedZkSerializer</a> zkSerializer =
-<a class="jxr_linenumber" name="578" href="#578">578</a>         ChainedPathZkSerializer.builder(<strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZNRecordStreamingSerializer.html">ZNRecordStreamingSerializer</a>())
-<a class="jxr_linenumber" name="579" href="#579">579</a>                                .serialize(propertyStorePath, <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ByteArraySerializer.html">ByteArraySerializer</a>())
-<a class="jxr_linenumber" name="580" href="#580">580</a>                                .build();
-<a class="jxr_linenumber" name="581" href="#581">581</a> 
-<a class="jxr_linenumber" name="582" href="#582">582</a>     _zkClient = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZkClient.html">ZkClient</a>(zkServers, _sessionTimeout, CONNECTIONTIMEOUT, zkSerializer);
-<a class="jxr_linenumber" name="583" href="#583">583</a> 
-<a class="jxr_linenumber" name="584" href="#584">584</a>     ZkBaseDataAccessor&lt;ZNRecord&gt; baseDataAccessor =
-<a class="jxr_linenumber" name="585" href="#585">585</a>         <strong class="jxr_keyword">new</strong> ZkBaseDataAccessor&lt;ZNRecord&gt;(_zkClient);
-<a class="jxr_linenumber" name="586" href="#586">586</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT)
-<a class="jxr_linenumber" name="587" href="#587">587</a>     {
-<a class="jxr_linenumber" name="588" href="#588">588</a>       String curStatePath =
-<a class="jxr_linenumber" name="589" href="#589">589</a>           PropertyPathConfig.getPath(PropertyType.CURRENTSTATES,
-<a class="jxr_linenumber" name="590" href="#590">590</a>                                      _clusterName,
-<a class="jxr_linenumber" name="591" href="#591">591</a>                                      _instanceName);
-<a class="jxr_linenumber" name="592" href="#592">592</a>       _baseDataAccessor =
-<a class="jxr_linenumber" name="593" href="#593">593</a>           <strong class="jxr_keyword">new</strong> ZkCacheBaseDataAccessor&lt;ZNRecord&gt;(baseDataAccessor,
-<a class="jxr_linenumber" name="594" href="#594">594</a>                                                 Arrays.asList(curStatePath));
-<a class="jxr_linenumber" name="595" href="#595">595</a>     }
-<a class="jxr_linenumber" name="596" href="#596">596</a>     <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.CONTROLLER)
-<a class="jxr_linenumber" name="597" href="#597">597</a>     {
-<a class="jxr_linenumber" name="598" href="#598">598</a>       String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW,
-<a class="jxr_linenumber" name="599" href="#599">599</a> 
-<a class="jxr_linenumber" name="600" href="#600">600</a>       _clusterName);
-<a class="jxr_linenumber" name="601" href="#601">601</a>       _baseDataAccessor =
-<a class="jxr_linenumber" name="602" href="#602">602</a>           <strong class="jxr_keyword">new</strong> ZkCacheBaseDataAccessor&lt;ZNRecord&gt;(baseDataAccessor,
-<a class="jxr_linenumber" name="603" href="#603">603</a>                                                 Arrays.asList(extViewPath));
-<a class="jxr_linenumber" name="604" href="#604">604</a> 
+<a class="jxr_linenumber" name="572" href="#572">572</a>     <em class="jxr_comment">// by default use ZNRecordStreamingSerializer except for paths within the property</em>
+<a class="jxr_linenumber" name="573" href="#573">573</a>     <em class="jxr_comment">// store which expects raw byte[] serialization/deserialization</em>
+<a class="jxr_linenumber" name="574" href="#574">574</a>     <a href="../../../../../org/apache/helix/manager/zk/PathBasedZkSerializer.html">PathBasedZkSerializer</a> zkSerializer =
+<a class="jxr_linenumber" name="575" href="#575">575</a>         ChainedPathZkSerializer.builder(<strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZNRecordStreamingSerializer.html">ZNRecordStreamingSerializer</a>())
+<a class="jxr_linenumber" name="576" href="#576">576</a>                                .build();
+<a class="jxr_linenumber" name="577" href="#577">577</a> 
+<a class="jxr_linenumber" name="578" href="#578">578</a>     _zkClient = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZkClient.html">ZkClient</a>(zkServers, _sessionTimeout, CONNECTIONTIMEOUT, zkSerializer);
+<a class="jxr_linenumber" name="579" href="#579">579</a> 
+<a class="jxr_linenumber" name="580" href="#580">580</a>     ZkBaseDataAccessor&lt;ZNRecord&gt; baseDataAccessor =
+<a class="jxr_linenumber" name="581" href="#581">581</a>         <strong class="jxr_keyword">new</strong> ZkBaseDataAccessor&lt;ZNRecord&gt;(_zkClient);
+<a class="jxr_linenumber" name="582" href="#582">582</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT)
+<a class="jxr_linenumber" name="583" href="#583">583</a>     {
+<a class="jxr_linenumber" name="584" href="#584">584</a>       String curStatePath =
+<a class="jxr_linenumber" name="585" href="#585">585</a>           PropertyPathConfig.getPath(PropertyType.CURRENTSTATES,
+<a class="jxr_linenumber" name="586" href="#586">586</a>                                      _clusterName,
+<a class="jxr_linenumber" name="587" href="#587">587</a>                                      _instanceName);
+<a class="jxr_linenumber" name="588" href="#588">588</a>       _baseDataAccessor =
+<a class="jxr_linenumber" name="589" href="#589">589</a>           <strong class="jxr_keyword">new</strong> ZkCacheBaseDataAccessor&lt;ZNRecord&gt;(baseDataAccessor,
+<a class="jxr_linenumber" name="590" href="#590">590</a>                                                 Arrays.asList(curStatePath));
+<a class="jxr_linenumber" name="591" href="#591">591</a>     }
+<a class="jxr_linenumber" name="592" href="#592">592</a>     <strong class="jxr_keyword">else</strong> <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.CONTROLLER)
+<a class="jxr_linenumber" name="593" href="#593">593</a>     {
+<a class="jxr_linenumber" name="594" href="#594">594</a>       String extViewPath = PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW,
+<a class="jxr_linenumber" name="595" href="#595">595</a> 
+<a class="jxr_linenumber" name="596" href="#596">596</a>       _clusterName);
+<a class="jxr_linenumber" name="597" href="#597">597</a>       _baseDataAccessor =
+<a class="jxr_linenumber" name="598" href="#598">598</a>           <strong class="jxr_keyword">new</strong> ZkCacheBaseDataAccessor&lt;ZNRecord&gt;(baseDataAccessor,
+<a class="jxr_linenumber" name="599" href="#599">599</a>                                                 Arrays.asList(extViewPath));
+<a class="jxr_linenumber" name="600" href="#600">600</a> 
+<a class="jxr_linenumber" name="601" href="#601">601</a>     }
+<a class="jxr_linenumber" name="602" href="#602">602</a>     <strong class="jxr_keyword">else</strong>
+<a class="jxr_linenumber" name="603" href="#603">603</a>     {
+<a class="jxr_linenumber" name="604" href="#604">604</a>       _baseDataAccessor = baseDataAccessor;
 <a class="jxr_linenumber" name="605" href="#605">605</a>     }
-<a class="jxr_linenumber" name="606" href="#606">606</a>     <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="607" href="#607">607</a>     {
-<a class="jxr_linenumber" name="608" href="#608">608</a>       _baseDataAccessor = baseDataAccessor;
-<a class="jxr_linenumber" name="609" href="#609">609</a>     }
-<a class="jxr_linenumber" name="610" href="#610">610</a> 
-<a class="jxr_linenumber" name="611" href="#611">611</a>     _helixAccessor =
-<a class="jxr_linenumber" name="612" href="#612">612</a>         <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZKHelixDataAccessor.html">ZKHelixDataAccessor</a>(_clusterName, _instanceType, _baseDataAccessor);
-<a class="jxr_linenumber" name="613" href="#613">613</a>     _configAccessor = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/ConfigAccessor.html">ConfigAccessor</a>(_zkClient);
-<a class="jxr_linenumber" name="614" href="#614">614</a>     <strong class="jxr_keyword">int</strong> retryCount = 0;
-<a class="jxr_linenumber" name="615" href="#615">615</a> 
-<a class="jxr_linenumber" name="616" href="#616">616</a>     _zkClient.subscribeStateChanges(_zkStateChangeListener);
-<a class="jxr_linenumber" name="617" href="#617">617</a>     <strong class="jxr_keyword">while</strong> (retryCount &lt; RETRY_LIMIT)
-<a class="jxr_linenumber" name="618" href="#618">618</a>     {
-<a class="jxr_linenumber" name="619" href="#619">619</a>       <strong class="jxr_keyword">try</strong>
-<a class="jxr_linenumber" name="620" href="#620">620</a>       {
-<a class="jxr_linenumber" name="621" href="#621">621</a>         _zkClient.waitUntilConnected(_sessionTimeout, TimeUnit.MILLISECONDS);
-<a class="jxr_linenumber" name="622" href="#622">622</a>         _zkStateChangeListener.handleStateChanged(KeeperState.SyncConnected);
-<a class="jxr_linenumber" name="623" href="#623">623</a>         _zkStateChangeListener.handleNewSession();
-<a class="jxr_linenumber" name="624" href="#624">624</a>         <strong class="jxr_keyword">break</strong>;
-<a class="jxr_linenumber" name="625" href="#625">625</a>       }
-<a class="jxr_linenumber" name="626" href="#626">626</a>       <strong class="jxr_keyword">catch</strong> (HelixException e)
-<a class="jxr_linenumber" name="627" href="#627">627</a>       {
-<a class="jxr_linenumber" name="628" href="#628">628</a>         logger.error(<span class="jxr_string">"fail to createClient."</span>, e);
-<a class="jxr_linenumber" name="629" href="#629">629</a>         <strong class="jxr_keyword">throw</strong> e;
-<a class="jxr_linenumber" name="630" href="#630">630</a>       }
-<a class="jxr_linenumber" name="631" href="#631">631</a>       <strong class="jxr_keyword">catch</strong> (Exception e)
-<a class="jxr_linenumber" name="632" href="#632">632</a>       {
-<a class="jxr_linenumber" name="633" href="#633">633</a>         retryCount++;
-<a class="jxr_linenumber" name="634" href="#634">634</a> 
-<a class="jxr_linenumber" name="635" href="#635">635</a>         logger.error(<span class="jxr_string">"fail to createClient. retry "</span> + retryCount, e);
-<a class="jxr_linenumber" name="636" href="#636">636</a>         <strong class="jxr_keyword">if</strong> (retryCount == RETRY_LIMIT)
-<a class="jxr_linenumber" name="637" href="#637">637</a>         {
-<a class="jxr_linenumber" name="638" href="#638">638</a>           <strong class="jxr_keyword">throw</strong> e;
-<a class="jxr_linenumber" name="639" href="#639">639</a>         }
-<a class="jxr_linenumber" name="640" href="#640">640</a>       }
-<a class="jxr_linenumber" name="641" href="#641">641</a>     }
-<a class="jxr_linenumber" name="642" href="#642">642</a>   }
-<a class="jxr_linenumber" name="643" href="#643">643</a> 
-<a class="jxr_linenumber" name="644" href="#644">644</a>   <strong class="jxr_keyword">private</strong> <a href="../../../../../org/apache/helix/manager/zk/CallbackHandler.html">CallbackHandler</a> createCallBackHandler(<a href="../../../../../org/apache/helix/PropertyKey.html">PropertyKey</a> propertyKey,
-<a class="jxr_linenumber" name="645" href="#645">645</a>                                                 Object listener,
-<a class="jxr_linenumber" name="646" href="#646">646</a>                                                 EventType[] eventTypes,
-<a class="jxr_linenumber" name="647" href="#647">647</a>                                                 <a href="../../../../../org/apache/helix/HelixConstants.html">ChangeType</a> changeType)
-<a class="jxr_linenumber" name="648" href="#648">648</a>   {
-<a class="jxr_linenumber" name="649" href="#649">649</a>     <strong class="jxr_keyword">if</strong> (listener == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="650" href="#650">650</a>     {
-<a class="jxr_linenumber" name="651" href="#651">651</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Listener cannot be null"</span>);
-<a class="jxr_linenumber" name="652" href="#652">652</a>     }
-<a class="jxr_linenumber" name="653" href="#653">653</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/CallbackHandler.html">CallbackHandler</a>(<strong class="jxr_keyword">this</strong>, _zkClient, propertyKey, listener, eventTypes, changeType);
-<a class="jxr_linenumber" name="654" href="#654">654</a>   }
-<a class="jxr_linenumber" name="655" href="#655">655</a> 
-<a class="jxr_linenumber" name="656" href="#656">656</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="657" href="#657">657</a> <em class="jxr_javadoccomment">   * This will be invoked when ever a new session is created&lt;br/&gt;</em>
-<a class="jxr_linenumber" name="658" href="#658">658</a> <em class="jxr_javadoccomment">   * </em>
-<a class="jxr_linenumber" name="659" href="#659">659</a> <em class="jxr_javadoccomment">   * case 1: the cluster manager was a participant carry over current state, add live</em>
-<a class="jxr_linenumber" name="660" href="#660">660</a> <em class="jxr_javadoccomment">   * instance, and invoke message listener; case 2: the cluster manager was controller and</em>
-<a class="jxr_linenumber" name="661" href="#661">661</a> <em class="jxr_javadoccomment">   * was a leader before do leader election, and if it becomes leader again, invoke ideal</em>
-<a class="jxr_linenumber" name="662" href="#662">662</a> <em class="jxr_javadoccomment">   * state listener, current state listener, etc. if it fails to become leader in the new</em>
-<a class="jxr_linenumber" name="663" href="#663">663</a> <em class="jxr_javadoccomment">   * session, then becomes standby; case 3: the cluster manager was controller and was NOT</em>
-<a class="jxr_linenumber" name="664" href="#664">664</a> <em class="jxr_javadoccomment">   * a leader before do leader election, and if it becomes leader, instantiate and invoke</em>
-<a class="jxr_linenumber" name="665" href="#665">665</a> <em class="jxr_javadoccomment">   * ideal state listener, current state listener, etc. if if fails to become leader in</em>
-<a class="jxr_linenumber" name="666" href="#666">666</a> <em class="jxr_javadoccomment">   * the new session, stay as standby</em>
-<a class="jxr_linenumber" name="667" href="#667">667</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="668" href="#668">668</a> 
-<a class="jxr_linenumber" name="669" href="#669">669</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">void</strong> handleNewSession()
-<a class="jxr_linenumber" name="670" href="#670">670</a>   {
-<a class="jxr_linenumber" name="671" href="#671">671</a>     <strong class="jxr_keyword">boolean</strong> isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
-<a class="jxr_linenumber" name="672" href="#672">672</a>     <strong class="jxr_keyword">while</strong> (!isConnected)
-<a class="jxr_linenumber" name="673" href="#673">673</a>     {
-<a class="jxr_linenumber" name="674" href="#674">674</a>       logger.error(<span class="jxr_string">"Could NOT connect to zk server in "</span> + CONNECTIONTIMEOUT + <span class="jxr_string">"ms. zkServer: "</span>
-<a class="jxr_linenumber" name="675" href="#675">675</a>           + _zkConnectString + <span class="jxr_string">", expiredSessionId: "</span> + _sessionId + <span class="jxr_string">", clusterName: "</span>
-<a class="jxr_linenumber" name="676" href="#676">676</a>           + _clusterName);
-<a class="jxr_linenumber" name="677" href="#677">677</a>       isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
-<a class="jxr_linenumber" name="678" href="#678">678</a>     }
-<a class="jxr_linenumber" name="679" href="#679">679</a> 
-<a class="jxr_linenumber" name="680" href="#680">680</a>     ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection());
-<a class="jxr_linenumber" name="681" href="#681">681</a>     
-<a class="jxr_linenumber" name="682" href="#682">682</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
-<a class="jxr_linenumber" name="683" href="#683">683</a>     {
-<a class="jxr_linenumber" name="684" href="#684">684</a>       _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
-<a class="jxr_linenumber" name="685" href="#685">685</a>     }
-<a class="jxr_linenumber" name="686" href="#686">686</a>     _baseDataAccessor.reset();
+<a class="jxr_linenumber" name="606" href="#606">606</a> 
+<a class="jxr_linenumber" name="607" href="#607">607</a>     _helixAccessor =
+<a class="jxr_linenumber" name="608" href="#608">608</a>         <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/ZKHelixDataAccessor.html">ZKHelixDataAccessor</a>(_clusterName, _instanceType, _baseDataAccessor);
+<a class="jxr_linenumber" name="609" href="#609">609</a>     _configAccessor = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/ConfigAccessor.html">ConfigAccessor</a>(_zkClient);
+<a class="jxr_linenumber" name="610" href="#610">610</a>     <strong class="jxr_keyword">int</strong> retryCount = 0;
+<a class="jxr_linenumber" name="611" href="#611">611</a> 
+<a class="jxr_linenumber" name="612" href="#612">612</a>     _zkClient.subscribeStateChanges(_zkStateChangeListener);
+<a class="jxr_linenumber" name="613" href="#613">613</a>     <strong class="jxr_keyword">while</strong> (retryCount &lt; RETRY_LIMIT)
+<a class="jxr_linenumber" name="614" href="#614">614</a>     {
+<a class="jxr_linenumber" name="615" href="#615">615</a>       <strong class="jxr_keyword">try</strong>
+<a class="jxr_linenumber" name="616" href="#616">616</a>       {
+<a class="jxr_linenumber" name="617" href="#617">617</a>         _zkClient.waitUntilConnected(_sessionTimeout, TimeUnit.MILLISECONDS);
+<a class="jxr_linenumber" name="618" href="#618">618</a>         _zkStateChangeListener.handleStateChanged(KeeperState.SyncConnected);
+<a class="jxr_linenumber" name="619" href="#619">619</a>         _zkStateChangeListener.handleNewSession();
+<a class="jxr_linenumber" name="620" href="#620">620</a>         <strong class="jxr_keyword">break</strong>;
+<a class="jxr_linenumber" name="621" href="#621">621</a>       }
+<a class="jxr_linenumber" name="622" href="#622">622</a>       <strong class="jxr_keyword">catch</strong> (HelixException e)
+<a class="jxr_linenumber" name="623" href="#623">623</a>       {
+<a class="jxr_linenumber" name="624" href="#624">624</a>         logger.error(<span class="jxr_string">"fail to createClient."</span>, e);
+<a class="jxr_linenumber" name="625" href="#625">625</a>         <strong class="jxr_keyword">throw</strong> e;
+<a class="jxr_linenumber" name="626" href="#626">626</a>       }
+<a class="jxr_linenumber" name="627" href="#627">627</a>       <strong class="jxr_keyword">catch</strong> (Exception e)
+<a class="jxr_linenumber" name="628" href="#628">628</a>       {
+<a class="jxr_linenumber" name="629" href="#629">629</a>         retryCount++;
+<a class="jxr_linenumber" name="630" href="#630">630</a> 
+<a class="jxr_linenumber" name="631" href="#631">631</a>         logger.error(<span class="jxr_string">"fail to createClient. retry "</span> + retryCount, e);
+<a class="jxr_linenumber" name="632" href="#632">632</a>         <strong class="jxr_keyword">if</strong> (retryCount == RETRY_LIMIT)
+<a class="jxr_linenumber" name="633" href="#633">633</a>         {
+<a class="jxr_linenumber" name="634" href="#634">634</a>           <strong class="jxr_keyword">throw</strong> e;
+<a class="jxr_linenumber" name="635" href="#635">635</a>         }
+<a class="jxr_linenumber" name="636" href="#636">636</a>       }
+<a class="jxr_linenumber" name="637" href="#637">637</a>     }
+<a class="jxr_linenumber" name="638" href="#638">638</a>   }
+<a class="jxr_linenumber" name="639" href="#639">639</a> 
+<a class="jxr_linenumber" name="640" href="#640">640</a>   <strong class="jxr_keyword">private</strong> <a href="../../../../../org/apache/helix/manager/zk/CallbackHandler.html">CallbackHandler</a> createCallBackHandler(<a href="../../../../../org/apache/helix/PropertyKey.html">PropertyKey</a> propertyKey,
+<a class="jxr_linenumber" name="641" href="#641">641</a>                                                 Object listener,
+<a class="jxr_linenumber" name="642" href="#642">642</a>                                                 EventType[] eventTypes,
+<a class="jxr_linenumber" name="643" href="#643">643</a>                                                 <a href="../../../../../org/apache/helix/HelixConstants.html">ChangeType</a> changeType)
+<a class="jxr_linenumber" name="644" href="#644">644</a>   {
+<a class="jxr_linenumber" name="645" href="#645">645</a>     <strong class="jxr_keyword">if</strong> (listener == <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="646" href="#646">646</a>     {
+<a class="jxr_linenumber" name="647" href="#647">647</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Listener cannot be null"</span>);
+<a class="jxr_linenumber" name="648" href="#648">648</a>     }
+<a class="jxr_linenumber" name="649" href="#649">649</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/CallbackHandler.html">CallbackHandler</a>(<strong class="jxr_keyword">this</strong>, _zkClient, propertyKey, listener, eventTypes, changeType);
+<a class="jxr_linenumber" name="650" href="#650">650</a>   }
+<a class="jxr_linenumber" name="651" href="#651">651</a> 
+<a class="jxr_linenumber" name="652" href="#652">652</a>   <em class="jxr_javadoccomment">/**</em>
+<a class="jxr_linenumber" name="653" href="#653">653</a> <em class="jxr_javadoccomment">   * This will be invoked when ever a new session is created&lt;br/&gt;</em>
+<a class="jxr_linenumber" name="654" href="#654">654</a> <em class="jxr_javadoccomment">   * </em>
+<a class="jxr_linenumber" name="655" href="#655">655</a> <em class="jxr_javadoccomment">   * case 1: the cluster manager was a participant carry over current state, add live</em>
+<a class="jxr_linenumber" name="656" href="#656">656</a> <em class="jxr_javadoccomment">   * instance, and invoke message listener; case 2: the cluster manager was controller and</em>
+<a class="jxr_linenumber" name="657" href="#657">657</a> <em class="jxr_javadoccomment">   * was a leader before do leader election, and if it becomes leader again, invoke ideal</em>
+<a class="jxr_linenumber" name="658" href="#658">658</a> <em class="jxr_javadoccomment">   * state listener, current state listener, etc. if it fails to become leader in the new</em>
+<a class="jxr_linenumber" name="659" href="#659">659</a> <em class="jxr_javadoccomment">   * session, then becomes standby; case 3: the cluster manager was controller and was NOT</em>
+<a class="jxr_linenumber" name="660" href="#660">660</a> <em class="jxr_javadoccomment">   * a leader before do leader election, and if it becomes leader, instantiate and invoke</em>
+<a class="jxr_linenumber" name="661" href="#661">661</a> <em class="jxr_javadoccomment">   * ideal state listener, current state listener, etc. if if fails to become leader in</em>
+<a class="jxr_linenumber" name="662" href="#662">662</a> <em class="jxr_javadoccomment">   * the new session, stay as standby</em>
+<a class="jxr_linenumber" name="663" href="#663">663</a> <em class="jxr_javadoccomment">   */</em>
+<a class="jxr_linenumber" name="664" href="#664">664</a> 
+<a class="jxr_linenumber" name="665" href="#665">665</a>   <strong class="jxr_keyword">protected</strong> <strong class="jxr_keyword">void</strong> handleNewSession()
+<a class="jxr_linenumber" name="666" href="#666">666</a>   {
+<a class="jxr_linenumber" name="667" href="#667">667</a>     <strong class="jxr_keyword">boolean</strong> isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
+<a class="jxr_linenumber" name="668" href="#668">668</a>     <strong class="jxr_keyword">while</strong> (!isConnected)
+<a class="jxr_linenumber" name="669" href="#669">669</a>     {
+<a class="jxr_linenumber" name="670" href="#670">670</a>       logger.error(<span class="jxr_string">"Could NOT connect to zk server in "</span> + CONNECTIONTIMEOUT + <span class="jxr_string">"ms. zkServer: "</span>
+<a class="jxr_linenumber" name="671" href="#671">671</a>           + _zkConnectString + <span class="jxr_string">", expiredSessionId: "</span> + _sessionId + <span class="jxr_string">", clusterName: "</span>
+<a class="jxr_linenumber" name="672" href="#672">672</a>           + _clusterName);
+<a class="jxr_linenumber" name="673" href="#673">673</a>       isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
+<a class="jxr_linenumber" name="674" href="#674">674</a>     }
+<a class="jxr_linenumber" name="675" href="#675">675</a> 
+<a class="jxr_linenumber" name="676" href="#676">676</a>     ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection());
+<a class="jxr_linenumber" name="677" href="#677">677</a>     
+<a class="jxr_linenumber" name="678" href="#678">678</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
+<a class="jxr_linenumber" name="679" href="#679">679</a>     {
+<a class="jxr_linenumber" name="680" href="#680">680</a>       _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
+<a class="jxr_linenumber" name="681" href="#681">681</a>     }
+<a class="jxr_linenumber" name="682" href="#682">682</a>     _baseDataAccessor.reset();
+<a class="jxr_linenumber" name="683" href="#683">683</a> 
+<a class="jxr_linenumber" name="684" href="#684">684</a>     <em class="jxr_comment">// reset all handlers so they have a chance to unsubscribe zk changes from zkclient</em>
+<a class="jxr_linenumber" name="685" href="#685">685</a>     <em class="jxr_comment">// abandon all callback-handlers added in expired session</em>
+<a class="jxr_linenumber" name="686" href="#686">686</a>     resetHandlers();
 <a class="jxr_linenumber" name="687" href="#687">687</a> 
-<a class="jxr_linenumber" name="688" href="#688">688</a>     <em class="jxr_comment">// reset all handlers so they have a chance to unsubscribe zk changes from zkclient</em>
-<a class="jxr_linenumber" name="689" href="#689">689</a>     <em class="jxr_comment">// abandon all callback-handlers added in expired session</em>
-<a class="jxr_linenumber" name="690" href="#690">690</a>     resetHandlers();
-<a class="jxr_linenumber" name="691" href="#691">691</a> 
-<a class="jxr_linenumber" name="692" href="#692">692</a>     logger.info(<span class="jxr_string">"Handling new session, session id:"</span> + _sessionId + <span class="jxr_string">", instance:"</span>
-<a class="jxr_linenumber" name="693" href="#693">693</a>         + _instanceName + <span class="jxr_string">", instanceTye: "</span> + _instanceType + <span class="jxr_string">", cluster: "</span> + _clusterName);
-<a class="jxr_linenumber" name="694" href="#694">694</a> 
-<a class="jxr_linenumber" name="695" href="#695">695</a>     logger.info(zkConnection.getZookeeper());
-<a class="jxr_linenumber" name="696" href="#696">696</a> 
-<a class="jxr_linenumber" name="697" href="#697">697</a>     <strong class="jxr_keyword">if</strong> (!ZKUtil.isClusterSetup(_clusterName, _zkClient))
-<a class="jxr_linenumber" name="698" href="#698">698</a>     {
-<a class="jxr_linenumber" name="699" href="#699">699</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Initial cluster structure is not set up for cluster:"</span>
-<a class="jxr_linenumber" name="700" href="#700">700</a>           + _clusterName);
-<a class="jxr_linenumber" name="701" href="#701">701</a>     }
-<a class="jxr_linenumber" name="702" href="#702">702</a>     <em class="jxr_comment">// Read cluster config and see if instance can auto join the cluster</em>
-<a class="jxr_linenumber" name="703" href="#703">703</a>     <strong class="jxr_keyword">boolean</strong> autoJoin = false;
-<a class="jxr_linenumber" name="704" href="#704">704</a>     <strong class="jxr_keyword">try</strong>
-<a class="jxr_linenumber" name="705" href="#705">705</a>     {
-<a class="jxr_linenumber" name="706" href="#706">706</a>       <a href="../../../../../org/apache/helix/model/HelixConfigScope.html">HelixConfigScope</a> scope =
-<a class="jxr_linenumber" name="707" href="#707">707</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/model/builder/HelixConfigScopeBuilder.html">HelixConfigScopeBuilder</a>(ConfigScopeProperty.CLUSTER).forCluster(getClusterName())
-<a class="jxr_linenumber" name="708" href="#708">708</a>                                   .build();
-<a class="jxr_linenumber" name="709" href="#709">709</a>       autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN));
-<a class="jxr_linenumber" name="710" href="#710">710</a>       logger.info(<span class="jxr_string">"Auto joining "</span> + _clusterName +<span class="jxr_string">" is true"</span>);
-<a class="jxr_linenumber" name="711" href="#711">711</a>     }
-<a class="jxr_linenumber" name="712" href="#712">712</a>     <strong class="jxr_keyword">catch</strong>(Exception e)
-<a class="jxr_linenumber" name="713" href="#713">713</a>     {
-<a class="jxr_linenumber" name="714" href="#714">714</a>     }
-<a class="jxr_linenumber" name="715" href="#715">715</a>     <strong class="jxr_keyword">if</strong> (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType))
-<a class="jxr_linenumber" name="716" href="#716">716</a>     {
-<a class="jxr_linenumber" name="717" href="#717">717</a>       <strong class="jxr_keyword">if</strong>(!autoJoin)
-<a class="jxr_linenumber" name="718" href="#718">718</a>       {
-<a class="jxr_linenumber" name="719" href="#719">719</a>         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Initial cluster structure is not set up for instance:"</span>
-<a class="jxr_linenumber" name="720" href="#720">720</a>           + _instanceName + <span class="jxr_string">" instanceType:"</span> + _instanceType);
-<a class="jxr_linenumber" name="721" href="#721">721</a>       }
-<a class="jxr_linenumber" name="722" href="#722">722</a>       <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="723" href="#723">723</a>       {
-<a class="jxr_linenumber" name="724" href="#724">724</a>         logger.info(<span class="jxr_string">"Auto joining instance "</span> + _instanceName);
-<a class="jxr_linenumber" name="725" href="#725">725</a>         <a href="../../../../../org/apache/helix/model/InstanceConfig.html">InstanceConfig</a> instanceConfig = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/model/InstanceConfig.html">InstanceConfig</a>(_instanceName);
-<a class="jxr_linenumber" name="726" href="#726">726</a>         String hostName = _instanceName;
-<a class="jxr_linenumber" name="727" href="#727">727</a>         String port = <span class="jxr_string">""</span>;
-<a class="jxr_linenumber" name="728" href="#728">728</a>         <strong class="jxr_keyword">int</strong> lastPos = _instanceName.lastIndexOf(<span class="jxr_string">"_"</span>);
-<a class="jxr_linenumber" name="729" href="#729">729</a>         <strong class="jxr_keyword">if</strong> (lastPos &gt; 0)
-<a class="jxr_linenumber" name="730" href="#730">730</a>         {
-<a class="jxr_linenumber" name="731" href="#731">731</a>           hostName = _instanceName.substring(0, lastPos);
-<a class="jxr_linenumber" name="732" href="#732">732</a>           port = _instanceName.substring(lastPos + 1);
-<a class="jxr_linenumber" name="733" href="#733">733</a>         }
-<a class="jxr_linenumber" name="734" href="#734">734</a>         instanceConfig.setHostName(hostName);
-<a class="jxr_linenumber" name="735" href="#735">735</a>         instanceConfig.setPort(port);
-<a class="jxr_linenumber" name="736" href="#736">736</a>         instanceConfig.setInstanceEnabled(<strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="737" href="#737">737</a>         getClusterManagmentTool().addInstance(_clusterName, instanceConfig);
-<a class="jxr_linenumber" name="738" href="#738">738</a>       }
-<a class="jxr_linenumber" name="739" href="#739">739</a>     }
-<a class="jxr_linenumber" name="740" href="#740">740</a> 
-<a class="jxr_linenumber" name="741" href="#741">741</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT
-<a class="jxr_linenumber" name="742" href="#742">742</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
-<a class="jxr_linenumber" name="743" href="#743">743</a>     {
-<a class="jxr_linenumber" name="744" href="#744">744</a>       handleNewSessionAsParticipant();
-<a class="jxr_linenumber" name="745" href="#745">745</a>     }
-<a class="jxr_linenumber" name="746" href="#746">746</a> 
-<a class="jxr_linenumber" name="747" href="#747">747</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.CONTROLLER
-<a class="jxr_linenumber" name="748" href="#748">748</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
-<a class="jxr_linenumber" name="749" href="#749">749</a>     {
-<a class="jxr_linenumber" name="750" href="#750">750</a>       addControllerMessageListener(_messagingService.getExecutor());
-<a class="jxr_linenumber" name="751" href="#751">751</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultControllerMsgHandlerFactory =
-<a class="jxr_linenumber" name="752" href="#752">752</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultControllerMessageHandlerFactory.html">DefaultControllerMessageHandlerFactory</a>();
-<a class="jxr_linenumber" name="753" href="#753">753</a>       _messagingService.getExecutor()
-<a class="jxr_linenumber" name="754" href="#754">754</a>                        .registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(),
-<a class="jxr_linenumber" name="755" href="#755">755</a>                                                       defaultControllerMsgHandlerFactory);
-<a class="jxr_linenumber" name="756" href="#756">756</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultSchedulerMsgHandlerFactory =
-<a class="jxr_linenumber" name="757" href="#757">757</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultSchedulerMessageHandlerFactory.html">DefaultSchedulerMessageHandlerFactory</a>(<strong class="jxr_keyword">this</strong>);
-<a class="jxr_linenumber" name="758" href="#758">758</a>       _messagingService.getExecutor()
-<a class="jxr_linenumber" name="759" href="#759">759</a>                        .registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(),
-<a class="jxr_linenumber" name="760" href="#760">760</a>                                                       defaultSchedulerMsgHandlerFactory);
-<a class="jxr_linenumber" name="761" href="#761">761</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultParticipantErrorMessageHandlerFactory =
-<a class="jxr_linenumber" name="762" href="#762">762</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultParticipantErrorMessageHandlerFactory.html">DefaultParticipantErrorMessageHandlerFactory</a>(<strong class="jxr_keyword">this</strong>);
-<a class="jxr_linenumber" name="763" href="#763">763</a>       _messagingService.getExecutor()
-<a class="jxr_linenumber" name="764" href="#764">764</a>                        .registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(),
-<a class="jxr_linenumber" name="765" href="#765">765</a>                                                       defaultParticipantErrorMessageHandlerFactory);
-<a class="jxr_linenumber" name="766" href="#766">766</a> 
-<a class="jxr_linenumber" name="767" href="#767">767</a>       <strong class="jxr_keyword">if</strong> (_leaderElectionHandler != <strong class="jxr_keyword">null</strong>) {
-<a class="jxr_linenumber" name="768" href="#768">768</a>     	  _leaderElectionHandler.reset();
-<a class="jxr_linenumber" name="769" href="#769">769</a>     	  _leaderElectionHandler.init();
-<a class="jxr_linenumber" name="770" href="#770">770</a>       } <strong class="jxr_keyword">else</strong> {
-<a class="jxr_linenumber" name="771" href="#771">771</a>         _leaderElectionHandler =
-<a class="jxr_linenumber" name="772" href="#772">772</a>               createCallBackHandler(<strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a>(_clusterName).controller(),
-<a class="jxr_linenumber" name="773" href="#773">773</a>                                     <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/participant/DistClusterControllerElection.html">DistClusterControllerElection</a>(_zkConnectString),
-<a class="jxr_linenumber" name="774" href="#774">774</a>                                     <strong class="jxr_keyword">new</strong> EventType[] { EventType.NodeChildrenChanged,
-<a class="jxr_linenumber" name="775" href="#775">775</a>                                         EventType.NodeDeleted, EventType.NodeCreated },
-<a class="jxr_linenumber" name="776" href="#776">776</a>                                     ChangeType.CONTROLLER);
-<a class="jxr_linenumber" name="777" href="#777">777</a>       }
-<a class="jxr_linenumber" name="778" href="#778">778</a>     }
-<a class="jxr_linenumber" name="779" href="#779">779</a> 
-<a class="jxr_linenumber" name="780" href="#780">780</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT
-<a class="jxr_linenumber" name="781" href="#781">781</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT
-<a class="jxr_linenumber" name="782" href="#782">782</a>         || (_instanceType == InstanceType.CONTROLLER &amp;&amp; isLeader()))
-<a class="jxr_linenumber" name="783" href="#783">783</a>     {
-<a class="jxr_linenumber" name="784" href="#784">784</a>       initHandlers();
-<a class="jxr_linenumber" name="785" href="#785">785</a>     }
-<a class="jxr_linenumber" name="786" href="#786">786</a>   }
-<a class="jxr_linenumber" name="787" href="#787">787</a> 
-<a class="jxr_linenumber" name="788" href="#788">788</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> handleNewSessionAsParticipant()
-<a class="jxr_linenumber" name="789" href="#789">789</a>   {
-<a class="jxr_linenumber" name="790" href="#790">790</a>     <em class="jxr_comment">// In case there is a live instance record on zookeeper</em>
-<a class="jxr_linenumber" name="791" href="#791">791</a>     <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a> keyBuilder = _helixAccessor.keyBuilder();
-<a class="jxr_linenumber" name="792" href="#792">792</a> 
-<a class="jxr_linenumber" name="793" href="#793">793</a>     <strong class="jxr_keyword">if</strong> (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="794" href="#794">794</a>     {
-<a class="jxr_linenumber" name="795" href="#795">795</a>       logger.warn(<span class="jxr_string">"Found another instance with same instanceName: "</span> + _instanceName
-<a class="jxr_linenumber" name="796" href="#796">796</a>           + <span class="jxr_string">" in cluster "</span> + _clusterName);
-<a class="jxr_linenumber" name="797" href="#797">797</a>       <em class="jxr_comment">// Wait for a while, in case previous storage node exits unexpectedly</em>
-<a class="jxr_linenumber" name="798" href="#798">798</a>       <em class="jxr_comment">// and its liveinstance</em>
-<a class="jxr_linenumber" name="799" href="#799">799</a>       <em class="jxr_comment">// still hangs around until session timeout happens</em>
-<a class="jxr_linenumber" name="800" href="#800">800</a>       <strong class="jxr_keyword">try</strong>
+<a class="jxr_linenumber" name="688" href="#688">688</a>     logger.info(<span class="jxr_string">"Handling new session, session id:"</span> + _sessionId + <span class="jxr_string">", instance:"</span>
+<a class="jxr_linenumber" name="689" href="#689">689</a>         + _instanceName + <span class="jxr_string">", instanceTye: "</span> + _instanceType + <span class="jxr_string">", cluster: "</span> + _clusterName);
+<a class="jxr_linenumber" name="690" href="#690">690</a> 
+<a class="jxr_linenumber" name="691" href="#691">691</a>     logger.info(zkConnection.getZookeeper());
+<a class="jxr_linenumber" name="692" href="#692">692</a> 
+<a class="jxr_linenumber" name="693" href="#693">693</a>     <strong class="jxr_keyword">if</strong> (!ZKUtil.isClusterSetup(_clusterName, _zkClient))
+<a class="jxr_linenumber" name="694" href="#694">694</a>     {
+<a class="jxr_linenumber" name="695" href="#695">695</a>       <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Initial cluster structure is not set up for cluster:"</span>
+<a class="jxr_linenumber" name="696" href="#696">696</a>           + _clusterName);
+<a class="jxr_linenumber" name="697" href="#697">697</a>     }
+<a class="jxr_linenumber" name="698" href="#698">698</a>     <em class="jxr_comment">// Read cluster config and see if instance can auto join the cluster</em>
+<a class="jxr_linenumber" name="699" href="#699">699</a>     <strong class="jxr_keyword">boolean</strong> autoJoin = false;
+<a class="jxr_linenumber" name="700" href="#700">700</a>     <strong class="jxr_keyword">try</strong>
+<a class="jxr_linenumber" name="701" href="#701">701</a>     {
+<a class="jxr_linenumber" name="702" href="#702">702</a>       <a href="../../../../../org/apache/helix/model/HelixConfigScope.html">HelixConfigScope</a> scope =
+<a class="jxr_linenumber" name="703" href="#703">703</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/model/builder/HelixConfigScopeBuilder.html">HelixConfigScopeBuilder</a>(ConfigScopeProperty.CLUSTER).forCluster(getClusterName())
+<a class="jxr_linenumber" name="704" href="#704">704</a>                                   .build();
+<a class="jxr_linenumber" name="705" href="#705">705</a>       autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN));
+<a class="jxr_linenumber" name="706" href="#706">706</a>       logger.info(<span class="jxr_string">"Auto joining "</span> + _clusterName +<span class="jxr_string">" is true"</span>);
+<a class="jxr_linenumber" name="707" href="#707">707</a>     }
+<a class="jxr_linenumber" name="708" href="#708">708</a>     <strong class="jxr_keyword">catch</strong>(Exception e)
+<a class="jxr_linenumber" name="709" href="#709">709</a>     {
+<a class="jxr_linenumber" name="710" href="#710">710</a>     }
+<a class="jxr_linenumber" name="711" href="#711">711</a>     <strong class="jxr_keyword">if</strong> (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType))
+<a class="jxr_linenumber" name="712" href="#712">712</a>     {
+<a class="jxr_linenumber" name="713" href="#713">713</a>       <strong class="jxr_keyword">if</strong>(!autoJoin)
+<a class="jxr_linenumber" name="714" href="#714">714</a>       {
+<a class="jxr_linenumber" name="715" href="#715">715</a>         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(<span class="jxr_string">"Initial cluster structure is not set up for instance:"</span>
+<a class="jxr_linenumber" name="716" href="#716">716</a>           + _instanceName + <span class="jxr_string">" instanceType:"</span> + _instanceType);
+<a class="jxr_linenumber" name="717" href="#717">717</a>       }
+<a class="jxr_linenumber" name="718" href="#718">718</a>       <strong class="jxr_keyword">else</strong>
+<a class="jxr_linenumber" name="719" href="#719">719</a>       {
+<a class="jxr_linenumber" name="720" href="#720">720</a>         logger.info(<span class="jxr_string">"Auto joining instance "</span> + _instanceName);
+<a class="jxr_linenumber" name="721" href="#721">721</a>         <a href="../../../../../org/apache/helix/model/InstanceConfig.html">InstanceConfig</a> instanceConfig = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/model/InstanceConfig.html">InstanceConfig</a>(_instanceName);
+<a class="jxr_linenumber" name="722" href="#722">722</a>         String hostName = _instanceName;
+<a class="jxr_linenumber" name="723" href="#723">723</a>         String port = <span class="jxr_string">""</span>;
+<a class="jxr_linenumber" name="724" href="#724">724</a>         <strong class="jxr_keyword">int</strong> lastPos = _instanceName.lastIndexOf(<span class="jxr_string">"_"</span>);
+<a class="jxr_linenumber" name="725" href="#725">725</a>         <strong class="jxr_keyword">if</strong> (lastPos &gt; 0)
+<a class="jxr_linenumber" name="726" href="#726">726</a>         {
+<a class="jxr_linenumber" name="727" href="#727">727</a>           hostName = _instanceName.substring(0, lastPos);
+<a class="jxr_linenumber" name="728" href="#728">728</a>           port = _instanceName.substring(lastPos + 1);
+<a class="jxr_linenumber" name="729" href="#729">729</a>         }
+<a class="jxr_linenumber" name="730" href="#730">730</a>         instanceConfig.setHostName(hostName);
+<a class="jxr_linenumber" name="731" href="#731">731</a>         instanceConfig.setPort(port);
+<a class="jxr_linenumber" name="732" href="#732">732</a>         instanceConfig.setInstanceEnabled(<strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="733" href="#733">733</a>         getClusterManagmentTool().addInstance(_clusterName, instanceConfig);
+<a class="jxr_linenumber" name="734" href="#734">734</a>       }
+<a class="jxr_linenumber" name="735" href="#735">735</a>     }
+<a class="jxr_linenumber" name="736" href="#736">736</a> 
+<a class="jxr_linenumber" name="737" href="#737">737</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT
+<a class="jxr_linenumber" name="738" href="#738">738</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
+<a class="jxr_linenumber" name="739" href="#739">739</a>     {
+<a class="jxr_linenumber" name="740" href="#740">740</a>       handleNewSessionAsParticipant();
+<a class="jxr_linenumber" name="741" href="#741">741</a>     }
+<a class="jxr_linenumber" name="742" href="#742">742</a> 
+<a class="jxr_linenumber" name="743" href="#743">743</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.CONTROLLER
+<a class="jxr_linenumber" name="744" href="#744">744</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
+<a class="jxr_linenumber" name="745" href="#745">745</a>     {
+<a class="jxr_linenumber" name="746" href="#746">746</a>       addControllerMessageListener(_messagingService.getExecutor());
+<a class="jxr_linenumber" name="747" href="#747">747</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultControllerMsgHandlerFactory =
+<a class="jxr_linenumber" name="748" href="#748">748</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultControllerMessageHandlerFactory.html">DefaultControllerMessageHandlerFactory</a>();
+<a class="jxr_linenumber" name="749" href="#749">749</a>       _messagingService.getExecutor()
+<a class="jxr_linenumber" name="750" href="#750">750</a>                        .registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(),
+<a class="jxr_linenumber" name="751" href="#751">751</a>                                                       defaultControllerMsgHandlerFactory);
+<a class="jxr_linenumber" name="752" href="#752">752</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultSchedulerMsgHandlerFactory =
+<a class="jxr_linenumber" name="753" href="#753">753</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultSchedulerMessageHandlerFactory.html">DefaultSchedulerMessageHandlerFactory</a>(<strong class="jxr_keyword">this</strong>);
+<a class="jxr_linenumber" name="754" href="#754">754</a>       _messagingService.getExecutor()
+<a class="jxr_linenumber" name="755" href="#755">755</a>                        .registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(),
+<a class="jxr_linenumber" name="756" href="#756">756</a>                                                       defaultSchedulerMsgHandlerFactory);
+<a class="jxr_linenumber" name="757" href="#757">757</a>       <a href="../../../../../org/apache/helix/messaging/handling/MessageHandlerFactory.html">MessageHandlerFactory</a> defaultParticipantErrorMessageHandlerFactory =
+<a class="jxr_linenumber" name="758" href="#758">758</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/manager/zk/DefaultParticipantErrorMessageHandlerFactory.html">DefaultParticipantErrorMessageHandlerFactory</a>(<strong class="jxr_keyword">this</strong>);
+<a class="jxr_linenumber" name="759" href="#759">759</a>       _messagingService.getExecutor()
+<a class="jxr_linenumber" name="760" href="#760">760</a>                        .registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(),
+<a class="jxr_linenumber" name="761" href="#761">761</a>                                                       defaultParticipantErrorMessageHandlerFactory);
+<a class="jxr_linenumber" name="762" href="#762">762</a> 
+<a class="jxr_linenumber" name="763" href="#763">763</a>       <strong class="jxr_keyword">if</strong> (_leaderElectionHandler != <strong class="jxr_keyword">null</strong>) {
+<a class="jxr_linenumber" name="764" href="#764">764</a>     	  _leaderElectionHandler.reset();
+<a class="jxr_linenumber" name="765" href="#765">765</a>     	  _leaderElectionHandler.init();
+<a class="jxr_linenumber" name="766" href="#766">766</a>       } <strong class="jxr_keyword">else</strong> {
+<a class="jxr_linenumber" name="767" href="#767">767</a>         _leaderElectionHandler =
+<a class="jxr_linenumber" name="768" href="#768">768</a>               createCallBackHandler(<strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a>(_clusterName).controller(),
+<a class="jxr_linenumber" name="769" href="#769">769</a>                                     <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/participant/DistClusterControllerElection.html">DistClusterControllerElection</a>(_zkConnectString),
+<a class="jxr_linenumber" name="770" href="#770">770</a>                                     <strong class="jxr_keyword">new</strong> EventType[] { EventType.NodeChildrenChanged,
+<a class="jxr_linenumber" name="771" href="#771">771</a>                                         EventType.NodeDeleted, EventType.NodeCreated },
+<a class="jxr_linenumber" name="772" href="#772">772</a>                                     ChangeType.CONTROLLER);
+<a class="jxr_linenumber" name="773" href="#773">773</a>       }
+<a class="jxr_linenumber" name="774" href="#774">774</a>     }
+<a class="jxr_linenumber" name="775" href="#775">775</a> 
+<a class="jxr_linenumber" name="776" href="#776">776</a>     <strong class="jxr_keyword">if</strong> (_instanceType == InstanceType.PARTICIPANT
+<a class="jxr_linenumber" name="777" href="#777">777</a>         || _instanceType == InstanceType.CONTROLLER_PARTICIPANT
+<a class="jxr_linenumber" name="778" href="#778">778</a>         || (_instanceType == InstanceType.CONTROLLER &amp;&amp; isLeader()))
+<a class="jxr_linenumber" name="779" href="#779">779</a>     {
+<a class="jxr_linenumber" name="780" href="#780">780</a>       initHandlers();
+<a class="jxr_linenumber" name="781" href="#781">781</a>     }
+<a class="jxr_linenumber" name="782" href="#782">782</a>   }
+<a class="jxr_linenumber" name="783" href="#783">783</a> 
+<a class="jxr_linenumber" name="784" href="#784">784</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> handleNewSessionAsParticipant()
+<a class="jxr_linenumber" name="785" href="#785">785</a>   {
+<a class="jxr_linenumber" name="786" href="#786">786</a>     <em class="jxr_comment">// In case there is a live instance record on zookeeper</em>
+<a class="jxr_linenumber" name="787" href="#787">787</a>     <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a> keyBuilder = _helixAccessor.keyBuilder();
+<a class="jxr_linenumber" name="788" href="#788">788</a> 
+<a class="jxr_linenumber" name="789" href="#789">789</a>     <strong class="jxr_keyword">if</strong> (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="790" href="#790">790</a>     {
+<a class="jxr_linenumber" name="791" href="#791">791</a>       logger.warn(<span class="jxr_string">"Found another instance with same instanceName: "</span> + _instanceName
+<a class="jxr_linenumber" name="792" href="#792">792</a>           + <span class="jxr_string">" in cluster "</span> + _clusterName);
+<a class="jxr_linenumber" name="793" href="#793">793</a>       <em class="jxr_comment">// Wait for a while, in case previous storage node exits unexpectedly</em>
+<a class="jxr_linenumber" name="794" href="#794">794</a>       <em class="jxr_comment">// and its liveinstance</em>
+<a class="jxr_linenumber" name="795" href="#795">795</a>       <em class="jxr_comment">// still hangs around until session timeout happens</em>
+<a class="jxr_linenumber" name="796" href="#796">796</a>       <strong class="jxr_keyword">try</strong>
+<a class="jxr_linenumber" name="797" href="#797">797</a>       {
+<a class="jxr_linenumber" name="798" href="#798">798</a>         Thread.sleep(_sessionTimeout + 5000);
+<a class="jxr_linenumber" name="799" href="#799">799</a>       }
+<a class="jxr_linenumber" name="800" href="#800">800</a>       <strong class="jxr_keyword">catch</strong> (InterruptedException e)
 <a class="jxr_linenumber" name="801" href="#801">801</a>       {
-<a class="jxr_linenumber" name="802" href="#802">802</a>         Thread.sleep(_sessionTimeout + 5000);
-<a class="jxr_linenumber" name="803" href="#803">803</a>       }
-<a class="jxr_linenumber" name="804" href="#804">804</a>       <strong class="jxr_keyword">catch</strong> (InterruptedException e)
-<a class="jxr_linenumber" name="805" href="#805">805</a>       {
-<a class="jxr_linenumber" name="806" href="#806">806</a>         logger.warn(<span class="jxr_string">"Sleep interrupted while waiting for previous liveinstance to go away."</span>,
-<a class="jxr_linenumber" name="807" href="#807">807</a>                     e);
-<a class="jxr_linenumber" name="808" href="#808">808</a>       }
-<a class="jxr_linenumber" name="809" href="#809">809</a> 
-<a class="jxr_linenumber" name="810" href="#810">810</a>       <strong class="jxr_keyword">if</strong> (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="811" href="#811">811</a>       {
-<a class="jxr_linenumber" name="812" href="#812">812</a>         String errorMessage =
-<a class="jxr_linenumber" name="813" href="#813">813</a>             <span class="jxr_string">"instance "</span> + _instanceName + <span class="jxr_string">" already has a liveinstance in cluster "</span>
-<a class="jxr_linenumber" name="814" href="#814">814</a>                 + _clusterName;
-<a class="jxr_linenumber" name="815" href="#815">815</a>         logger.error(errorMessage);
-<a class="jxr_linenumber" name="816" href="#816">816</a>         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(errorMessage);
-<a class="jxr_linenumber" name="817" href="#817">817</a>       }
-<a class="jxr_linenumber" name="818" href="#818">818</a>     }
-<a class="jxr_linenumber" name="819" href="#819">819</a>     <em class="jxr_comment">// Invoke the PreConnectCallbacks</em>
-<a class="jxr_linenumber" name="820" href="#820">820</a>     <strong class="jxr_keyword">for</strong> (PreConnectCallback callback : _preConnectCallbacks)
-<a class="jxr_linenumber" name="821" href="#821">821</a>     {
-<a class="jxr_linenumber" name="822" href="#822">822</a>       callback.onPreConnect();
-<a class="jxr_linenumber" name="823" href="#823">823</a>     }
-<a class="jxr_linenumber" name="824" href="#824">824</a>     addLiveInstance();
-<a class="jxr_linenumber" name="825" href="#825">825</a>     carryOverPreviousCurrentState();
-<a class="jxr_linenumber" name="826" href="#826">826</a> 
-<a class="jxr_linenumber" name="827" href="#827">827</a>     <em class="jxr_comment">// In case the cluster manager is running as a participant, setup message</em>
-<a class="jxr_linenumber" name="828" href="#828">828</a>     <em class="jxr_comment">// listener</em>
-<a class="jxr_linenumber" name="829" href="#829">829</a>     _messagingService.registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
-<a class="jxr_linenumber" name="830" href="#830">830</a>                                                     _stateMachEngine);
-<a class="jxr_linenumber" name="831" href="#831">831</a>     addMessageListener(_messagingService.getExecutor(), _instanceName);
-<a class="jxr_linenumber" name="832" href="#832">832</a>     addControllerListener(_helixAccessor);
-<a class="jxr_linenumber" name="833" href="#833">833</a>     
-<a class="jxr_linenumber" name="834" href="#834">834</a>     <a href="../../../../../org/apache/helix/participant/statemachine/ScheduledTaskStateModelFactory.html">ScheduledTaskStateModelFactory</a> stStateModelFactory = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/participant/statemachine/ScheduledTaskStateModelFactory.html">ScheduledTaskStateModelFactory</a>(_messagingService.getExecutor());
-<a class="jxr_linenumber" name="835" href="#835">835</a>     _stateMachEngine.registerStateModelFactory(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE, stStateModelFactory);
-<a class="jxr_linenumber" name="836" href="#836">836</a> 
-<a class="jxr_linenumber" name="837" href="#837">837</a>     <strong class="jxr_keyword">if</strong> (_participantHealthCheckInfoCollector == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="838" href="#838">838</a>     {
-<a class="jxr_linenumber" name="839" href="#839">839</a>       _participantHealthCheckInfoCollector =
-<a class="jxr_linenumber" name="840" href="#840">840</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.html">ParticipantHealthReportCollectorImpl</a>(<strong class="jxr_keyword">this</strong>, _instanceName);
-<a class="jxr_linenumber" name="841" href="#841">841</a>       _participantHealthCheckInfoCollector.start();
-<a class="jxr_linenumber" name="842" href="#842">842</a>     }
-<a class="jxr_linenumber" name="843" href="#843">843</a>     <em class="jxr_comment">// start the participant health check timer, also create zk path for health</em>
-<a class="jxr_linenumber" name="844" href="#844">844</a>     <em class="jxr_comment">// check info</em>
-<a class="jxr_linenumber" name="845" href="#845">845</a>     String healthCheckInfoPath =
-<a class="jxr_linenumber" name="846" href="#846">846</a>         _helixAccessor.keyBuilder().healthReports(_instanceName).getPath();
-<a class="jxr_linenumber" name="847" href="#847">847</a>     <strong class="jxr_keyword">if</strong> (!_zkClient.exists(healthCheckInfoPath))
-<a class="jxr_linenumber" name="848" href="#848">848</a>     {
-<a class="jxr_linenumber" name="849" href="#849">849</a>       _zkClient.createPersistent(healthCheckInfoPath, <strong class="jxr_keyword">true</strong>);
-<a class="jxr_linenumber" name="850" href="#850">850</a>       logger.info(<span class="jxr_string">"Creating healthcheck info path "</span> + healthCheckInfoPath);
-<a class="jxr_linenumber" name="851" href="#851">851</a>     }
-<a class="jxr_linenumber" name="852" href="#852">852</a>   }
-<a class="jxr_linenumber" name="853" href="#853">853</a> 
-<a class="jxr_linenumber" name="854" href="#854">854</a>   @Override
-<a class="jxr_linenumber" name="855" href="#855">855</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addPreConnectCallback(<a href="../../../../../org/apache/helix/PreConnectCallback.html">PreConnectCallback</a> callback)
-<a class="jxr_linenumber" name="856" href="#856">856</a>   {
-<a class="jxr_linenumber" name="857" href="#857">857</a>     logger.info(<span class="jxr_string">"Adding preconnect callback"</span>);
-<a class="jxr_linenumber" name="858" href="#858">858</a>     _preConnectCallbacks.add(callback);
-<a class="jxr_linenumber" name="859" href="#859">859</a>   }
-<a class="jxr_linenumber" name="860" href="#860">860</a> 
-<a class="jxr_linenumber" name="861" href="#861">861</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resetHandlers()
-<a class="jxr_linenumber" name="862" href="#862">862</a>   {
-<a class="jxr_linenumber" name="863" href="#863">863</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
-<a class="jxr_linenumber" name="864" href="#864">864</a>     {
-<a class="jxr_linenumber" name="865" href="#865">865</a>     	<strong class="jxr_keyword">if</strong> (_handlers != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="866" href="#866">866</a>         {
-<a class="jxr_linenumber" name="867" href="#867">867</a>             <em class="jxr_comment">// get a copy of the list and iterate over the copy list</em>
-<a class="jxr_linenumber" name="868" href="#868">868</a>             <em class="jxr_comment">// in case handler.reset() will modify the original handler list</em>
-<a class="jxr_linenumber" name="869" href="#869">869</a>             List&lt;CallbackHandler&gt; tmpHandlers = <strong class="jxr_keyword">new</strong> ArrayList&lt;CallbackHandler&gt;();
-<a class="jxr_linenumber" name="870" href="#870">870</a>             tmpHandlers.addAll(_handlers);
-<a class="jxr_linenumber" name="871" href="#871">871</a> 
-<a class="jxr_linenumber" name="872" href="#872">872</a>             <strong class="jxr_keyword">for</strong> (CallbackHandler handler : tmpHandlers)
-<a class="jxr_linenumber" name="873" href="#873">873</a>             {
-<a class="jxr_linenumber" name="874" href="#874">874</a>               handler.reset();
-<a class="jxr_linenumber" name="875" href="#875">875</a>               logger.info(<span class="jxr_string">"reset handler: "</span> + handler.getPath() + <span class="jxr_string">", "</span> + handler.getListener());
-<a class="jxr_linenumber" name="876" href="#876">876</a>             }
-<a class="jxr_linenumber" name="877" href="#877">877</a>         }
-<a class="jxr_linenumber" name="878" href="#878">878</a>     }
-<a class="jxr_linenumber" name="879" href="#879">879</a>   }
-<a class="jxr_linenumber" name="880" href="#880">880</a> 
-<a class="jxr_linenumber" name="881" href="#881">881</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> initHandlers()
-<a class="jxr_linenumber" name="882" href="#882">882</a>   {
-<a class="jxr_linenumber" name="883" href="#883">883</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
-<a class="jxr_linenumber" name="884" href="#884">884</a>     {
-<a class="jxr_linenumber" name="885" href="#885">885</a>     	<strong class="jxr_keyword">if</strong> (_handlers != <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="886" href="#886">886</a>     	{
-<a class="jxr_linenumber" name="887" href="#887">887</a>     	  <em class="jxr_comment">// may add new currentState and message listeners during init()</em>
-<a class="jxr_linenumber" name="888" href="#888">888</a>     	  <em class="jxr_comment">// so make a copy and iterate over the copy</em>
-<a class="jxr_linenumber" name="889" href="#889">889</a>     	  List&lt;CallbackHandler&gt; tmpHandlers = <strong class="jxr_keyword">new</strong> ArrayList&lt;CallbackHandler&gt;();
-<a class="jxr_linenumber" name="890" href="#890">890</a>     	  tmpHandlers.addAll(_handlers);
-<a class="jxr_linenumber" name="891" href="#891">891</a>           <strong class="jxr_keyword">for</strong> (CallbackHandler handler : tmpHandlers)
-<a class="jxr_linenumber" name="892" href="#892">892</a>           {
-<a class="jxr_linenumber" name="893" href="#893">893</a>             handler.init();
-<a class="jxr_linenumber" name="894" href="#894">894</a>             logger.info(<span class="jxr_string">"init handler: "</span> + handler.getPath() + <span class="jxr_string">", "</span> + handler.getListener());
-<a class="jxr_linenumber" name="895" href="#895">895</a>           }
-<a class="jxr_linenumber" name="896" href="#896">896</a>     	}
-<a class="jxr_linenumber" name="897" href="#897">897</a>     }
-<a class="jxr_linenumber" name="898" href="#898">898</a>   }
-<a class="jxr_linenumber" name="899" href="#899">899</a> 
-<a class="jxr_linenumber" name="900" href="#900">900</a>   @Override
-<a class="jxr_linenumber" name="901" href="#901">901</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> isLeader()
-<a class="jxr_linenumber" name="902" href="#902">902</a>   {
-<a class="jxr_linenumber" name="903" href="#903">903</a>     <strong class="jxr_keyword">if</strong> (!isConnected())
-<a class="jxr_linenumber" name="904" href="#904">904</a>     {
-<a class="jxr_linenumber" name="905" href="#905">905</a>       <strong class="jxr_keyword">return</strong> false;
-<a class="jxr_linenumber" name="906" href="#906">906</a>     }
-<a class="jxr_linenumber" name="907" href="#907">907</a> 
-<a class="jxr_linenumber" name="908" href="#908">908</a>     <strong class="jxr_keyword">if</strong> (_instanceType != InstanceType.CONTROLLER)
-<a class="jxr_linenumber" name="909" href="#909">909</a>     {
-<a class="jxr_linenumber" name="910" href="#910">910</a>       <strong class="jxr_keyword">return</strong> false;
-<a class="jxr_linenumber" name="911" href="#911">911</a>     }
-<a class="jxr_linenumber" name="912" href="#912">912</a> 
-<a class="jxr_linenumber" name="913" href="#913">913</a>     <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a> keyBuilder = _helixAccessor.keyBuilder();
-<a class="jxr_linenumber" name="914" href="#914">914</a>     <a href="../../../../../org/apache/helix/model/LiveInstance.html">LiveInstance</a> leader = _helixAccessor.getProperty(keyBuilder.controllerLeader());
-<a class="jxr_linenumber" name="915" href="#915">915</a>     <strong class="jxr_keyword">if</strong> (leader == <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="802" href="#802">802</a>         logger.warn(<span class="jxr_string">"Sleep interrupted while waiting for previous liveinstance to go away."</span>,
+<a class="jxr_linenumber" name="803" href="#803">803</a>                     e);
+<a class="jxr_linenumber" name="804" href="#804">804</a>       }
+<a class="jxr_linenumber" name="805" href="#805">805</a> 
+<a class="jxr_linenumber" name="806" href="#806">806</a>       <strong class="jxr_keyword">if</strong> (_helixAccessor.getProperty(keyBuilder.liveInstance(_instanceName)) != <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="807" href="#807">807</a>       {
+<a class="jxr_linenumber" name="808" href="#808">808</a>         String errorMessage =
+<a class="jxr_linenumber" name="809" href="#809">809</a>             <span class="jxr_string">"instance "</span> + _instanceName + <span class="jxr_string">" already has a liveinstance in cluster "</span>
+<a class="jxr_linenumber" name="810" href="#810">810</a>                 + _clusterName;
+<a class="jxr_linenumber" name="811" href="#811">811</a>         logger.error(errorMessage);
+<a class="jxr_linenumber" name="812" href="#812">812</a>         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/HelixException.html">HelixException</a>(errorMessage);
+<a class="jxr_linenumber" name="813" href="#813">813</a>       }
+<a class="jxr_linenumber" name="814" href="#814">814</a>     }
+<a class="jxr_linenumber" name="815" href="#815">815</a>     <em class="jxr_comment">// Invoke the PreConnectCallbacks</em>
+<a class="jxr_linenumber" name="816" href="#816">816</a>     <strong class="jxr_keyword">for</strong> (PreConnectCallback callback : _preConnectCallbacks)
+<a class="jxr_linenumber" name="817" href="#817">817</a>     {
+<a class="jxr_linenumber" name="818" href="#818">818</a>       callback.onPreConnect();
+<a class="jxr_linenumber" name="819" href="#819">819</a>     }
+<a class="jxr_linenumber" name="820" href="#820">820</a>     addLiveInstance();
+<a class="jxr_linenumber" name="821" href="#821">821</a>     carryOverPreviousCurrentState();
+<a class="jxr_linenumber" name="822" href="#822">822</a> 
+<a class="jxr_linenumber" name="823" href="#823">823</a>     <em class="jxr_comment">// In case the cluster manager is running as a participant, setup message</em>
+<a class="jxr_linenumber" name="824" href="#824">824</a>     <em class="jxr_comment">// listener</em>
+<a class="jxr_linenumber" name="825" href="#825">825</a>     _messagingService.registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
+<a class="jxr_linenumber" name="826" href="#826">826</a>                                                     _stateMachEngine);
+<a class="jxr_linenumber" name="827" href="#827">827</a>     addMessageListener(_messagingService.getExecutor(), _instanceName);
+<a class="jxr_linenumber" name="828" href="#828">828</a>     addControllerListener(_helixAccessor);
+<a class="jxr_linenumber" name="829" href="#829">829</a>     
+<a class="jxr_linenumber" name="830" href="#830">830</a>     <a href="../../../../../org/apache/helix/participant/statemachine/ScheduledTaskStateModelFactory.html">ScheduledTaskStateModelFactory</a> stStateModelFactory = <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/participant/statemachine/ScheduledTaskStateModelFactory.html">ScheduledTaskStateModelFactory</a>(_messagingService.getExecutor());
+<a class="jxr_linenumber" name="831" href="#831">831</a>     _stateMachEngine.registerStateModelFactory(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE, stStateModelFactory);
+<a class="jxr_linenumber" name="832" href="#832">832</a> 
+<a class="jxr_linenumber" name="833" href="#833">833</a>     <strong class="jxr_keyword">if</strong> (_participantHealthCheckInfoCollector == <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="834" href="#834">834</a>     {
+<a class="jxr_linenumber" name="835" href="#835">835</a>       _participantHealthCheckInfoCollector =
+<a class="jxr_linenumber" name="836" href="#836">836</a>           <strong class="jxr_keyword">new</strong> <a href="../../../../../org/apache/helix/healthcheck/ParticipantHealthReportCollectorImpl.html">ParticipantHealthReportCollectorImpl</a>(<strong class="jxr_keyword">this</strong>, _instanceName);
+<a class="jxr_linenumber" name="837" href="#837">837</a>       _participantHealthCheckInfoCollector.start();
+<a class="jxr_linenumber" name="838" href="#838">838</a>     }
+<a class="jxr_linenumber" name="839" href="#839">839</a>     <em class="jxr_comment">// start the participant health check timer, also create zk path for health</em>
+<a class="jxr_linenumber" name="840" href="#840">840</a>     <em class="jxr_comment">// check info</em>
+<a class="jxr_linenumber" name="841" href="#841">841</a>     String healthCheckInfoPath =
+<a class="jxr_linenumber" name="842" href="#842">842</a>         _helixAccessor.keyBuilder().healthReports(_instanceName).getPath();
+<a class="jxr_linenumber" name="843" href="#843">843</a>     <strong class="jxr_keyword">if</strong> (!_zkClient.exists(healthCheckInfoPath))
+<a class="jxr_linenumber" name="844" href="#844">844</a>     {
+<a class="jxr_linenumber" name="845" href="#845">845</a>       _zkClient.createPersistent(healthCheckInfoPath, <strong class="jxr_keyword">true</strong>);
+<a class="jxr_linenumber" name="846" href="#846">846</a>       logger.info(<span class="jxr_string">"Creating healthcheck info path "</span> + healthCheckInfoPath);
+<a class="jxr_linenumber" name="847" href="#847">847</a>     }
+<a class="jxr_linenumber" name="848" href="#848">848</a>   }
+<a class="jxr_linenumber" name="849" href="#849">849</a> 
+<a class="jxr_linenumber" name="850" href="#850">850</a>   @Override
+<a class="jxr_linenumber" name="851" href="#851">851</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> addPreConnectCallback(<a href="../../../../../org/apache/helix/PreConnectCallback.html">PreConnectCallback</a> callback)
+<a class="jxr_linenumber" name="852" href="#852">852</a>   {
+<a class="jxr_linenumber" name="853" href="#853">853</a>     logger.info(<span class="jxr_string">"Adding preconnect callback"</span>);
+<a class="jxr_linenumber" name="854" href="#854">854</a>     _preConnectCallbacks.add(callback);
+<a class="jxr_linenumber" name="855" href="#855">855</a>   }
+<a class="jxr_linenumber" name="856" href="#856">856</a> 
+<a class="jxr_linenumber" name="857" href="#857">857</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> resetHandlers()
+<a class="jxr_linenumber" name="858" href="#858">858</a>   {
+<a class="jxr_linenumber" name="859" href="#859">859</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
+<a class="jxr_linenumber" name="860" href="#860">860</a>     {
+<a class="jxr_linenumber" name="861" href="#861">861</a>     	<strong class="jxr_keyword">if</strong> (_handlers != <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="862" href="#862">862</a>         {
+<a class="jxr_linenumber" name="863" href="#863">863</a>             <em class="jxr_comment">// get a copy of the list and iterate over the copy list</em>
+<a class="jxr_linenumber" name="864" href="#864">864</a>             <em class="jxr_comment">// in case handler.reset() will modify the original handler list</em>
+<a class="jxr_linenumber" name="865" href="#865">865</a>             List&lt;CallbackHandler&gt; tmpHandlers = <strong class="jxr_keyword">new</strong> ArrayList&lt;CallbackHandler&gt;();
+<a class="jxr_linenumber" name="866" href="#866">866</a>             tmpHandlers.addAll(_handlers);
+<a class="jxr_linenumber" name="867" href="#867">867</a> 
+<a class="jxr_linenumber" name="868" href="#868">868</a>             <strong class="jxr_keyword">for</strong> (CallbackHandler handler : tmpHandlers)
+<a class="jxr_linenumber" name="869" href="#869">869</a>             {
+<a class="jxr_linenumber" name="870" href="#870">870</a>               handler.reset();
+<a class="jxr_linenumber" name="871" href="#871">871</a>               logger.info(<span class="jxr_string">"reset handler: "</span> + handler.getPath() + <span class="jxr_string">", "</span> + handler.getListener());
+<a class="jxr_linenumber" name="872" href="#872">872</a>             }
+<a class="jxr_linenumber" name="873" href="#873">873</a>         }
+<a class="jxr_linenumber" name="874" href="#874">874</a>     }
+<a class="jxr_linenumber" name="875" href="#875">875</a>   }
+<a class="jxr_linenumber" name="876" href="#876">876</a> 
+<a class="jxr_linenumber" name="877" href="#877">877</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> initHandlers()
+<a class="jxr_linenumber" name="878" href="#878">878</a>   {
+<a class="jxr_linenumber" name="879" href="#879">879</a>     <strong class="jxr_keyword">synchronized</strong> (<strong class="jxr_keyword">this</strong>)
+<a class="jxr_linenumber" name="880" href="#880">880</a>     {
+<a class="jxr_linenumber" name="881" href="#881">881</a>     	<strong class="jxr_keyword">if</strong> (_handlers != <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="882" href="#882">882</a>     	{
+<a class="jxr_linenumber" name="883" href="#883">883</a>     	  <em class="jxr_comment">// may add new currentState and message listeners during init()</em>
+<a class="jxr_linenumber" name="884" href="#884">884</a>     	  <em class="jxr_comment">// so make a copy and iterate over the copy</em>
+<a class="jxr_linenumber" name="885" href="#885">885</a>     	  List&lt;CallbackHandler&gt; tmpHandlers = <strong class="jxr_keyword">new</strong> ArrayList&lt;CallbackHandler&gt;();
+<a class="jxr_linenumber" name="886" href="#886">886</a>     	  tmpHandlers.addAll(_handlers);
+<a class="jxr_linenumber" name="887" href="#887">887</a>           <strong class="jxr_keyword">for</strong> (CallbackHandler handler : tmpHandlers)
+<a class="jxr_linenumber" name="888" href="#888">888</a>           {
+<a class="jxr_linenumber" name="889" href="#889">889</a>             handler.init();
+<a class="jxr_linenumber" name="890" href="#890">890</a>             logger.info(<span class="jxr_string">"init handler: "</span> + handler.getPath() + <span class="jxr_string">", "</span> + handler.getListener());
+<a class="jxr_linenumber" name="891" href="#891">891</a>           }
+<a class="jxr_linenumber" name="892" href="#892">892</a>     	}
+<a class="jxr_linenumber" name="893" href="#893">893</a>     }
+<a class="jxr_linenumber" name="894" href="#894">894</a>   }
+<a class="jxr_linenumber" name="895" href="#895">895</a> 
+<a class="jxr_linenumber" name="896" href="#896">896</a>   @Override
+<a class="jxr_linenumber" name="897" href="#897">897</a>   <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> isLeader()
+<a class="jxr_linenumber" name="898" href="#898">898</a>   {
+<a class="jxr_linenumber" name="899" href="#899">899</a>     <strong class="jxr_keyword">if</strong> (!isConnected())
+<a class="jxr_linenumber" name="900" href="#900">900</a>     {
+<a class="jxr_linenumber" name="901" href="#901">901</a>       <strong class="jxr_keyword">return</strong> false;
+<a class="jxr_linenumber" name="902" href="#902">902</a>     }
+<a class="jxr_linenumber" name="903" href="#903">903</a> 
+<a class="jxr_linenumber" name="904" href="#904">904</a>     <strong class="jxr_keyword">if</strong> (_instanceType != InstanceType.CONTROLLER)
+<a class="jxr_linenumber" name="905" href="#905">905</a>     {
+<a class="jxr_linenumber" name="906" href="#906">906</a>       <strong class="jxr_keyword">return</strong> false;
+<a class="jxr_linenumber" name="907" href="#907">907</a>     }
+<a class="jxr_linenumber" name="908" href="#908">908</a> 
+<a class="jxr_linenumber" name="909" href="#909">909</a>     <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a> keyBuilder = _helixAccessor.keyBuilder();
+<a class="jxr_linenumber" name="910" href="#910">910</a>     <a href="../../../../../org/apache/helix/model/LiveInstance.html">LiveInstance</a> leader = _helixAccessor.getProperty(keyBuilder.controllerLeader());
+<a class="jxr_linenumber" name="911" href="#911">911</a>     <strong class="jxr_keyword">if</strong> (leader == <strong class="jxr_keyword">null</strong>)
+<a class="jxr_linenumber" name="912" href="#912">912</a>     {
+<a class="jxr_linenumber" name="913" href="#913">913</a>       <strong class="jxr_keyword">return</strong> false;
+<a class="jxr_linenumber" name="914" href="#914">914</a>     }
+<a class="jxr_linenumber" name="915" href="#915">915</a>     <strong class="jxr_keyword">else</strong>
 <a class="jxr_linenumber" name="916" href="#916">916</a>     {
-<a class="jxr_linenumber" name="917" href="#917">917</a>       <strong class="jxr_keyword">return</strong> false;
-<a class="jxr_linenumber" name="918" href="#918">918</a>     }
-<a class="jxr_linenumber" name="919" href="#919">919</a>     <strong class="jxr_keyword">else</strong>
-<a class="jxr_linenumber" name="920" href="#920">920</a>     {
-<a class="jxr_linenumber" name="921" href="#921">921</a>       String leaderName = leader.getInstanceName();
-<a class="jxr_linenumber" name="922" href="#922">922</a>       <em class="jxr_comment">// TODO need check sessionId also, but in distributed mode, leader's</em>
-<a class="jxr_linenumber" name="923" href="#923">923</a>       <em class="jxr_comment">// sessionId is</em>
-<a class="jxr_linenumber" name="924" href="#924">924</a>       <em class="jxr_comment">// not equal to</em>
-<a class="jxr_linenumber" name="925" href="#925">925</a>       <em class="jxr_comment">// the leader znode's sessionId field which is the sessionId of the</em>
-<a class="jxr_linenumber" name="926" href="#926">926</a>       <em class="jxr_comment">// controller_participant that</em>
-<a class="jxr_linenumber" name="927" href="#927">927</a>       <em class="jxr_comment">// successfully creates the leader node</em>
-<a class="jxr_linenumber" name="928" href="#928">928</a>       <strong class="jxr_keyword">if</strong> (leaderName == <strong class="jxr_keyword">null</strong> || !leaderName.equals(_instanceName))
-<a class="jxr_linenumber" name="929" href="#929">929</a>       {
-<a class="jxr_linenumber" name="930" href="#930">930</a>         <strong class="jxr_keyword">return</strong> false;
-<a class="jxr_linenumber" name="931" href="#931">931</a>       }
-<a class="jxr_linenumber" name="932" href="#932">932</a>     }
-<a class="jxr_linenumber" name="933" href="#933">933</a>     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
-<a class="jxr_linenumber" name="934" href="#934">934</a>   }
-<a class="jxr_linenumber" name="935" href="#935">935</a> 
-<a class="jxr_linenumber" name="936" href="#936">936</a>   <em class="jxr_javadoccomment">/**</em>
-<a class="jxr_linenumber" name="937" href="#937">937</a> <em class="jxr_javadoccomment">   * carry over current-states from last sessions</em>
-<a class="jxr_linenumber" name="938" href="#938">938</a> <em class="jxr_javadoccomment">   * set to initial state for current session only when the state doesn't exist in current session</em>
-<a class="jxr_linenumber" name="939" href="#939">939</a> <em class="jxr_javadoccomment">   */</em>
-<a class="jxr_linenumber" name="940" href="#940">940</a>   <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">void</strong> carryOverPreviousCurrentState()
-<a class="jxr_linenumber" name="941" href="#941">941</a>   {
-<a class="jxr_linenumber" name="942" href="#942">942</a>     <a href="../../../../../org/apache/helix/PropertyKey.html">Builder</a> keyBuilder = _helixAccessor.keyBuilder();
-<a class="jxr_linenumber" name="943" href="#943">943</a>     List&lt;String&gt; sessions = _helixAccessor.getChildNames(keyBuilder.sessions(_instanceName));
-<a class="jxr_linenumber" name="944" href="#944">944</a>     
-<a class="jxr_linenumber" name="945" href="#945">945</a>     <em class="jxr_comment">// carry-over</em>
-<a class="jxr_linenumber" name="946" href="#946">946</a>     <strong class="jxr_keyword">for</strong> (String session : sessions) {
-<a class="jxr_linenumber" name="947" href="#947">947</a>       <strong class="jxr_keyword">if</strong> (session.equals(_sessionId)) {
-<a class="jxr_linenumber" name="948" href="#948">948</a>         <strong class="jxr_keyword">continue</strong>;
-<a class="jxr_linenumber" name="949" href="#949">949</a>       }
-<a class="jxr_linenumber" name="950" href="#950">950</a>       
-<a class="jxr_linenumber" name="951" href="#951">951</a>       List&lt;CurrentState&gt; lastCurStates = 
-<a class="jxr_linenumber" name="952" href="#952">952</a>           _helixAccessor.getChildValues(keyBuilder.currentStates(_instanceName, session));
-<a class="jxr_linenumber" name="953" href="#953">953</a> 
-<a class="jxr_linenumber" name="954" href="#954">954</a>       <strong class="jxr_keyword">for</strong> (CurrentState lastCurState : lastCurStates) {
-<a class="jxr_linenumber" name="955" href="#955">955</a>         logger.info(<span class="jxr_string">"Carrying over old session: "</span> + session + <span class="jxr_string">", resource: "</span>
-<a class="jxr_linenumber" name="956" href="#956">956</a>             + lastCurState.getId() + <span class="jxr_string">" to current session: "</span> + _sessionId);
-<a class="jxr_linenumber" name="957" href="#957">957</a>         String stateModelDefRef = lastCurState.getStateModelDefRef();
-<a class="jxr_linenumber" name="958" href="#958">958</a>         <strong class="jxr_keyword">if</strong> (stateModelDefRef == <strong class="jxr_keyword">null</strong>)
-<a class="jxr_linenumber" name="959" href="#959">959</a>         {
-<a class="jxr_linenumber" name="960" href="#960">960</a>           logger.error(<span class="jxr_string">"skip carry-over because previous current state doesn't have a state model definition. previous current-state: "</span>
-<a class="jxr_linenumber" name="961" href="#961">961</a>               + lastCurState);
-<a class="jxr_linenumber" name="962" href="#962">962</a>           <strong class="jxr_keyword">continue</strong>;
-<a class="jxr_linenumber" name="963" href="#963">963</a>         }
-<a class="jxr_linenumber" name="964" href="#964">964</a>         <a href="../../../../../org/apache/helix/model/StateModelDefinition.html">StateModelDefinition</a> stateModel =
-<a class="jxr_linenumber" name="965" href="#965">965</a>             _helixAccessor.getProperty(keyBuilder.stateModelDef(stateModelDefRef));
-<a class="jxr_linenumber" name="966" href="#966">966</a> 
-<a class="jxr_linenumber" name="967" href="#967">967</a>         String curStatePath = keyBuilder.currentState(_instanceName, _sessionId, lastCurState.getResourceName()).getPath();
-<a class="jxr_linenumber" name="968" href="#968">968</a>         _helixAccessor.getBaseDataAccessor().update(curStatePath, 

[... 306 lines stripped ...]


Mime
View raw message