/**
  * File: StateHandlerBaseImpl.java
  * Content: Defines an abstract rmi class to implement the StateHandler 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 StateHandler RMI interface.
  **/
public abstract class StateHandlerBaseImpl extends UnicastRemoteObject implements StateHandler
{

  public StateHandlerBaseImpl() throws Exception
  {
    thisStateHandler=this;
  }

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

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

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

  public final StateHandler theStateHandler()
  {
    return thisStateHandler;
  }

  protected StateHandler thisStateHandler;
};