/**
  * File: CoordinatorElectorBaseImpl.java
  * Content: Defines an abstract rmi class to implement the CoordinatorElector interface
  * Author: LuisM Pena
  * Date: 28th October 2001
  * Version:  0.51.00
  * Last change:
  *
  **/

package sensei.middleware.domains;

import java.rmi.server.UnicastRemoteObject;

/**
  * Implementation of the CoordinatorElector RMI interface.
  **/
public abstract class CoordinatorElectorBaseImpl extends UnicastRemoteObject implements CoordinatorElector
{

  public CoordinatorElectorBaseImpl() throws Exception
  {
    thisCoordinatorElector=this;
  }

  public CoordinatorElectorBaseImpl(boolean activate) throws Exception
  {
    if (!activate)
      deactivate();
  }

  public void activate() throws Exception
  {
    if (thisCoordinatorElector==null)
    {
      thisCoordinatorElector=this;
      exportObject(this);
    }
  }

  public void deactivate() throws Exception
  {
    synchronized (this)
    {
      if (thisCoordinatorElector!=null)
        unexportObject(thisCoordinatorElector,true);
      thisCoordinatorElector=null;
    }
  }

  public final CoordinatorElector theCoordinatorElector()
  {
    return thisCoordinatorElector;
  }

  protected CoordinatorElector thisCoordinatorElector;
};