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

org.objectweb.dream.pump.PumpPeriodicSynchronized 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): Vivien Quema
 */

package org.objectweb.dream.pump;

import java.util.HashMap;
import java.util.Map;

import org.objectweb.dream.control.activity.Util;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.fraclet.annotation.annotations.Attribute;
import org.objectweb.dream.dreamannotation.DreamComponent;
import org.objectweb.dream.dreamannotation.DreamLifeCycle;
import org.objectweb.dream.dreamannotation.util.DreamLifeCycleType;
import org.objectweb.util.monolog.api.BasicLevel;

/**
 * Implementation of a periodic pump: every T  ms, a message is pulled on
 * the input and is then pushed on the output. If these two actions (pull then
 * push) are longer than T  ms, an other message is pulled immediately.
 * 

* * @see AbstractPumpSynchronized */ @DreamComponent(controllerDesc = "activeDreamPrimitive") public class PumpPeriodicSynchronized extends AbstractPumpSynchronized { // --------------------------------------------------------------------------- // Attributes // --------------------------------------------------------------------------- // TODO : remove these first three attributes when attributes inheritance // works in fraclet /** * The PushNullPolicy indicates whether "null" messages that * are pulled must be pushed or not. Its default value is false. */ @Attribute(argument = "pushNullPolicy") protected boolean pushNullPolicy = false; /** * The StopOnPushExceptionPolicy indicates whether the task * must be stopped when a {@link org.objectweb.dream.PushException} occurs. * Its default value is true. */ @Attribute(argument = "stopOnPushExceptionPolicy") protected boolean stopOnPushExceptionPolicy = true; /** * The StopOnPullExceptionPolicy indicates whether the task * must be stopped when a {@link org.objectweb.dream.PullException} occurs. * Its default value is true. */ @Attribute(argument = "stopOnPullExceptionPolicy") protected boolean stopOnPullExceptionPolicy = true; /** * The period in milliseconds between two pull */ @Attribute(argument = "period") protected long period = -1; // --------------------------------------------------------------------------- // Overriding of the PumpAttributeControllerPeriodic interface // generated by fraclet // --------------------------------------------------------------------------- /** * Overriding of the PumpAttributeControllerPeriodic interface * generated by fraclet. It checks that period is a positive value */ public void setPeriod(long period) { if (period < 0) { throw new IllegalArgumentException("Period value negative"); } this.period = period; } // ------------------------------------------------------------------------- // Implementation of the LifeCycleController interface. // ------------------------------------------------------------------------- /** * @see org.objectweb.dream.AbstractComponent#beforeFirstStart(Component) */ @DreamLifeCycle(on=DreamLifeCycleType.FIRST_START) public void beforeFirstStart(Component componentItf) throws IllegalLifeCycleException { try { Map hints = new HashMap(); hints.put("period", Long.valueOf(period)); Util.addTask(componentItf, pumpTask, hints); } catch (Exception e) { logger.log(BasicLevel.ERROR, "Unable to register the periodic pump task", e); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy