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

  public CheckpointableBaseImpl() throws Exception
  {
    thisCheckpointable=this;
  }

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

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

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

  public final Checkpointable theCheckpointable()
  {
    return thisCheckpointable;
  }

  protected Checkpointable thisCheckpointable;
};