summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/core
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-08 23:39:36 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-08 23:39:36 +0000
commit9059026361e282b7f867817bcf8fd721030c8f8d (patch)
treeb5cb829671d35f8bcd604570cd8c1a8f03ae07f7 /java/sca/modules/core
parenta36d95000a638694fa3004cf5a2da0fe44808921 (diff)
Refactor the PolicyProviderFactory to take Endpoint and EndpointReference
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@792358 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core')
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java32
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java10
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java8
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java16
-rw-r--r--java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java26
-rw-r--r--java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/CallbackInterfaceInterceptorTestCase.java.fixme62
-rw-r--r--java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java3
-rw-r--r--java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/NonBlockingInterceptorTestCase.java.fixme74
8 files changed, 66 insertions, 165 deletions
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
index cd27763885..15c38db0e7 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java
@@ -230,7 +230,7 @@ public class CompositeActivatorImpl implements CompositeActivator {
.getName());
}
for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
- PolicyProvider policyProvider = f.createImplementationPolicyProvider(component, implementation);
+ PolicyProvider policyProvider = f.createImplementationPolicyProvider(component);
if (policyProvider != null) {
component.addPolicyProvider(policyProvider);
}
@@ -315,10 +315,8 @@ public class CompositeActivatorImpl implements CompositeActivator {
((RuntimeComponentService) service).setBindingProvider(binding,
bindingProvider);
}
- for (PolicyProviderFactory f : providerFactories
- .getPolicyProviderFactories()) {
- PolicyProvider policyProvider = f.createServicePolicyProvider(
- component, service, binding);
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createServicePolicyProvider(endpoint);
if (policyProvider != null) {
service.addPolicyProvider(binding, policyProvider);
}
@@ -530,6 +528,11 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
RuntimeComponentService runtimeService = (RuntimeComponentService)service;
for (Endpoint endpoint : service.getEndpoints()) {
+ // FIXME: Should the policy providers be started before the endpoint is started?
+ for (PolicyProvider policyProvider : runtimeService.getPolicyProviders(endpoint.getBinding())) {
+ policyProvider.start();
+ }
+
final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(endpoint.getBinding());
if (bindingProvider != null) {
// bindingProvider.start();
@@ -549,6 +552,9 @@ public class CompositeActivatorImpl implements CompositeActivator {
if (implementation instanceof Composite) {
start((Composite)implementation);
} else {
+ for (PolicyProvider policyProvider : runtimeComponent.getPolicyProviders()) {
+ policyProvider.start();
+ }
ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
if (implementationProvider != null) {
implementationProvider.start();
@@ -588,6 +594,10 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
});
}
+ for (PolicyProvider policyProvider : ((RuntimeComponentService)service).getPolicyProviders(endpoint
+ .getBinding())) {
+ policyProvider.stop();
+ }
}
}
for (ComponentReference reference : component.getReferences()) {
@@ -607,6 +617,11 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
});
}
+ for (PolicyProvider policyProvider : ((RuntimeComponentReference)reference)
+ .getPolicyProviders(endpointReference.getBinding())) {
+ policyProvider.stop();
+ }
+
}
}
Implementation implementation = component.getImplementation();
@@ -623,6 +638,9 @@ public class CompositeActivatorImpl implements CompositeActivator {
}
});
}
+ for (PolicyProvider policyProvider : ((RuntimeComponent)component).getPolicyProviders()) {
+ policyProvider.stop();
+ }
}
if (component instanceof ScopedRuntimeComponent) {
@@ -722,6 +740,10 @@ public class CompositeActivatorImpl implements CompositeActivator {
if (bindingProvider != null) {
bindingProvider.stop();
}
+ for (PolicyProvider policyProvider : ((RuntimeComponentReference)reference)
+ .getPolicyProviders(endpointReference.getBinding())) {
+ policyProvider.stop();
+ }
}
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java
index c0a9f616f6..3fdc35a720 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.core.assembly.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -43,7 +44,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWire;
public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference {
private ArrayList<RuntimeWire> wires;
private HashMap<Binding, ReferenceBindingProvider> bindingProviders =
- new HashMap<Binding, ReferenceBindingProvider>();
+ new HashMap<Binding, ReferenceBindingProvider>();
private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
private RuntimeComponent component;
@@ -134,7 +135,12 @@ public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implem
}
public List<PolicyProvider> getPolicyProviders(Binding binding) {
- return policyProviders.get(binding);
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ return Collections.emptyList();
+ } else {
+ return providers;
+ }
}
@Override
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java
index 776d35327d..ffa488b7bd 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentServiceImpl.java
@@ -20,6 +20,7 @@
package org.apache.tuscany.sca.core.assembly.impl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -153,7 +154,12 @@ public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements
}
public List<PolicyProvider> getPolicyProviders(Binding binding) {
- return policyProviders.get(binding);
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ return Collections.emptyList();
+ } else {
+ return providers;
+ }
}
@Override
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java
index 32645244fb..3ec13b2190 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java
@@ -354,6 +354,9 @@ public class RuntimeWireImpl implements RuntimeWire {
}
});
}
+ for (PolicyProvider policyProvider : runtimeRef.getPolicyProviders(endpointReference.getBinding())) {
+ policyProvider.start();
+ }
InterfaceContract bindingContract = getInterfaceContract(endpointReference.getReference(), endpointReference.getBinding());
Endpoint endpoint = endpointReference.getTargetEndpoint();
@@ -377,8 +380,7 @@ public class RuntimeWireImpl implements RuntimeWire {
for (PolicyProviderFactory f : providerFactories
.getPolicyProviderFactories()) {
PolicyProvider policyProvider = f
- .createReferencePolicyProvider(component, reference,
- binding);
+ .createReferencePolicyProvider(endpointReference);
if (policyProvider != null) {
reference.addPolicyProvider(binding, policyProvider);
}
@@ -425,7 +427,7 @@ public class RuntimeWireImpl implements RuntimeWire {
if (p instanceof PolicyProviderRRB) {
Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor();
if (interceptor != null) {
- bindingInvocationChain.addInterceptor(p.getPhase(), interceptor);
+ bindingInvocationChain.addInterceptor(interceptor);
}
}
}
@@ -449,7 +451,7 @@ public class RuntimeWireImpl implements RuntimeWire {
if (p instanceof PolicyProviderRRB) {
Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor();
if (interceptor != null) {
- bindingInvocationChain.addInterceptor(p.getPhase(), interceptor);
+ bindingInvocationChain.addInterceptor(interceptor);
}
}
}
@@ -555,7 +557,7 @@ public class RuntimeWireImpl implements RuntimeWire {
for (PolicyProvider p : pps) {
Interceptor interceptor = p.createInterceptor(operation);
if (interceptor != null) {
- chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ chain.addInterceptor(p.createInterceptor(operation));
}
}
}
@@ -578,7 +580,7 @@ public class RuntimeWireImpl implements RuntimeWire {
for (PolicyProvider p : pps) {
Interceptor interceptor = p.createInterceptor(operation);
if (interceptor != null) {
- chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ chain.addInterceptor(p.createInterceptor(operation));
}
}
}
@@ -640,7 +642,7 @@ public class RuntimeWireImpl implements RuntimeWire {
for (PolicyProvider p : pps) {
Interceptor interceptor = p.createInterceptor(operation);
if (interceptor != null) {
- chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ chain.addInterceptor(p.createInterceptor(operation));
}
}
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java
index 3c7fefb674..d8eb746776 100644
--- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java
+++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImpl.java
@@ -28,6 +28,7 @@ import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.InvocationChain;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
/**
* Default implementation of an invocation chain
@@ -45,9 +46,6 @@ public class InvocationChainImpl implements InvocationChain {
private boolean allowsPassByReference;
public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) {
- // TODO - binding invocation chain doesn't provide operations
- //assert sourceOperation != null;
- //assert targetOperation != null;
this.targetOperation = targetOperation;
this.sourceOperation = sourceOperation;
this.forReference = forReference;
@@ -62,11 +60,25 @@ public class InvocationChainImpl implements InvocationChain {
}
public void addInterceptor(Interceptor interceptor) {
+ if (interceptor instanceof PhasedInterceptor) {
+ PhasedInterceptor pi = (PhasedInterceptor)interceptor;
+ if (pi.getPhase() != null) {
+ addInvoker(pi.getPhase(), pi);
+ return;
+ }
+ }
String phase = forReference ? Phase.REFERENCE : Phase.SERVICE;
addInterceptor(phase, interceptor);
}
public void addInvoker(Invoker invoker) {
+ if (invoker instanceof PhasedInterceptor) {
+ PhasedInterceptor pi = (PhasedInterceptor)invoker;
+ if (pi.getPhase() != null) {
+ addInvoker(pi.getPhase(), pi);
+ return;
+ }
+ }
String phase = forReference ? Phase.REFERENCE_BINDING : Phase.IMPLEMENTATION;
addInvoker(phase, invoker);
}
@@ -75,10 +87,6 @@ public class InvocationChainImpl implements InvocationChain {
return nodes.isEmpty() ? null : nodes.get(0).getInvoker();
}
- public Invoker getTailInvoker() {
- return nodes.isEmpty() ? null : nodes.get(nodes.size() - 1).getInvoker();
- }
-
/**
* @return the sourceOperation
*/
@@ -93,10 +101,6 @@ public class InvocationChainImpl implements InvocationChain {
this.sourceOperation = sourceOperation;
}
- public void addInterceptor(int index, Interceptor interceptor) {
- addInterceptor(interceptor);
- }
-
public void addInterceptor(String phase, Interceptor interceptor) {
addInvoker(phase, interceptor);
}
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/CallbackInterfaceInterceptorTestCase.java.fixme b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/CallbackInterfaceInterceptorTestCase.java.fixme
deleted file mode 100644
index b11eaa9621..0000000000
--- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/CallbackInterfaceInterceptorTestCase.java.fixme
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.core.wire;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl;
-import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor;
-import org.apache.tuscany.sca.core.invocation.impl.MessageFactoryImpl;
-import org.apache.tuscany.sca.invocation.Interceptor;
-import org.apache.tuscany.sca.invocation.Message;
-import org.easymock.EasyMock;
-import org.oasisopen.sca.NoRegisteredCallbackException;
-
-/**
- * @version $Rev$ $Date$
- */
-public class CallbackInterfaceInterceptorTestCase extends TestCase {
-
- public void testHasCallbackObject() {
- CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor();
- Interceptor next = EasyMock.createMock(Interceptor.class);
- EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null);
- EasyMock.replay(next);
- interceptor.setNext(next);
- Message msg = new MessageFactoryImpl().createMessage();
- msg.setFrom(new EndpointReferenceImpl("uri"));
- msg.getFrom().getReferenceParameters().setCallbackObjectID("ABC");
- interceptor.invoke(msg);
- EasyMock.verify(next);
- }
-
- public void testNoCallbackObject() {
- CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor();
- Message msg = new MessageFactoryImpl().createMessage();
- msg.setFrom(new EndpointReferenceImpl("uri"));
- msg.getFrom().getReferenceParameters().setCallbackObjectID(null);
- try {
- interceptor.invoke(msg);
- fail();
- } catch (NoRegisteredCallbackException e) {
- // expected
- }
- }
-
-}
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java
index d6367163fa..c8990686b9 100644
--- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java
+++ b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/InvocationChainImplTestCase.java
@@ -45,8 +45,6 @@ public class InvocationChainImplTestCase {
Interceptor head = (Interceptor)chain.getHeadInvoker();
assertEquals(inter1, head);
assertEquals(inter2, head.getNext());
- assertEquals(inter2, chain.getTailInvoker());
-
}
@Test
@@ -66,7 +64,6 @@ public class InvocationChainImplTestCase {
assertEquals(inter2, inter1.getNext());
assertEquals(inter3, inter2.getNext());
assertEquals(inter4, inter3.getNext());
- assertEquals(inter4, chain.getTailInvoker());
}
private class MockInterceptor implements Interceptor {
diff --git a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/NonBlockingInterceptorTestCase.java.fixme b/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/NonBlockingInterceptorTestCase.java.fixme
deleted file mode 100644
index b8150d4edc..0000000000
--- a/java/sca/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/impl/NonBlockingInterceptorTestCase.java.fixme
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.core.wire;
-
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
-import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
-import org.apache.tuscany.sca.invocation.Interceptor;
-import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.work.WorkScheduler;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-
-/**
- * @version $Rev$ $Date$
- */
-public class NonBlockingInterceptorTestCase extends TestCase {
-
- public void testInvoke() throws Exception {
- WorkScheduler scheduler = createMock(WorkScheduler.class);
- scheduler.scheduleWork(isA(Runnable.class));
- expectLastCall().andStubAnswer(new IAnswer<Object>() {
- public Object answer() throws Throwable {
- Runnable runnable = (Runnable) getCurrentArguments()[0];
- runnable.run();
- return null;
- }
- });
- replay(scheduler);
- Message context = createMock(Message.class);
- //String convID = "convID";
- //TODO port to the new way of dealing with conversation IDs later
- //EasyMock.expect(context.getConversationID()).andReturn(convID);
- EasyMock.replay(context);
- ThreadMessageContext.setMessageContext(context);
- Message msg = createMock(Message.class);
- //TODO port to the new way of dealing with conversation IDs later
- //msg.setConversationID(convID);
- Interceptor next = EasyMock.createMock(Interceptor.class);
- EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
- EasyMock.expect(msg.isFault()).andReturn(false);
- EasyMock.replay(next);
- EasyMock.replay(msg);
- Interceptor interceptor = new NonBlockingInterceptor(scheduler, next);
- interceptor.invoke(msg);
- verify(context);
- verify(next);
- verify(msg);
- }
-
-}