/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This 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 (at your option) any later version.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.pvm.impl;
import java.util.Map;
import java.util.logging.Logger;
import org.jbpm.PvmException;
import org.jbpm.env.session.Message;
import org.jbpm.pvm.ExternalActivity;
import org.jbpm.pvm.impl.ExecutionImpl.Propagation;
/**
* @author Tom Baeyens
*/
public class SignalOp implements AtomicOperation {
private static final Logger log = Logger.getLogger(SignalOp.class.getName());
String signal;
Map<String, Object> parameters;
public SignalOp(String signal, Map<String, Object> parameters) {
this.signal = signal;
this.parameters = parameters;
}
public boolean isAsync(ExecutionImpl execution) {
return execution.getNode().isSignalAsync();
}
public void perform(ExecutionImpl execution) {
NodeImpl node = execution.getNode();
if (execution.getName()!=null) {
log.fine(execution.toString()+" signals "+node);
} else {
log.fine("signalling "+node+", signal="+signal);
}
ExternalActivity externalActivity = (ExternalActivity) node.getBehaviour();
try {
execution.userCodeType = ExecutionImpl.UserCodeType.NODE_BEHAVIOUR;
execution.propagation = Propagation.UNSPECIFIED;
externalActivity.signal(execution, signal, parameters);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new PvmException("couldn't signal "+node+": "+e.getMessage(), e);
} finally {
execution.userCodeType = null;
}
if (execution.propagation == Propagation.UNSPECIFIED) {
execution.proceed();
}
}
public String toString() {
return "signal(node)";
}
public Message createAsyncMessage(ExecutionImpl execution) {
return new SignalMessage(execution, signal);
}
}