📄 activityguard.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.ode.bpel.runtime;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.ode.bpel.common.FaultException;import org.apache.ode.bpel.evt.ActivityEnabledEvent;import org.apache.ode.bpel.evt.ActivityExecEndEvent;import org.apache.ode.bpel.evt.ActivityExecStartEvent;import org.apache.ode.bpel.evt.ActivityFailureEvent;import org.apache.ode.bpel.evt.ActivityRecoveryEvent;import org.apache.ode.bpel.explang.EvaluationException;import org.apache.ode.bpel.o.OActivity;import org.apache.ode.bpel.o.OExpression;import org.apache.ode.bpel.o.OLink;import org.apache.ode.bpel.o.OScope;import org.apache.ode.bpel.o.OFailureHandling;import org.apache.ode.bpel.runtime.channels.FaultData;import org.apache.ode.bpel.runtime.channels.LinkStatusChannelListener;import org.apache.ode.bpel.runtime.channels.ParentScopeChannel;import org.apache.ode.bpel.runtime.channels.ParentScopeChannelListener;import org.apache.ode.bpel.runtime.channels.TerminationChannelListener;import org.apache.ode.bpel.runtime.channels.ActivityRecoveryChannel;import org.apache.ode.bpel.runtime.channels.ActivityRecoveryChannelListener;import org.apache.ode.bpel.runtime.channels.TimerResponseChannel;import org.apache.ode.bpel.runtime.channels.TimerResponseChannelListener;import org.apache.ode.jacob.ChannelListener;import org.apache.ode.jacob.SynchChannel;import org.w3c.dom.Element;import java.io.Serializable;import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Map;import java.util.Set;class ACTIVITYGUARD extends ACTIVITY { private static final long serialVersionUID = 1L; private static final Log __log = LogFactory.getLog(ACTIVITYGUARD.class); private static final ActivityTemplateFactory __activityTemplateFactory = new ActivityTemplateFactory(); private OActivity _oactivity; /** Link values. */ private Map<OLink, Boolean> _linkVals = new HashMap<OLink, Boolean>(); /** Flag to prevent duplicate ActivityEnabledEvents */ private boolean _firstTime = true; private ActivityFailure _failure; public ACTIVITYGUARD(ActivityInfo self, ScopeFrame scopeFrame, LinkFrame linkFrame) { super(self, scopeFrame, linkFrame); _oactivity = self.o; } public void run() { // Send a notification of the activity being enabled, if (_firstTime) { sendEvent(new ActivityEnabledEvent()); _firstTime = false; } if (_linkVals.keySet().containsAll(_oactivity.targetLinks)) { if (evaluateJoinCondition()) { ActivityExecStartEvent aese = new ActivityExecStartEvent(); sendEvent(aese); // intercept completion channel in order to execute transition conditions. ActivityInfo activity = new ActivityInfo(genMonotonic(),_self.o,_self.self, newChannel(ParentScopeChannel.class)); instance(createActivity(activity)); instance(new TCONDINTERCEPT(activity.parent)); } else { if (_oactivity.suppressJoinFailure) { _self.parent.completed(null, CompensationHandler.emptySet()); if (__log.isDebugEnabled()) __log.debug("Join condition false, suppress join failure on activity " + _self.aId); } else { FaultData fault = null; fault = createFault(_oactivity.getOwner().constants.qnJoinFailure,_oactivity); _self.parent.completed(fault, CompensationHandler.emptySet()); } // Dead path activity. dpe(_oactivity); } } else /* don't know all our links statuses */ { Set<ChannelListener> mlset = new HashSet<ChannelListener>(); mlset.add(new TerminationChannelListener(_self.self) { private static final long serialVersionUID = 5094153128476008961L; public void terminate() { // Complete immediately, without faulting or registering any comps. _self.parent.completed(null, CompensationHandler.emptySet()); // Dead-path activity dpe(_oactivity); } }); for (final OLink link : _oactivity.targetLinks) { mlset.add(new LinkStatusChannelListener(_linkFrame.resolve(link).sub) { private static final long serialVersionUID = 1024137371118887935L; public void linkStatus(boolean value) { _linkVals.put(link, Boolean.valueOf(value)); instance(ACTIVITYGUARD.this); } }); } object(false, mlset); } } private boolean evaluateTransitionCondition(OExpression transitionCondition) throws FaultException { if (transitionCondition == null) return true; try { return getBpelRuntimeContext().getExpLangRuntime().evaluateAsBoolean(transitionCondition, new ExprEvaluationContextImpl(_scopeFrame, getBpelRuntimeContext())); } catch (EvaluationException e) { String msg = "Error in transition condition detected at runtime; condition=" + transitionCondition; __log.error(msg,e); throw new InvalidProcessException(msg, e); } } /** * Evaluate an activity's join condition. * @return <code>true</code> if join condition evaluates to true. */ private boolean evaluateJoinCondition() { // For activities with no link targets, the join condition is always satisfied. if (_oactivity.targetLinks.size() == 0) return true; // For activities with no join condition, an OR condition is assumed. if (_oactivity.joinCondition == null) return _linkVals.values().contains(Boolean.TRUE); try { return getBpelRuntimeContext().getExpLangRuntime().evaluateAsBoolean(_oactivity.joinCondition, new ExprEvaluationContextImpl(null, null,_linkVals)); } catch (Exception e) { String msg = "Unexpected error evaluating a join condition: " + _oactivity.joinCondition; __log.error(msg,e); throw new InvalidProcessException(msg,e); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -