summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache')
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingImplementationPolicyProvider.java59
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicy.java38
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyDefinitionsProvider.java61
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyInterceptor.java172
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyProviderFactory.java58
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberFactoryImpl.java80
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java186
-rw-r--r--sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/InvalidPolicyAssociationException.java38
8 files changed, 692 insertions, 0 deletions
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingImplementationPolicyProvider.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingImplementationPolicyProvider.java
new file mode 100644
index 0000000000..01ca3a0166
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingImplementationPolicyProvider.java
@@ -0,0 +1,59 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+
+public class GuardianExceptionHandlingImplementationPolicyProvider implements PolicyProvider {
+
+ private MessageFactory messageFactory;
+ private RuntimeComponent component;
+ private RuntimeComponentService service;
+ private Binding binding;
+
+ public GuardianExceptionHandlingImplementationPolicyProvider(ExtensionPointRegistry extensionPoints,
+ RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ messageFactory = modelFactories.getFactory(MessageFactory.class);
+
+ this.component = component;
+ this.service = service;
+ this.binding = binding;
+ }
+
+ public Interceptor createInterceptor(Operation operation) {
+
+ return new GuardianExceptionHandlingPolicyInterceptor(service, service.getRuntimeWire(binding));
+ }
+
+ public String getPhase() {
+ return Phase.IMPLEMENTATION_POLICY;
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicy.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicy.java
new file mode 100644
index 0000000000..a4179bd666
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicy.java
@@ -0,0 +1,38 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Policy;
+
+public class GuardianExceptionHandlingPolicy implements Policy {
+
+ public QName getSchemaName() {
+ return null;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyDefinitionsProvider.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyDefinitionsProvider.java
new file mode 100644
index 0000000000..b1ca3f2edc
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyDefinitionsProvider.java
@@ -0,0 +1,61 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import java.net.URI;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.provider.SCADefinitionsProvider;
+import org.apache.tuscany.sca.provider.SCADefinitionsProviderException;
+
+public class GuardianExceptionHandlingPolicyDefinitionsProvider implements SCADefinitionsProvider {
+ private String definitionsFile = "org/apache/tuscany/sca/policy/guardianExceptionHandling/definitions.xml";
+ URLArtifactProcessor urlArtifactProcessor = null;
+
+ public GuardianExceptionHandlingPolicyDefinitionsProvider(ExtensionPointRegistry registry) {
+ URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class);
+ }
+
+ public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException {
+ // Allow privileged access to load resource. Requires RuntimePermssion in security policy.
+ URL definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return getClass().getClassLoader().getResource(definitionsFile);
+ }
+ });
+
+ try {
+ URI uri = new URI(definitionsFile);
+ return (SCADefinitions)urlArtifactProcessor.read(null,
+ uri,
+ definitionsFileUrl);
+ } catch ( Exception e ) {
+ throw new SCADefinitionsProviderException(e);
+ }
+ }
+
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyInterceptor.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyInterceptor.java
new file mode 100644
index 0000000000..a98b300aae
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyInterceptor.java
@@ -0,0 +1,172 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.tuscany.sca.implementation.guardian.common.Context;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.implementation.guardian.GuardianMember;
+import org.apache.tuscany.sca.implementation.guardian.common.GlobalException;
+import org.apache.tuscany.sca.implementation.guardian.common.GlobalExceptionInterface;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+public class GuardianExceptionHandlingPolicyInterceptor implements Interceptor {
+
+ public static final String ENABLE_CONTEXT = "enableContext";
+ public static final String REMOVE_CONTEXT = "removeContext";
+ public static final String GTHROW = "gthrow";
+ public static final String PROPAGATE = "propagate";
+ public static final String CHECK_EXCEPTION_STATUS = "checkExceptionStatus";
+ private Invoker next;
+ private RuntimeWire runtimeWire;
+ private RuntimeComponentService service;
+
+ public GuardianExceptionHandlingPolicyInterceptor(RuntimeComponentService service, RuntimeWire runtimeWire) {
+ super();
+ this.runtimeWire = runtimeWire;
+ this.service = service;
+ }
+
+ //IMPLEMENTAR A LOGICA ENTRE {P <-> GM <-> GG}
+ public Message invoke(Message msg) {
+
+ Class targetComponentImplClass = msg.getTo().getComponent().getImplementation().getClass();
+
+ String implementationGuardian = "org.apache.tuscany.sca.implementation.guardian.impl.GuardianGroupImplementationImpl";
+ Message responseMsg = null;
+
+// //Test the target component - must be a implemenation.guardian
+// try {
+// if (!targetComponentImplClass.equals(Class.forName(implementationJava))) {
+// throw new InvalidPolicyAssociationException("The target component must be a implementation.guardian");
+// }
+// } catch (ClassNotFoundException ex) {
+// Logger.getLogger(GuardianExceptionHandlingPolicyInterceptor.class.getName()).log(Level.SEVERE, null, ex);
+// }
+
+ try {
+ if (targetComponentImplClass.equals(Class.forName(implementationGuardian))) {
+
+ String msgOperationName = msg.getOperation().getName();
+ String componentName = msg.getFrom().getComponent().getName();
+
+ GuardianMemberFactoryImpl factory = GuardianMemberFactoryImpl.getInstance();
+ GuardianMember gm = factory.createGuardianMember(componentName, msg, this);
+
+ Object msgBody = msg.getBody();
+
+ if (msgOperationName.equals(ENABLE_CONTEXT)) {
+ Context context = (Context)((Object[]) msg.getBody())[0];
+ gm.enableContext(context);
+ msg.setBody(null);
+ return msg;
+ } else if (msgOperationName.equals(REMOVE_CONTEXT)) {
+ Context removedContext = gm.removeContext();
+ msg.setBody(removedContext);
+
+ //All the contexts were removed
+ if(gm.getCurrentContext().equals(Context.INIT_CONTEXT)) {
+ factory.removeGuardianMember(componentName, msg, this);
+ }
+
+ return msg;
+ } else if (msgOperationName.equals(GTHROW)) {
+ GlobalExceptionInterface ex = (GlobalExceptionInterface) ((Object[]) msgBody)[0];
+ List<String> participantList = (List<String>) ((Object[]) msgBody)[1];
+ gm.gthrow(ex, participantList);
+ msg.setBody(null);
+ return msg;
+ } else if (msgOperationName.equals(PROPAGATE)) {
+ GlobalExceptionInterface ex = (GlobalExceptionInterface) ((Object[]) msgBody)[0];
+ boolean response = gm.propagate(ex);
+ msg.setBody(response);
+ return msg;
+ } else if (msgOperationName.equals(CHECK_EXCEPTION_STATUS)) {
+ try {
+ gm.checkExceptionStatus();
+ msg.setBody(null);
+ } catch (GlobalException ex) {
+ msg.setFaultBody(ex);
+ }
+ return msg;
+ }
+ } else {
+ //throw new UnsupportedOperationException("Invocation of " + msgOperationName + " is not allowed");
+ responseMsg = getNext().invoke(msg);
+ }
+ } catch (ClassNotFoundException ex) {
+ Logger.getLogger(GuardianExceptionHandlingPolicyInterceptor.class.getName()).log(Level.SEVERE, null, ex);
+ }
+
+ return responseMsg;
+ }
+
+ public Message invokeGuardianGroupOperation(String operationName, Message msg) {
+
+ //Changing the operation
+ Operation desiredOperation = findOperation(operationName);
+
+ msg.setOperation(desiredOperation);
+
+ RuntimeComponent component = msg.getTo().getComponent();
+ ImplementationProvider implProvider = component.getImplementationProvider();
+
+ Message responseMsg = implProvider.createInvoker(this.service, desiredOperation).invoke(msg);
+
+ return responseMsg;
+ }
+
+ private Operation findOperation(String method) {
+ if (method.contains(".")) {
+ method = method.substring(method.lastIndexOf(".") + 1);
+ }
+
+ List<Operation> operations = runtimeWire.getTarget().getInterfaceContract().getInterface().getOperations();
+
+ Operation result = null;
+ for (Operation o : operations) {
+ if (o.getName().equalsIgnoreCase(method)) {
+ result = o;
+ break;
+ }
+ }
+
+ return result;
+ }
+
+
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyProviderFactory.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyProviderFactory.java
new file mode 100644
index 0000000000..bd2d67ad6f
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianExceptionHandlingPolicyProviderFactory.java
@@ -0,0 +1,58 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+public class GuardianExceptionHandlingPolicyProviderFactory implements PolicyProviderFactory<GuardianExceptionHandlingPolicy> {
+
+ private ExtensionPointRegistry extensionPoints;
+
+ public GuardianExceptionHandlingPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.extensionPoints = registry;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) {
+ return null;
+ }
+
+ public PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ return null;
+ }
+
+ public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ return new GuardianExceptionHandlingImplementationPolicyProvider(extensionPoints, component, service, binding);
+ }
+
+ public Class getModelType() {
+ return null;
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberFactoryImpl.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberFactoryImpl.java
new file mode 100644
index 0000000000..2f5e9617ed
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberFactoryImpl.java
@@ -0,0 +1,80 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.tuscany.sca.implementation.guardian.GuardianMember;
+import org.apache.tuscany.sca.invocation.Message;
+
+public class GuardianMemberFactoryImpl {
+
+ Map<String, GuardianMember> guardianMembers;
+ private static GuardianMemberFactoryImpl instance = null;
+
+ public static GuardianMemberFactoryImpl getInstance() {
+ if (instance == null) {
+ instance = new GuardianMemberFactoryImpl();
+ }
+ return instance;
+ }
+
+ protected GuardianMemberFactoryImpl() {
+ guardianMembers = new HashMap<String, GuardianMember>();
+ }
+
+ public GuardianMember createGuardianMember(String componentName, Message msg, GuardianExceptionHandlingPolicyInterceptor interceptor) {
+ GuardianMemberImpl gm = (GuardianMemberImpl) guardianMembers.get(componentName);
+
+ if (gm == null) {
+ gm = new GuardianMemberImpl(componentName, msg, interceptor);
+ guardianMembers.put(componentName, gm);
+
+ //Inform the Guardian Group of the new Guardian Member
+ Object msgBody = msg.getBody();
+
+ msg.setBody(gm);
+ interceptor.invokeGuardianGroupOperation("addGuardianMember", msg);
+
+ msg.setBody(msgBody);
+ }
+
+ gm.setMessage(msg);
+ gm.setGuardianExceptionHandlingPolicyInterceptor(interceptor);
+
+ return gm;
+ }
+
+ public GuardianMember removeGuardianMember(String componentName, Message msg, GuardianExceptionHandlingPolicyInterceptor interceptor) {
+
+ GuardianMember gm = guardianMembers.remove(componentName);
+
+ if (gm != null) {
+
+ Object msgBody = msg.getBody();
+
+ msg.setBody(gm);
+ interceptor.invokeGuardianGroupOperation("removeGuardianMember", msg);
+
+ msg.setBody(msgBody);
+ }
+
+ return gm;
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java
new file mode 100644
index 0000000000..5e9ae7853c
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java
@@ -0,0 +1,186 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.tuscany.sca.implementation.guardian.common.GlobalExceptionInterface;
+import org.apache.tuscany.sca.implementation.guardian.GuardianGroup;
+import org.apache.tuscany.sca.implementation.guardian.GuardianMember;
+import org.apache.tuscany.sca.implementation.guardian.common.Context;
+import org.apache.tuscany.sca.implementation.guardian.common.GlobalException;
+import org.apache.tuscany.sca.implementation.guardian.common.JoinException;
+import org.apache.tuscany.sca.implementation.guardian.common.SuspendException;
+import org.apache.tuscany.sca.invocation.Message;
+
+public class GuardianMemberImpl implements GuardianMember {
+
+ private int participantState;
+ private Stack<Context> contextList;
+ private Queue<GlobalException> exceptionQueue;
+ private String id;
+
+ //FIXME: Review the usage of this variable
+ private boolean exceptionThrown;
+ private Message msg;
+ private GuardianExceptionHandlingPolicyInterceptor interceptor;
+
+ protected GuardianMemberImpl(String componentName, Message msg, GuardianExceptionHandlingPolicyInterceptor interceptor) {
+ contextList = new Stack<Context>();
+ contextList.add(Context.INIT_CONTEXT);
+ exceptionQueue = new LinkedList<GlobalException>();
+ participantState = GuardianGroup.NORMAL_PARTICIPANT_STATE;
+ exceptionThrown = false;
+
+ this.id = componentName;
+ this.msg = msg;
+ this.interceptor = interceptor;
+ }
+
+ public void setGuardianExceptionHandlingPolicyInterceptor(GuardianExceptionHandlingPolicyInterceptor interceptor) {
+ this.interceptor = interceptor;
+ }
+
+ public GuardianExceptionHandlingPolicyInterceptor getGuardianExceptionHandlingPolicyInterceptor() {
+ return this.interceptor;
+ }
+
+ public void setMessage(Message msg) {
+ this.msg = msg;
+ }
+
+ public Message getMessage() {
+ return this.msg;
+ }
+
+ public void addException(GlobalException ex) {
+ exceptionQueue.add(ex);
+ }
+
+ public Context getCurrentContext() {
+ return contextList.peek();
+ }
+
+ public void enableContext(Context context) {
+ //Update the context list with the related set of exceptions
+
+ if (contextList.size() == 1) {
+ contextList.push(context);
+
+ JoinException ex = new JoinException();
+ ex.setSignalingContext(context);
+ ex.putSignalingParticipant(getParticipantIdentifier());
+ gthrow(ex, null);
+ } else {
+ contextList.push(context);
+ }
+
+ }
+
+ public Context removeContext() {
+// if (contextList.size() > 1) {
+// return contextList.pop();
+// }
+ return contextList.pop();
+ }
+
+ //If participantList is null then signal to ALL participants
+ public void gthrow(GlobalExceptionInterface ex, List<String> participantList) {
+ //1)Block the participant until raise an exception
+
+ if (!(ex instanceof SuspendException)) {
+ //Set the exception's parameters
+ ex.setSignalingContext(getCurrentContext());
+ ex.putSignalingParticipant(getParticipantIdentifier());
+
+ //Prepare the parameters
+ Object[] params = {ex, participantList};
+ msg.setBody(params);
+
+ interceptor.invokeGuardianGroupOperation("gthrow", msg);
+ //guardianGroup.gthrow(ex, participantList);
+
+ exceptionThrown = true;
+ } else {
+ setParticipantState(GuardianGroup.SUSPENDED_PARTICIPANT_STATE);
+ }
+ }
+
+ public boolean propagate(GlobalExceptionInterface ex) {
+ //1)Compares the current context with the exception's target context
+ return !getCurrentContext().equals(ex.getTargetContext());
+ }
+
+ public void checkExceptionStatus() throws GlobalException {
+
+ //Blocks until the state be diferent the SUSPENDED_STATE
+ while (participantState == GuardianGroup.SUSPENDED_PARTICIPANT_STATE && exceptionThrown) {
+ System.out.println(getParticipantIdentifier() + ": I am blocked!");
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(GuardianMemberImpl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ exceptionThrown = false;
+ System.out.println(getParticipantIdentifier() + ": I am not blocked!");
+
+ GlobalException exc;
+
+ if ((exc = exceptionQueue.peek()) == null) {
+ System.out.println(getParticipantIdentifier() + "#No exception on exception queue");
+ return;
+ }
+
+ //Check if ex.targetContext() matches the participant id
+ //Eg. ex.targetContext(): Main and participant id: Init.Main.Backup -> should thrown the exception
+ //Test if the exception should be thrown in the target context
+ for (Context c : contextList) {
+ if (exc.getTargetContext().equals(c) && (c.equals(Context.INIT_CONTEXT) || c.getExceptionList().contains(exc.getClass()))) {
+ System.out.println(getParticipantIdentifier() + "#Returning an exception");
+ exceptionQueue.poll();
+ throw exc;
+ }
+ }
+
+ return;
+ }
+
+ public String getParticipantIdentifier() {
+ //1) Return the participant identifier -> context list dot separated
+ StringBuffer participantIdentifier = new StringBuffer();
+ participantIdentifier.append(this.id);
+ for (int i = 0; i < contextList.size(); i++) {
+ participantIdentifier.append("." + contextList.get(i).getName());
+ }
+ return participantIdentifier.toString();
+ }
+
+ public int getParticipantState() {
+ return participantState;
+ }
+
+ public void setParticipantState(int state) {
+ this.participantState = state;
+ }
+}
diff --git a/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/InvalidPolicyAssociationException.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/InvalidPolicyAssociationException.java
new file mode 100644
index 0000000000..183e60c8be
--- /dev/null
+++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/InvalidPolicyAssociationException.java
@@ -0,0 +1,38 @@
+/*
+ * 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.tuscany.sca.policy.guardianExceptionHandling;
+
+public class InvalidPolicyAssociationException extends RuntimeException {
+
+ public InvalidPolicyAssociationException() {
+ super();
+ }
+
+ public InvalidPolicyAssociationException(String message) {
+ super(message);
+ }
+
+ public InvalidPolicyAssociationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidPolicyAssociationException(Throwable cause) {
+ super(cause);
+ }
+}