summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java')
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java146
1 files changed, 24 insertions, 122 deletions
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 c8964f2b98..53bbeb08ff 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
@@ -48,11 +48,13 @@ public class GuardianGroupImpl implements GuardianGroup {
private InnerGuardianGroupThread innerThread;
private List<GlobalExceptionInterface> concurrentExList;
private Map<String, OMElement> resolutionTreeElements;
+ private ResolutionTreeUtils resolutionTreeUtils;
public GuardianGroupImpl() {
guardianList = new LinkedList<GuardianMember>();
concurrentExList = new LinkedList<GlobalExceptionInterface>();
innerThread = new InnerGuardianGroupThread();
+ resolutionTreeUtils = new ResolutionTreeUtils();
}
@Property(name = "recovery_rules", required = false)
@@ -228,12 +230,6 @@ public class GuardianGroupImpl implements GuardianGroup {
gmList = getMatchingParticipants(participantMatch, ex);
- //TESTING--------------------------------------------
- for (GuardianMember gm : gmList) {
- System.out.println(gm.getParticipantIdentifier());
- }
- //---------------------------------------------------
-
if (!gmList.isEmpty()) {
throwExceptionTag(gmList, ex);
}
@@ -414,6 +410,7 @@ public class GuardianGroupImpl implements GuardianGroup {
private GlobalExceptionInterface checkExceptionResolutionTrees(List<GlobalExceptionInterface> exceptionList, Iterator resolutionTreesElements) {
OMElement tree;
+ OMElement root;
String exceptionLevel = null;
GlobalExceptionInterface resolvedEx = null;
@@ -421,7 +418,8 @@ public class GuardianGroupImpl implements GuardianGroup {
tree = (OMElement) resolutionTreesElements.next();
exceptionLevel = tree.getAttributeValue(Constants.EXCEPTION_LEVEL_QNAME);
- resolvedEx = checkExceptionResolutionTree(exceptionList, tree.getChildElements(), new WrapperInteger(exceptionList.size()));
+ root = (OMElement) tree.getChildElements().next();
+ resolvedEx = checkExceptionResolutionTree(exceptionList, root);
if (resolvedEx != null) {
break;
@@ -432,56 +430,29 @@ 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.
- //FIXME: Check for equal exception classes on the tree
- //FIXME: Implement the Lowest common ancestor algorithm
- private GlobalExceptionInterface checkExceptionResolutionTree(List<GlobalExceptionInterface> exceptionList, Iterator elements, WrapperInteger currentListSize) {
-
- OMElement el;
- OMAttribute at;
- String exClass = null;
+ private GlobalExceptionInterface checkExceptionResolutionTree(List<GlobalExceptionInterface> exceptionList, OMElement rootTree) {
+
+ resolutionTreeUtils.setRoot(rootTree);
+ String ex1, ex2;
GlobalExceptionInterface resolvedEx = null;
- boolean isLeaf = false;
-
- while (elements.hasNext()) {
- el = (OMElement) elements.next();
-
- //<exception class="">
- if (el.getLocalName().equals(Constants.EXCEPTION)) {
-
- Iterator it = el.getAllAttributes();
- while (it.hasNext()) {
- at = (OMAttribute) it.next();
- if (at.getLocalName().equals(Constants.CLASS)) {
- exClass = at.getAttributeValue();
- }
- }
- try {
- for (GlobalExceptionInterface ex : exceptionList) {
- if (Class.forName(exClass).equals(ex.getClass())) {
- currentListSize.decrement();
- break;
- }
- }
+ ex1 = exceptionList.get(0).getClass().getName();
+ for (int i = 1; i < exceptionList.size(); i++) {
+ ex2 = exceptionList.get(i).getClass().getName();
- } catch (ClassNotFoundException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- }
-
- Iterator children = el.getChildElements();
- if (children.hasNext()) {
- resolvedEx = checkExceptionResolutionTree(exceptionList, children, currentListSize);
- } else {
- isLeaf = true;
- }
+ try {
+ ex1 = resolutionTreeUtils.getLowestCommonAncestor(ex1, ex2);
+ } catch (InvalidNodeException invalidNodeException) {
+ ex1 = null;
+ break;
}
}
- if (resolvedEx == null && currentListSize.getValue() == 0 && !isLeaf) {
+ if (ex1 != null) {
Class exceptionClass;
try {
- exceptionClass = Class.forName(exClass);
+ exceptionClass = Class.forName(ex1);
resolvedEx = (GlobalException) exceptionClass.newInstance();
for (GlobalExceptionInterface ex : exceptionList) {
@@ -495,8 +466,12 @@ public class GuardianGroupImpl implements GuardianGroup {
} catch (ClassNotFoundException ex) {
Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
+
+ return resolvedEx;
+
+ } else {
+ return null;
}
- return resolvedEx;
}
private List<GuardianMember> getMatchingParticipants(String regularExpression, GlobalExceptionInterface signaledException) {
@@ -516,16 +491,10 @@ public class GuardianGroupImpl implements GuardianGroup {
if (signaledException.getSignalingParticipants().contains(gm.getParticipantIdentifier())) {
matchingParticipants.add(gm);
}
-
- /*//All concurrent signaler were found
- if (matchingParticipants.size() == signaledException.getSignalingParticipants().size()) {
- break;
- }*/
}
} else if (regularExpression.toUpperCase().equals("!SIGNALER")) {
for (GuardianMember gm : guardianList) {
if (!signaledException.getSignalingParticipants().contains(gm.getParticipantIdentifier())) {
- //if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
matchingParticipants.add(gm);
}
}
@@ -575,47 +544,11 @@ public class GuardianGroupImpl implements GuardianGroup {
if (signaledException.getSignalingParticipants().contains(gm.getParticipantIdentifier())) {
matchingParticipants.add(gm);
}
-
- /*//All concurrent signaler were found
- if (matchingParticipants.size() == signaledException.getSignalingParticipants().size()) {
- break;
- }*/
-
-// //ConcurrentGlobalException: there are more than one signaler
-// if (signaledException instanceof ConcurrentGlobalException) {
-// List<String> signalingPartcipants = ((ConcurrentGlobalException) signaledException).getSignalingParticipants();
-//
-// if (signalingPartcipants.contains(gm.getParticipantIdentifier())) {
-// matchingParticipants.add(gm);
-// count++;
-// }
-//
-// //All concurrent signaler were found
-// if (count == signalingPartcipants.size()) {
-// break;
-// }
-//
-// } else if (gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
-// matchingParticipants.add(gm);
-// break;
-// }
} //Test if the participant is not Signaler
else {
if (!signaledException.getSignalingParticipants().contains(gm.getParticipantIdentifier())) {
matchingParticipants.add(gm);
}
-
-// //ConcurrentGlobalException: there are more than one signaler
-// if (signaledException instanceof ConcurrentGlobalException) {
-// List<String> signalingPartcipants = ((ConcurrentGlobalException) signaledException).getSignalingParticipants();
-//
-// if (!(signalingPartcipants.contains(gm.getParticipantIdentifier()))) {
-// matchingParticipants.add(gm);
-// }
-//
-// } else if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
-// matchingParticipants.add(gm);
-// }
}
}
}
@@ -625,37 +558,6 @@ public class GuardianGroupImpl implements GuardianGroup {
return matchingParticipants;
}
-// private List<GuardianMember> getMatchingParticipantsOriginal(String regularExpression, GlobalExceptionInterface signaledException) {
-// List<GuardianMember> matchingParticipants = new LinkedList();
-//
-// if (regularExpression.toUpperCase().equals("SIGNALER")) {
-// for (GuardianMember gm : guardianList) {
-// if (gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
-// matchingParticipants.add(gm);
-// break;
-// }
-// }
-// } else if (regularExpression.toUpperCase().equals("!SIGNALER")) {
-// for (GuardianMember gm : guardianList) {
-// if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
-// matchingParticipants.add(gm);
-// }
-// }
-//
-// } else {
-// //Create an java regular expression
-// String re = createJavaRegularExpression(regularExpression);
-//
-// for (GuardianMember gm : guardianList) {
-// if (gm.getParticipantIdentifier().matches(re)) {
-// matchingParticipants.add(gm);
-// }
-// }
-// }
-//
-// return matchingParticipants;
-// }
-
/* Valid expressions: *, <Context>.*, <Context>, *.<Context>, *.<Context>.*,
* *.<Context>.*.<Context>.*, <REG_EXP> || <REG_EXP>
*