Package de.danet.an.workflow.tools.timing

Source Code of de.danet.an.workflow.tools.timing.TimerCreator

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2004 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: TimerCreator.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.2  2004/10/20 20:39:57  drmlipp
* Added debug info.
*
* Revision 1.1.1.1  2004/08/18 15:17:39  drmlipp
* Update to 1.2
*
* Revision 1.5  2004/04/13 14:34:23  lipp
* Added DirectInvocable support.
*
* Revision 1.4  2004/04/12 19:33:52  lipp
* Clarified application invocation interface.
*
* Revision 1.3  2004/03/31 19:36:20  lipp
* Completed implementation of Activity.abandon(String).
*
* Revision 1.2  2004/02/24 13:51:21  lipp
* Fixed typo.
*
* Revision 1.1  2004/02/20 18:56:35  lipp
* Renamed package waittool to timing (much better ;-)).
*
* Revision 1.4  2004/02/20 15:58:22  lipp
* Several WaitTool fixes.
*
* Revision 1.3  2004/02/19 21:14:48  lipp
* Several WaitTool fixes.
*
* Revision 1.2  2004/02/19 18:06:42  lipp
* Fixed application name handling.
*
* Revision 1.1  2004/02/19 17:55:55  lipp
* Initial version of waittool.
*
*/
package de.danet.an.workflow.tools.timing;

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

import java.rmi.RemoteException;

import de.danet.an.workflow.api.Activity;
import de.danet.an.workflow.api.FormalParameter;
import de.danet.an.workflow.api.InvalidKeyException;

import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
import de.danet.an.workflow.spis.aii.CannotExecuteException;
import de.danet.an.workflow.spis.aii.ResultProvider;
import de.danet.an.workflow.tools.util.DirectInvocable;

/**
* This class provides a tool agent that creates a timer.
*
* @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
* @version $Revision: 1607 $
*/

public class TimerCreator extends ToolAgentBase
    implements ResultProvider, DirectInvocable {

    private static final org.apache.commons.logging.Log logger
  = org.apache.commons.logging.LogFactory.getLog(TimerCreator.class);

    /** The result container. */
    private ThreadLocal result = new ThreadLocal ();
   
    /**
     * Creates an instance of <code>TimerCreator</code>
     * with all attributes initialized to default values.
     */
    public TimerCreator () {
    }
   
    /**
     * Executes the tool.
     *
     * @param activity an <code>Activity</code> value
     * @param fps the formal parameters
     * @param map a <code>Map</code> value
     * @exception CannotExecuteException if an error occurs
     * @exception RemoteException if an error occurs
     */
    public void invoke
  (Activity activity, FormalParameter[] fps, Map map)
  throws CannotExecuteException, RemoteException {
  try {
      if (fps[0].mode() == FormalParameter.Mode.IN
    || fps[0].type() != Long.class
    || fps[1].mode() == FormalParameter.Mode.OUT
    || fps[1].type() != Date.class) {
    throw new CannotExecuteException
        ("First parameter must be OUT or INOUT (is "
         + fps[0].mode() + ") and of type INTEGER (is "
         + fps[0].type() + ", "
         + "second parameter must be IN or INOUT (is "
         + fps[1].mode() + ") and of type STRING (is "
         + fps[1].type() + ")");
      }
      Date waitUntil = (Date)map.get(fps[1].id());
      if (logger.isDebugEnabled ()) {
    logger.debug ("Creating timer for " + waitUntil);
      }
      long applId = applicationDirectory().registerInstance
    (WaitTool.class.getName(), activity, null, false);
      if (logger.isDebugEnabled()) {
    logger.debug ("Application " + applId
            + " created for " + activity);
      }
      Object timer = timerHandler().createTimer (applId, waitUntil);
      applicationDirectory().updateState
    (applId, new Object[] { timer, null });
      applicationDirectory().updateInvokingActivity (applId, null);
      Map res = new HashMap ();
      res.put (fps[0].id(), new Long (applId));
      result.set (res);
  } catch (InvalidKeyException e) {
      String msg = "Cannot use newly created key?!: " + e.getMessage ();
      logger.error (msg);
      throw new CannotExecuteException (msg);
  }
    }

    /**
     * Application cannot be terminated, throws exception.
     *
     * @param activity the activity to be canceled
     * @throws ApplicationNotStoppedException if execution cannot be
     * terminated (see {@link ApplicationNotStoppedException
     * <code>ApplicationNotStoppedException</code>}).
     */
    public void terminate (Activity activity)
  throws ApplicationNotStoppedException {
  throw new ApplicationNotStoppedException
      ("Cannot terminate TimerCreator");
    }
   
    // Implementation of de.danet.an.workflow.spis.aii.ResultProvider

    /**
     * Returns the result.
     *
     * @return a <code>Map</code> value
     */
    public Object result() {
  Map res = (Map)result.get();
  result.set (null);
  return res;
    }
   
}
TOP

Related Classes of de.danet.an.workflow.tools.timing.TimerCreator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.