You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by do...@apache.org on 2009/08/12 15:34:41 UTC

svn commit: r803501 - in /tuscany/sandbox/dougsleite/guardian-model: pom.xml src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java

Author: dougsleite
Date: Wed Aug 12 13:34:41 2009
New Revision: 803501

URL: http://svn.apache.org/viewvc?rev=803501&view=rev
Log:
- 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.

Modified:
    tuscany/sandbox/dougsleite/guardian-model/pom.xml
    tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
    tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java

Modified: tuscany/sandbox/dougsleite/guardian-model/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sandbox/dougsleite/guardian-model/pom.xml?rev=803501&r1=803500&r2=803501&view=diff
==============================================================================
--- tuscany/sandbox/dougsleite/guardian-model/pom.xml (original)
+++ tuscany/sandbox/dougsleite/guardian-model/pom.xml Wed Aug 12 13:34:41 2009
@@ -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>
 

Modified: tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java?rev=803501&r1=803500&r2=803501&view=diff
==============================================================================
--- tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java (original)
+++ tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java Wed Aug 12 13:34:41 2009
@@ -22,7 +22,6 @@
 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.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 @@
         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 @@
         }
 
         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;
+            Integer minParticipantJoined;
+            Integer maxParticipantJoined;
 
-            try {
+            OMElement throwException;
+            while (throwExceptionElements.hasNext()) {
 
-                while (recoveryRulesReader.hasNext() && !(recoveryRulesReader.isEndElement() && recoveryRulesReader.getLocalName().equals(Constants.PARTICIPANT))) {
-                    recoveryRulesReader.next();
+                throwException = throwExceptionElements.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));
-                            }
-                        }
+                className = getAttributeValue(throwException, Constants.CLASS);
+                targetContextName = getAttributeValue(throwException, Constants.TARGET_CONTEXT);
 
-                        //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;
-                            }
-                        }
+                try {
+                    minParticipantJoined = Integer.parseInt(getAttributeValue(throwException, Constants.MIN_PARTICIPANT_JOINED));
+                } catch (NumberFormatException nex) {
+                    minParticipantJoined = null;
+                }
 
-                        //<affected_participants>
-                        String affectedParticipants = affectedParticipantsTag();
-                        int index = -1;
-
-                        //Verify if the parameter is an index
-                        try {
-                            index = Integer.parseInt(affectedParticipants);
-                        } catch (NumberFormatException nexc) {
-                            index = -1;
-                        }
+                try {
+                    maxParticipantJoined = Integer.parseInt(getAttributeValue(throwException, Constants.MAX_PARTICIPANT_JOINED));
+                } catch (NumberFormatException nexc) {
+                    maxParticipantJoined = null;
+                }
 
-                        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();
+                //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;
+                    }
+                }
 
-                        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 {
+                //<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 @@
 
         //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 @@
             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

Modified: tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java?rev=803501&r1=803500&r2=803501&view=diff
==============================================================================
--- tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java (original)
+++ tuscany/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/ResolutionTreeUtils.java Wed Aug 12 13:34:41 2009
@@ -29,7 +29,7 @@
 
 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;