📄 scope.java
字号:
terminateEventHandlers(); } else stopEventHandlers(); instance(ACTIVE.this); } public void cancelled() { completed(null, CompensationHandler.emptySet()); } public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); } }); } object(false, mlSet); } else /* nothing to wait for... */ { // Any compensation handlers that were available but not activated will be forgotten. Set<CompensationHandler> unreachableCompensationHandlers = _scopeFrame.availableCompensations; if (unreachableCompensationHandlers != null) for (Iterator<CompensationHandler> i = unreachableCompensationHandlers.iterator(); i.hasNext(); ) { CompensationHandler ch = i.next(); ch.compChannel.forget(); } _scopeFrame.availableCompensations = null; // Maintain a set of links needing dead-path elimination. Set<OLink> linksNeedingDPE = new HashSet<OLink>(); if (_oscope.faultHandler != null) for (Iterator<OCatch> i = _oscope.faultHandler.catchBlocks.iterator(); i.hasNext(); ) linksNeedingDPE.addAll(i.next().outgoingLinks); // We're done with the main work, if we were terminated, we will // need to load the termination handler: if (_terminated) { __log.debug("Scope: " + _oscope + " was terminated."); // ??? Should we forward _self.parent.completed(null,_compensations); } else if (_fault != null) { sendEvent(new ScopeFaultEvent(_fault.getFaultName(), _fault.getFaultLineNo(),_fault.getExplanation())); // Find a fault handler for our fault. OCatch catchBlock = _oscope.faultHandler == null ? null : findCatch(_oscope.faultHandler, _fault.getFaultName(), _fault.getFaultType()); // Collect all the compensation data for completed child scopes. assert !!_eventHandlers.isEmpty(); assert _child == null; if (catchBlock == null) { // If we cannot find a catch block for this fault, then we simply propagate the fault // to the parent. NOTE: the "default" fault handler as described in the BPEL spec // must be generated by the compiler. if (__log.isDebugEnabled()) __log.debug(_self + ": has no fault handler for " + _fault.getFaultName() + "; scope will propagate FAULT!"); _self.parent.completed(_fault, _compensations); } else /* catchBlock != null */ { if (__log.isDebugEnabled()) __log.debug(_self + ": has a fault handler for " + _fault.getFaultName() + ": "+ catchBlock); linksNeedingDPE.removeAll(catchBlock.outgoingLinks); // We have to create a scope for the catch block. BpelRuntimeContext ntive = getBpelRuntimeContext(); ActivityInfo faultHandlerActivity = new ActivityInfo(genMonotonic(), catchBlock, newChannel(TerminationChannel.class,"FH"), newChannel(ParentScopeChannel.class,"FH")); ScopeFrame faultHandlerScopeFrame = new ScopeFrame(catchBlock, ntive.createScopeInstance(_scopeFrame.scopeInstanceId, catchBlock), _scopeFrame, _compensations, _fault); if (catchBlock.faultVariable != null) { try { VariableInstance vinst = faultHandlerScopeFrame.resolve(catchBlock.faultVariable); initializeVariable(vinst, _fault.getFaultMessage()); // Generating event VariableModificationEvent se = new VariableModificationEvent(vinst.declaration.name); se.setNewValue(_fault.getFaultMessage()); if (_oscope.debugInfo != null) se.setLineNo(_oscope.debugInfo.startLine); sendEvent(se); } catch (Exception ex) { __log.fatal(ex); throw new InvalidProcessException(ex); } } // Create the fault handler scope. instance(new SCOPE(faultHandlerActivity,faultHandlerScopeFrame, SCOPE.this._linkFrame)); object(new ParentScopeChannelListener(faultHandlerActivity.parent) { private static final long serialVersionUID = -6009078124717125270L; public void compensate(OScope scope, SynchChannel ret) { // This should never happen. throw new AssertionError("received compensate request!"); } public void completed(FaultData fault, Set<CompensationHandler> compensations) { // The compensations that have been registered here, will never be activated, // so we'll forget them as soon as possible. for(Iterator<CompensationHandler> i = compensations.iterator();i.hasNext();) i.next().compChannel.forget(); _self.parent.completed(fault, CompensationHandler.emptySet()); } public void cancelled() { completed(null, CompensationHandler.emptySet()); } public void failure(String reason, Element data) { completed(null, CompensationHandler.emptySet()); } }); } } else /* completed ok */ { if (_oscope.compensationHandler != null) { CompensationHandler compensationHandler = new CompensationHandler( _scopeFrame, newChannel(CompensationChannel.class), _startTime, System.currentTimeMillis()); _self.parent.completed(null, Collections.singleton(compensationHandler)); instance(new COMPENSATIONHANDLER_(compensationHandler, _compensations)); } else /* no compensation handler */ { _self.parent.completed(null, _compensations); } } // DPE links needing DPE (i.e. the unselected catch blocks). dpe(linksNeedingDPE); } } private void terminateEventHandlers() { for (Iterator<EventHandlerInfo> i = _eventHandlers.iterator();i.hasNext(); ) { EventHandlerInfo ehi = i.next(); if (!ehi.terminateRequested && !ehi.stopRequested) { replication(ehi.tc).terminate(); ehi.terminateRequested = true; } } } private void stopEventHandlers() { for (Iterator<EventHandlerInfo> i = _eventHandlers.iterator();i.hasNext();) { EventHandlerInfo ehi = i.next(); if (!ehi.stopRequested && !ehi.terminateRequested) { ehi.cc.stop(); ehi.stopRequested = true; } } } } private static OCatch findCatch(OFaultHandler fh, QName faultName, OVarType faultType) { OCatch bestMatch = null; for (Iterator<OCatch> i = fh.catchBlocks.iterator(); i.hasNext();) { OCatch c = i.next(); // First we try to eliminate this catch block based on fault-name mismatches: if (c.faultName != null) { if (faultName == null) continue; if (!faultName.equals(c.faultName)) continue; } // Then we try to eliminate this catch based on type incompatibility: if (c.faultVariable != null) { if (faultType == null) continue; else if (c.faultVariable.type instanceof OMessageVarType) { if (faultType instanceof OMessageVarType && ((OMessageVarType)faultType).equals(c.faultVariable.type)) { // Don't eliminate. } else if (faultType instanceof OElementVarType && ((OMessageVarType)c.faultVariable.type).docLitType !=null && !((OMessageVarType)c.faultVariable.type).docLitType.equals(faultType)) { // Don't eliminate. } else { continue; // Eliminate. } } else if (c.faultVariable.type instanceof OElementVarType) { if (faultType instanceof OElementVarType && faultType.equals(c.faultVariable.type)) { // Don't eliminate } else if (faultType instanceof OMessageVarType && ((OMessageVarType)faultType).docLitType != null && ((OMessageVarType)faultType).docLitType.equals(c.faultVariable.type)) { // Don't eliminate } else { continue; // eliminate } } else { continue; // Eliminate } } // If we got to this point we did not eliminate this catch block. However, we don't just // use the first non-eliminated catch, we instead try to find the best match. if (bestMatch == null) { // Obviously something is better then nothing. bestMatch = c; } else { // Otherwise we prefer name and variable matches but prefer name-only matches to // variable-only matches. int existingScore = (bestMatch.faultName == null ? 0 : 2) + (bestMatch.faultVariable == null ? 0 : 1); int currentScore = (c.faultName == null ? 0 : 2) + (c.faultVariable == null ? 0 : 1); if (currentScore > existingScore) { bestMatch = c; } } } return bestMatch; } static final class EventHandlerInfo implements Serializable { private static final long serialVersionUID = -9046603073542446478L; final OBase o; final EventHandlerControlChannel cc; final ParentScopeChannel psc; final TerminationChannel tc; boolean terminateRequested; boolean stopRequested; EventHandlerInfo(OBase o, EventHandlerControlChannel cc, ParentScopeChannel psc, TerminationChannel tc) { this.o = o; this.cc = cc; this.psc = psc; this.tc = tc; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -