You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geode.apache.org by Anthony Baker <me...@yahoo.com> on 2015/06/27 15:40:30 UTC

HAComponent?

Has anyone used (or needed) an HAComponent pattern before?  The object would be instantiated on each member of the cluster but only “activated” on one node.  If that node fails or is shutdown another member will automatically activate its instance.  The distributed lock service could be used to arbitrate access something like this:


  /**
   * Invoke to activate a component. Only one instance of the component is
   * allowed to be active in the distributed system at any given time. This
   * method blocks until the component is activated on this member or the
   * component is released.
   * 
   * @param ds
   *          the distributed system
   * @param retryDelay
   *          the retry delay in millis
   */
  protected void activate(DistributedSystem ds, int retryDelay) {
    DistributedLockService dls = DistributedLockService.create(DLS_SERVICE, ds);
    while (!abort && !Thread.interrupted()) {
      if (dls.lock(getClass().getName(), retryDelay, -1)) {
        locked = true;
        return;
      }
    }
  }


Anthony


Re: HAComponent?

Posted by md...@pivotal.io.
I've used it for job scheduling for Quartz as well.


> On Jun 27, 2015, at 06:46, Lyndon Adams <ly...@gmail.com> wrote:
> 
> And if fact I used this for Lucene index rebuilds on VM failures.
> 
> Sent from my iPhone
> 
>> On 27 Jun 2015, at 14:44, Lyndon Adams <ly...@gmail.com> wrote:
>> 
>> Yes I have needed this before and written code to support this function.
>> 
>> Sent from my iPhone
>> 
>>> On 27 Jun 2015, at 14:40, Anthony Baker <me...@yahoo.com> wrote:
>>> 
>>> Has anyone used (or needed) an HAComponent pattern before?  The object would be instantiated on each member of the cluster but only “activated” on one node.  If that node fails or is shutdown another member will automatically activate its instance.  The distributed lock service could be used to arbitrate access something like this:
>>> 
>>> 
>>>   /**
>>>    * Invoke to activate a component. Only one instance of the component is
>>>    * allowed to be active in the distributed system at any given time. This
>>>    * method blocks until the component is activated on this member or the
>>>    * component is released.
>>>    * 
>>>    * @param ds
>>>    *          the distributed system
>>>    * @param retryDelay
>>>    *          the retry delay in millis
>>>    */
>>>   protected void activate(DistributedSystem ds, int retryDelay) {
>>>     DistributedLockService dls = DistributedLockService.create(DLS_SERVICE, ds);
>>>     while (!abort && !Thread.interrupted()) {
>>>       if (dls.lock(getClass().getName(), retryDelay, -1)) {
>>>         locked = true;
>>>         return;
>>>       }
>>>     }
>>>   }
>>> 
>>> 
>>> Anthony
>>> 

Re: HAComponent?

Posted by Lyndon Adams <ly...@gmail.com>.
And if fact I used this for Lucene index rebuilds on VM failures.

Sent from my iPhone

> On 27 Jun 2015, at 14:44, Lyndon Adams <ly...@gmail.com> wrote:
> 
> Yes I have needed this before and written code to support this function.
> 
> Sent from my iPhone
> 
>> On 27 Jun 2015, at 14:40, Anthony Baker <me...@yahoo.com> wrote:
>> 
>> Has anyone used (or needed) an HAComponent pattern before?  The object would be instantiated on each member of the cluster but only “activated” on one node.  If that node fails or is shutdown another member will automatically activate its instance.  The distributed lock service could be used to arbitrate access something like this:
>> 
>> 
>>   /**
>>    * Invoke to activate a component. Only one instance of the component is
>>    * allowed to be active in the distributed system at any given time. This
>>    * method blocks until the component is activated on this member or the
>>    * component is released.
>>    * 
>>    * @param ds
>>    *          the distributed system
>>    * @param retryDelay
>>    *          the retry delay in millis
>>    */
>>   protected void activate(DistributedSystem ds, int retryDelay) {
>>     DistributedLockService dls = DistributedLockService.create(DLS_SERVICE, ds);
>>     while (!abort && !Thread.interrupted()) {
>>       if (dls.lock(getClass().getName(), retryDelay, -1)) {
>>         locked = true;
>>         return;
>>       }
>>     }
>>   }
>> 
>> 
>> Anthony
>> 

Re: HAComponent?

Posted by Lyndon Adams <ly...@gmail.com>.
Yes I have needed this before and written code to support this function.

Sent from my iPhone

> On 27 Jun 2015, at 14:40, Anthony Baker <me...@yahoo.com> wrote:
> 
> Has anyone used (or needed) an HAComponent pattern before?  The object would be instantiated on each member of the cluster but only “activated” on one node.  If that node fails or is shutdown another member will automatically activate its instance.  The distributed lock service could be used to arbitrate access something like this:
> 
> 
>   /**
>    * Invoke to activate a component. Only one instance of the component is
>    * allowed to be active in the distributed system at any given time. This
>    * method blocks until the component is activated on this member or the
>    * component is released.
>    * 
>    * @param ds
>    *          the distributed system
>    * @param retryDelay
>    *          the retry delay in millis
>    */
>   protected void activate(DistributedSystem ds, int retryDelay) {
>     DistributedLockService dls = DistributedLockService.create(DLS_SERVICE, ds);
>     while (!abort && !Thread.interrupted()) {
>       if (dls.lock(getClass().getName(), retryDelay, -1)) {
>         locked = true;
>         return;
>       }
>     }
>   }
> 
> 
> Anthony
>