summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite
diff options
context:
space:
mode:
authordougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-08-12 13:34:41 +0000
committerdougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-08-12 13:34:41 +0000
commite1448e957b13debf895f3001da9f718e9fac3eab (patch)
tree02fa690fe729ab0683506a549d090a2fefa77601 /sandbox/dougsleite
parentfae119c5401a5fc62e66be2d7f71140ef842d051 (diff)
- Modifying the way the recovery rules XML file is processed. The RecoveryRulesPolicyProcesor is being used. However, it does not mean that the recovery rules are being treated as polices.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@803501 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/dougsleite')
-rw-r--r--sandbox/dougsleite/guardian-model/pom.xml6
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java336
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java2
3 files changed, 157 insertions, 187 deletions
diff --git a/sandbox/dougsleite/guardian-model/pom.xml b/sandbox/dougsleite/guardian-model/pom.xml
index 1a6ddf3fd7..a204957231 100644
--- a/sandbox/dougsleite/guardian-model/pom.xml
+++ b/sandbox/dougsleite/guardian-model/pom.xml
@@ -73,6 +73,12 @@
<artifactId>tuscany-policy-resolutiontrees</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-recoveryrules</artifactId>
+ <version>1.6-SNAPSHOT</version>
+ </dependency>
</dependencies>
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
index 53bbeb08ff..f9fe5c2c59 100644
--- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
@@ -22,7 +22,6 @@ import org.apache.tuscany.sca.contribution.service.ContributionReadException;
import org.apache.tuscany.sca.policy.resolutiontrees.ResolutionTreesPolicyProcessor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -34,21 +33,21 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
-import org.apache.axis2.jaxws.message.util.ResettableReader;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
+import org.apache.tuscany.sca.policy.recoveryrules.RecoveryRulesPolicyProcessor;
@Service(GuardianGroup.class)
@Scope("COMPOSITE")
public class GuardianGroupImpl implements GuardianGroup {
private List<GuardianMember> guardianList;
- private ResettableReader recoveryRulesReader;
private InnerGuardianGroupThread innerThread;
private List<GlobalExceptionInterface> concurrentExList;
private Map<String, OMElement> resolutionTreeElements;
private ResolutionTreeUtils resolutionTreeUtils;
+ private Map<String, OMElement> ruleElements;
public GuardianGroupImpl() {
guardianList = new LinkedList<GuardianMember>();
@@ -62,7 +61,12 @@ public class GuardianGroupImpl implements GuardianGroup {
try {
FileInputStream fileInputStream = new FileInputStream(recoveryRules);
XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream);
- recoveryRulesReader = new ResettableReader(xmlReader);
+
+ RecoveryRulesPolicyProcessor processor = new RecoveryRulesPolicyProcessor(null, null);
+ ruleElements = processor.read(xmlReader).getRuleElements();
+
+ } catch (ContributionReadException ex) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (XMLStreamException ex) {
Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
@@ -195,178 +199,179 @@ public class GuardianGroupImpl implements GuardianGroup {
}
private void applyRecoveryRules(GlobalExceptionInterface ex) throws ConcurrentExceptionOcurrenceException {
- recoveryRulesReader.reset();
- ruleTag(ex);
+ ruleTag(ex, ruleElements.values().iterator());
}
- private void ruleTag(GlobalExceptionInterface ex) throws ConcurrentExceptionOcurrenceException {
- try {
- while (recoveryRulesReader.hasNext()) {
- recoveryRulesReader.next();
- //<rule name="" signaled_exception="">
- if (recoveryRulesReader.isStartElement() && recoveryRulesReader.getLocalName().equals(Constants.RULE)) {
- for (int i = 0; i < recoveryRulesReader.getAttributeCount(); i++) {
- //ex == signaled_exception
- if (recoveryRulesReader.getAttributeLocalName(i).equals(Constants.SIGNALED_EXCEPTION) && ex.getClass().getName().equals(recoveryRulesReader.getAttributeValue(i))) {
- participantExceptionTag(ex);
- break;
- }
- }
- }
+ private void ruleTag(GlobalExceptionInterface ex, Iterator<OMElement> ruleElements) throws ConcurrentExceptionOcurrenceException {
+ String signaledException;
+ String exceptionName;
+
+ OMElement rule;
+ while (ruleElements.hasNext()) {
+
+ rule = ruleElements.next();
+ signaledException = getAttributeValue(rule, Constants.SIGNALED_EXCEPTION);
+ exceptionName = ex.getClass().getName();
+
+ if (signaledException.equals(exceptionName)) {
+ participantExceptionTag(ex, rule.getChildElements());
+ break;
}
- } catch (XMLStreamException exc) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
- private void participantExceptionTag(GlobalExceptionInterface ex) throws ConcurrentExceptionOcurrenceException {
+ private void participantExceptionTag(GlobalExceptionInterface ex, Iterator<OMElement> participantElements) throws ConcurrentExceptionOcurrenceException {
+ String matchParticipant;
List<GuardianMember> gmList;
- try {
- while (recoveryRulesReader.hasNext() && !(recoveryRulesReader.isEndElement() && recoveryRulesReader.getLocalName().equals(Constants.RULE))) {
- recoveryRulesReader.next();
- //<participant match="<REG_EXP> | SIGNALER">
- if (recoveryRulesReader.isStartElement() && recoveryRulesReader.getLocalName().equals(Constants.PARTICIPANT)) {
- String participantMatch = recoveryRulesReader.getAttributeValue(0).trim();
- gmList = getMatchingParticipants(participantMatch, ex);
+ OMElement participant;
+ while (participantElements.hasNext()) {
+ participant = participantElements.next();
- if (!gmList.isEmpty()) {
- throwExceptionTag(gmList, ex);
- }
- }
+ matchParticipant = getAttributeValue(participant, Constants.MATCH);
+ gmList = getMatchingParticipants(matchParticipant, ex);
+
+ if (!gmList.isEmpty()) {
+ throwExceptionTag(gmList, ex, participant.getChildElements());
}
- } catch (XMLStreamException exc) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, exc);
}
}
- private void throwExceptionTag(List<GuardianMember> gmList, GlobalExceptionInterface ex) throws ConcurrentExceptionOcurrenceException {
-
- String exceptionClassName;
+ private void throwExceptionTag(List<GuardianMember> gmList, GlobalExceptionInterface ex, Iterator<OMElement> throwExceptionElements) throws ConcurrentExceptionOcurrenceException {
+ String className;
String targetContextName;
- Integer min_participant_joined;
- Integer max_participant_joined;
-
- try {
-
- while (recoveryRulesReader.hasNext() && !(recoveryRulesReader.isEndElement() && recoveryRulesReader.getLocalName().equals(Constants.PARTICIPANT))) {
- recoveryRulesReader.next();
-
- //<throw_exception class="<Exception>" target_context="<Context>"/>
- if (recoveryRulesReader.isStartElement() && recoveryRulesReader.getLocalName().equals(Constants.THROW_EXCEPTION)) {
-
- exceptionClassName = null;
- targetContextName = null;
- min_participant_joined = null;
- max_participant_joined = null;
- for (int j = 0; j < recoveryRulesReader.getAttributeCount(); j++) {
- if (recoveryRulesReader.getAttributeLocalName(j).equals(Constants.CLASS)) {
- //class value
- exceptionClassName = recoveryRulesReader.getAttributeValue(j);
- } else if (recoveryRulesReader.getAttributeLocalName(j).equals(Constants.TARGET_CONTEXT)) {
- //target_context value
- targetContextName = recoveryRulesReader.getAttributeValue(j);
- } else if (recoveryRulesReader.getAttributeLocalName(j).equals(Constants.MIN_PARTICIPANT_JOINED)) {
- //min_participant_joined value
- min_participant_joined = Integer.parseInt(recoveryRulesReader.getAttributeValue(j));
- } else {
- //max_participant_joined value
- max_participant_joined = Integer.parseInt(recoveryRulesReader.getAttributeValue(j));
- }
- }
+ Integer minParticipantJoined;
+ Integer maxParticipantJoined;
- //Test the min and max joined participants condition
- if (min_participant_joined != null && max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
- break;
- }
- } else if (min_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- } else if (max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- }
+ OMElement throwException;
+ while (throwExceptionElements.hasNext()) {
- //<affected_participants>
- String affectedParticipants = affectedParticipantsTag();
- int index = -1;
+ throwException = throwExceptionElements.next();
- //Verify if the parameter is an index
- try {
- index = Integer.parseInt(affectedParticipants);
- } catch (NumberFormatException nexc) {
- index = -1;
- }
+ className = getAttributeValue(throwException, Constants.CLASS);
+ targetContextName = getAttributeValue(throwException, Constants.TARGET_CONTEXT);
- Class exceptionClass = Class.forName(exceptionClassName);
- Context targetContext;
- if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.CURRENT_CONTEXT;
- } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.INIT_CONTEXT;
- } else {
- targetContext = new Context(targetContextName);
- }
- GlobalException newException = (GlobalException) exceptionClass.newInstance();
+ try {
+ minParticipantJoined = Integer.parseInt(getAttributeValue(throwException, Constants.MIN_PARTICIPANT_JOINED));
+ } catch (NumberFormatException nex) {
+ minParticipantJoined = null;
+ }
- newException.setTargetContext(targetContext);
- newException.setSignalingContext(ex.getSignalingContext());
- newException.putSignalingParticipant(ex.getSignalingParticipants().toString());
+ try {
+ maxParticipantJoined = Integer.parseInt(getAttributeValue(throwException, Constants.MAX_PARTICIPANT_JOINED));
+ } catch (NumberFormatException nexc) {
+ maxParticipantJoined = null;
+ }
- //Check concurrent exception existence
- if (concurrentExList.size() > 1) {
- throw new ConcurrentExceptionOcurrenceException(concurrentExList.toString());
- }
+ //Test the min and max joined participants condition
+ if (minParticipantJoined != null && maxParticipantJoined != null) {
+ if (!(guardianList.size() >= minParticipantJoined && guardianList.size() < maxParticipantJoined)) {
+ break;
+ }
+ } else if (minParticipantJoined != null) {
+ if (!(guardianList.size() >= minParticipantJoined)) {
+ break;
+ }
+ } else if (minParticipantJoined != null) {
+ if (!(guardianList.size() >= minParticipantJoined)) {
+ break;
+ }
+ }
- //Add the exception to the participants matched
- if (index != -1) {
- gmList.get(index).addException(newException);
- } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
- if (affectedParticipants.toUpperCase().equals(Constants.FIRST)) {
- gmList.get(0).addException(newException);
- } else if (affectedParticipants.toUpperCase().equals(Constants.LAST)) {
- gmList.get(gmList.size() - 1).addException(newException);
- } else if (affectedParticipants.toUpperCase().equals(Constants.ALL)) {
- for (GuardianMember gm : gmList) {
- gm.addException(newException);
- }
- }
- } else {
+ //<affected_participants>
+ String affectedParticipants = affectedParticipantsTag(throwException.getChildElements());
+ int index = -1;
+
+ //Verify if the parameter is an index
+ try {
+ index = Integer.parseInt(affectedParticipants);
+ } catch (NumberFormatException nexc) {
+ index = -1;
+ }
+
+ //Create the new exception instance
+ Class exceptionClass;
+ try {
+ exceptionClass = Class.forName(className);
+
+ Context targetContext;
+ if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
+ targetContext = Context.CURRENT_CONTEXT;
+ } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
+ targetContext = Context.INIT_CONTEXT;
+ } else {
+ targetContext = new Context(targetContextName);
+ }
+ GlobalException newException = (GlobalException) exceptionClass.newInstance();
+
+ newException.setTargetContext(targetContext);
+ newException.setSignalingContext(ex.getSignalingContext());
+ newException.putSignalingParticipant(ex.getSignalingParticipants().toString());
+
+ //Check concurrent exception existence
+ if (concurrentExList.size() > 1) {
+ throw new ConcurrentExceptionOcurrenceException(concurrentExList.toString());
+ }
+
+ //Add the exception to the participants matched
+ if (index != -1) {
+ gmList.get(index).addException(newException);
+ } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
+ if (affectedParticipants.toUpperCase().equals(Constants.FIRST)) {
+ gmList.get(0).addException(newException);
+ } else if (affectedParticipants.toUpperCase().equals(Constants.LAST)) {
+ gmList.get(gmList.size() - 1).addException(newException);
+ } else if (affectedParticipants.toUpperCase().equals(Constants.ALL)) {
for (GuardianMember gm : gmList) {
gm.addException(newException);
}
}
+ } else {
+ for (GuardianMember gm : gmList) {
+ gm.addException(newException);
+ }
}
+
+ } catch (InstantiationException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ } catch (IllegalAccessException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ } catch (ClassNotFoundException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
- } catch (XMLStreamException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (InstantiationException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (IllegalAccessException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (ClassNotFoundException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
}
- private String affectedParticipantsTag() {
- String affectedParticipants = null;
- try {
- while (recoveryRulesReader.hasNext() && !(recoveryRulesReader.isEndElement() && recoveryRulesReader.getLocalName().equals(Constants.THROW_EXCEPTION))) {
- recoveryRulesReader.next();
- //<affected_participants>
- if (recoveryRulesReader.isStartElement() && recoveryRulesReader.getLocalName().equals(Constants.AFFECTED_PARTICIPANTS)) {
- affectedParticipants = recoveryRulesReader.getElementText();
- }
+ private String affectedParticipantsTag(Iterator<OMElement> affectedParticipantElements) {
+
+ String affectedParticipantValue = null;
+
+ OMElement affectedParticipant;
+ while (affectedParticipantElements.hasNext()) {
+
+ affectedParticipant = affectedParticipantElements.next();
+ affectedParticipantValue = affectedParticipant.getText();
+ }
+
+ if (affectedParticipantValue != null && affectedParticipantValue.length() == 0) {
+ affectedParticipantValue = null;
+ }
+
+ return affectedParticipantValue;
+ }
+
+ private String getAttributeValue(OMElement element, String attributeName) {
+ OMAttribute at;
+ Iterator it = element.getAllAttributes();
+
+ while (it.hasNext()) {
+ at = (OMAttribute) it.next();
+ if (at.getLocalName().equals(attributeName)) {
+ return at.getAttributeValue();
}
- } catch (XMLStreamException ex) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
- return affectedParticipants;
+ return null;
}
private void applyConcurrentRecoveryRules() {
@@ -431,7 +436,7 @@ public class GuardianGroupImpl implements GuardianGroup {
//Search for the root of the smallest subtree that contains all the concurrently signaled exceptions. If not found, return null.
private GlobalExceptionInterface checkExceptionResolutionTree(List<GlobalExceptionInterface> exceptionList, OMElement rootTree) {
-
+
resolutionTreeUtils.setRoot(rootTree);
String ex1, ex2;
GlobalExceptionInterface resolvedEx = null;
@@ -629,45 +634,4 @@ public class GuardianGroupImpl implements GuardianGroup {
return re.toString();
}
}
-
- private class WrapperInteger {
-
- private int value;
-
- public WrapperInteger() {
- }
-
- public WrapperInteger(int value) {
- this.value = value;
- }
-
- public void setValue(int value) {
- this.value = value;
- }
-
- public int getValue() {
- return this.value;
- }
-
- public int increment() {
- return ++value;
- }
-
- public int increment(int amount) {
- return value += amount;
- }
-
- public int decrement() {
- return --value;
- }
-
- public int decrement(int amount) {
- return value -= value;
- }
-
- @Override
- public String toString() {
- return Integer.toString(value);
- }
- }
-}
+} \ No newline at end of file
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java
index e4bd6652c8..09dd0673eb 100644
--- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java
@@ -29,7 +29,7 @@ import org.apache.axiom.om.OMElement;
public class ResolutionTreeUtils {
- //E: Euler tour of the tree obtained by listing the nodes viseted in a depth firts search of the tree starting from the root. Contains 2n-1 elements
+ //E: Euler tour of the tree obtained by listing the nodes visited in a depth first search of the tree starting from the root. Contains 2n-1 elements
private List<String> eulerTour;
//L: Array of level numbers such that L[i] contains the tree-depth of the node E[i]. Contains 2n-1 elements
private List<Integer> levels;