📄 scope.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 java.io.Serializable;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import javax.xml.namespace.QName;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.ode.bpel.evt.ScopeFaultEvent;import org.apache.ode.bpel.evt.ScopeStartEvent;import org.apache.ode.bpel.evt.VariableModificationEvent;import org.apache.ode.bpel.o.OBase;import org.apache.ode.bpel.o.OCatch;import org.apache.ode.bpel.o.OElementVarType;import org.apache.ode.bpel.o.OEventHandler;import org.apache.ode.bpel.o.OFailureHandling;import org.apache.ode.bpel.o.OFaultHandler;import org.apache.ode.bpel.o.OLink;import org.apache.ode.bpel.o.OMessageVarType;import org.apache.ode.bpel.o.OScope;import org.apache.ode.bpel.o.OVarType;import org.apache.ode.bpel.runtime.channels.CompensationChannel;import org.apache.ode.bpel.runtime.channels.EventHandlerControlChannel;import org.apache.ode.bpel.runtime.channels.FaultData;import org.apache.ode.bpel.runtime.channels.ParentScopeChannel;import org.apache.ode.bpel.runtime.channels.ParentScopeChannelListener;import org.apache.ode.bpel.runtime.channels.TerminationChannel;import org.apache.ode.bpel.runtime.channels.TerminationChannelListener;import org.apache.ode.jacob.ChannelListener;import org.apache.ode.jacob.SynchChannel;import org.w3c.dom.Element;/** * An active scope. */class SCOPE extends ACTIVITY { private static final long serialVersionUID = 6111903798996023525L; private static final Log __log = LogFactory.getLog(SCOPE.class); private OScope _oscope; private ActivityInfo _child; private Set<EventHandlerInfo> _eventHandlers = new HashSet<EventHandlerInfo>(); /** Constructor. */ public SCOPE(ActivityInfo self, ScopeFrame frame, LinkFrame linkFrame) { super(self, frame, linkFrame); _oscope = (OScope) self.o; assert _oscope.activity != null; } public void run() { // Start the child activity. _child = new ActivityInfo(genMonotonic(), _oscope.activity, newChannel(TerminationChannel.class), newChannel(ParentScopeChannel.class)); instance(createChild(_child, _scopeFrame, _linkFrame)); if (_oscope.eventHandler != null) { for (Iterator<OEventHandler.OAlarm> i = _oscope.eventHandler.onAlarms.iterator(); i.hasNext(); ) { OEventHandler.OAlarm alarm = i.next(); EventHandlerInfo ehi = new EventHandlerInfo(alarm, newChannel(EventHandlerControlChannel.class), newChannel(ParentScopeChannel.class), newChannel(TerminationChannel.class)); _eventHandlers.add(ehi); instance(new EH_ALARM(ehi.psc,ehi.tc, ehi.cc, alarm, _scopeFrame)); } for (Iterator<OEventHandler.OEvent> i = _oscope.eventHandler.onMessages.iterator(); i.hasNext(); ) { OEventHandler.OEvent event = i.next(); EventHandlerInfo ehi = new EventHandlerInfo(event, newChannel(EventHandlerControlChannel.class), newChannel(ParentScopeChannel.class), newChannel(TerminationChannel.class)); _eventHandlers.add(ehi); instance(new EH_EVENT(ehi.psc,ehi.tc, ehi.cc, event, _scopeFrame)); } } getBpelRuntimeContext().initializePartnerLinks(_scopeFrame.scopeInstanceId, _oscope.partnerLinks.values()); sendEvent(new ScopeStartEvent()); instance(new ACTIVE()); } private List<CompensationHandler> findCompensationData(OScope scope) { List<CompensationHandler> out = new ArrayList<CompensationHandler>(); for (Iterator<CompensationHandler> i = _scopeFrame.availableCompensations.iterator(); i.hasNext(); ) { CompensationHandler ch = i.next(); if (null == scope || ch.compensated.oscope.equals(scope)) out.add(ch); } // TODO: sort out in terms of completion order return out; } class ACTIVE extends ACTIVITY { private static final long serialVersionUID = -5876892592071965346L; /** Links collected. */ private boolean _terminated; private FaultData _fault; private long _startTime; private final HashSet<CompensationHandler> _compensations = new HashSet<CompensationHandler>(); private boolean _childTermRequested; ACTIVE() { super(SCOPE.this._self, SCOPE.this._scopeFrame, SCOPE.this._linkFrame); _startTime = System.currentTimeMillis(); } public void run() { if (_child != null || !_eventHandlers.isEmpty()) { HashSet<ChannelListener> mlSet = new HashSet<ChannelListener>(); // Listen to messages from our parent. mlSet.add(new TerminationChannelListener(_self.self) { private static final long serialVersionUID = 1913414844895865116L; public void terminate() { _terminated = true; // Forward the termination request to the nested activity. if (_child != null && !_childTermRequested) { replication(_child.self).terminate(); _childTermRequested = true; } // Forward the termination request to our event handlers. terminateEventHandlers(); instance(ACTIVE.this); } }); // Handle messages from the child if it is still alive if (_child != null) { mlSet.add(new ParentScopeChannelListener(_child.parent) { private static final long serialVersionUID = -6934246487304813033L; public void compensate(OScope scope, SynchChannel ret) { // If this scope does not have available compensations, defer to // parent scope, otherwise do compensation. if (_scopeFrame.availableCompensations == null) _self.parent.compensate(scope, ret); else { // TODO: Check if we are doing duplicate compensation List<CompensationHandler> compensations = findCompensationData(scope); _scopeFrame.availableCompensations.removeAll(compensations); instance(new ORDEREDCOMPENSATOR(compensations, ret)); } instance(ACTIVE.this); } public void completed(FaultData flt, Set<CompensationHandler> compenstations) { // Set the fault to the activity's choice, if and only if no previous fault // has been detected (first fault wins). if (flt != null && _fault == null) _fault = flt; _child = null; _compensations.addAll(compenstations); if (flt == null) stopEventHandlers(); else terminateEventHandlers(); instance(ACTIVE.this); } public void cancelled() { // Implicit scope holds links of the enclosed activity, // they only get cancelled when we propagate upwards. if (_oscope.implicitScope) _self.parent.cancelled(); else completed(null, CompensationHandler.emptySet()); } public void failure(String reason, Element data) { completed(createFault(OFailureHandling.FAILURE_FAULT_NAME, _self.o, null), CompensationHandler.emptySet()); } }); } // Similarly, handle messages from the event handler, if one exists // and if it has not completed. for (Iterator<EventHandlerInfo> i = _eventHandlers.iterator();i.hasNext();) { final EventHandlerInfo ehi = i.next(); mlSet.add(new ParentScopeChannelListener(ehi.psc) { private static final long serialVersionUID = -4694721357537858221L; public void compensate(OScope scope, SynchChannel ret) { // ACTIVE scopes do not compensate, send request up to parent. _self.parent.compensate(scope, ret); instance(ACTIVE.this); } public void completed(FaultData flt, Set<CompensationHandler> compenstations) { // Set the fault to the activity's choice, if and only if no previous fault // has been detected (first fault wins). if (flt != null && _fault == null) _fault = flt; _eventHandlers.remove(ehi); _compensations.addAll(compenstations); if (flt != null) { // Terminate child if we get a fault from the event handler. if (_child != null && !_childTermRequested) { replication(_child.self).terminate(); _childTermRequested = true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -