Package de.danet.an.workflow.tools.util

Source Code of de.danet.an.workflow.tools.util.SimpleApplicationAgent

/*
* 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: SimpleApplicationAgent.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1  2004/08/18 15:17:39  drmlipp
* Update to 1.2
*
* Revision 1.2  2004/04/08 09:34:54  lipp
* Clarified documentation of package structure.
*
* Revision 1.1  2004/02/19 17:55:54  lipp
* Initial version of waittool.
*
*/
package de.danet.an.workflow.tools.util;

import java.rmi.RemoteException;

import de.danet.an.util.EJBUtil;
import de.danet.an.util.ResourceNotAvailableException;

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

import de.danet.an.workflow.spis.aii.ApplicationNotStoppedException;
import de.danet.an.workflow.spis.aii.ToolAgent;

/**
* This is a base class for writing agents for applications that have
* a life cycle exceeding a single tool agent invocation, and have only
* state information that can efficiently be persisted as a binary
* large object in an RDBMs.<P>
*
* An example for such an application is the wait tool (see <i>User
* Manual</i>). A wait tool (or "wait application") is created by one
* tool agent invocation.  Then another tool agent invocation waits
* for the completion of the wait, while yet another tool agent
* invocation may cause the wait tool to complete prematurely. The
* wait tool has state that is controlled by the tool agents and a
* timer provided by the enviroment. Its state is therefore completely
* serializable (no open sockets, tool controlled threads etc.).<P>
*
* This base class mainly provides access to the {@link
* SimpleApplicationDirectory application directory} that does all the
* important work.
*
* @author <a href="mailto:lipp@danet.de">Michael Lipp</a>
* @version $Revision: 1607 $
*/

public abstract class SimpleApplicationAgent implements ToolAgent {

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

    /** Application directory. */
    private SimpleApplicationDirectoryLocal applDirCache = null;
   
    /**
     * Creates an instance of <code>SimpleApplicationAgent</code>
     * with all attributes initialized to default values.
     */
    public SimpleApplicationAgent () {
    }
   
    /**
     * Return the application directory.
     * @return the application directory
     * @throws ResourceNotAvailableException if an application
     * directory EJB cannot be instantiated
     */
    protected SimpleApplicationDirectoryLocal applicationDirectory()
  throws ResourceNotAvailableException {
  if (applDirCache == null) {
      applDirCache = (SimpleApplicationDirectoryLocal)
    EJBUtil.createSession
    (SimpleApplicationDirectoryLocalHome.class,
     "java:comp/env/ejb/SimpleApplicationDirectoryLocal");
  }
  return applDirCache;
    }

    /**
     * Terminates execution of the given activity. This base
     * implementation simply removes the application instance fom the
     * application directory.
     *
     * @param activity the activity to be canceled
     * @throws ApplicationNotStoppedException if execution cannot be
     * terminated (see {@link ApplicationNotStoppedException
     * <code>ApplicationNotStoppedException</code>}).
     * workflow engine should retry the tool invocation
     * @throws RemoteException if a temporary problem occurs and the
     * workflow engine should retry the tool invocation
     */
    public void terminate (Activity activity)
  throws ApplicationNotStoppedException, RemoteException {
  ActivityUniqueKey auk = null;
  try {
      auk = activity.uniqueKey();
      SimpleApplicationInfo info
    = applicationDirectory().infoByActivity (auk);
      applicationDirectory().removeInstance (info.id());
  } catch (InvalidKeyException e) {
      logger.debug ("No application instance for " + auk
        + " already removed(?): " + e.getMessage ());
  }
    }
}
TOP

Related Classes of de.danet.an.workflow.tools.util.SimpleApplicationAgent

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.