All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.dyade.aaa.agent.CallbackNotification Maven / Gradle / Ivy

There is a newer version: 5.22.1
Show newest version
/*
 * Copyright (C) 2013 ScalAgent Distributed Technologies
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA.
 *
 * Initial developer(s): ScalAgent Distributed Technologies
 * Contributor(s): 
 */
package fr.dyade.aaa.agent;

/**
 * Notification locally transmitting a CountDownCallback. The
 * CountDownCallback is not persistent and is not transmitted to a
 * remote destination. If sent to a remote destination, the
 * CountDownCallback should be decremented either after the
 * notification has been successfully transmitted, or if a transmission error
 * has been raised. A CountDownCallback can be transmitted in
 * several CallbackNotification instances. In that case it is
 * incremented and decremented once for every CallbackNotification.
 */
public class CallbackNotification extends Notification {
  
  private transient CountDownCallback countDownCallback;

  /**
   * Returns true if a CountDownCallback is
   * transmitted, false otherwise.
   * 
   * @return true if a CountDownCallback is
   *         transmitted, false otherwise
   */
  public boolean hasCallback() {
    return (countDownCallback != null);
  }
  
  /**
   * Passes the CountDownCallback to the specified
   * CallbackNotification.
   * 
   * @param not
   *          the CallbackNotification to be assigned with the
   *          CountDownCallback owned by this
   *          CallbackNotification
   */
  public void passCallback(CallbackNotification not) {
    not.setCountDownCallback(countDownCallback);
  }

  /**
   * Sets the CountDownCallback to be transmitted by this
   * CallbackNotification.
   * 
   * @param the
   *          CountDownCallback to transmit
   */
  public void setCountDownCallback(CountDownCallback countDownCallback) {
    if (countDownCallback != null) {
      countDownCallback.incrementAndGet();
      this.countDownCallback = countDownCallback;
    }
  }
  
  /**
   * Called if this CallbackNotification is successfully processed.
   */
  public void done() {
    if (countDownCallback != null) {
      countDownCallback.done();
      countDownCallback = null;
    }
  }
  
  /**
   * Called if this CallbackNotification raises an error.
   * @param error the error that has been raised
   */
  public void failed(Throwable error) {
    if (countDownCallback != null) {
      countDownCallback.failed(error);
      countDownCallback = null;
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy