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

org.objectweb.dream.exception.RetryPush Maven / Gradle / Ivy

/**
 * Dream
 * Copyright (C) 2003-2004 INRIA Rhone-Alpes
 *
 * 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 of the License, or (at your option) 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
 *
 * Contact: [email protected]
 *
 * Initial developer(s): Matthieu Leclercq
 * Contributor(s): Romain Lenglet
 */

package org.objectweb.dream.exception;

import org.objectweb.dream.Push;
import org.objectweb.dream.PushException;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.dreamannotation.DreamMonolog;
import org.objectweb.dream.message.Message;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
import org.objectweb.fractal.fraclet.annotation.annotations.Requires;
import org.objectweb.fractal.fraclet.annotation.annotations.Service;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;

/**
 * This component forwards incoming messages, if a {@link PushException }is
 * catched, the message is pushed again. If a {@link PushException }occurs a
 * second time, it is thrown.
 */
@DreamComponent(controllerDesc = "dreamPrimitive")
@Provides(interfaces={@Interface(name="in-push", signature=Push.class)})
public class RetryPush implements Push
{

  // ---------------------------------------------------------------------------
  // Client interface
  // ---------------------------------------------------------------------------
  @Requires(name = "out-push")
  protected Push outPushItf;
  
  // --------------------------------------------------------------------------
  // Services interfaces
  // --------------------------------------------------------------------------    
  
  /**
   * Component reference
   */
  @Service
  Component weaveableC;
  
  /**
   * Logger "impl"
   */ 
  @DreamMonolog()
  protected Logger                   logger;  

  // ---------------------------------------------------------------------------
  // Implementation of the Push interface
  // ---------------------------------------------------------------------------

  /**
   * @see Push#push(Message)
   */
  public void push(Message message) throws PushException
  {
    try
    {
      outPushItf.push(message);
    }
    catch (PushException e)
    {
      logger.log(BasicLevel.WARN, "Catched Push Exception retry immediatly. ",
          e);
      outPushItf.push(message);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy