Author: rfeng
Date: Wed Aug 29 13:48:35 2007
New Revision: 570929
URL: http://svn.apache.org/viewvc?rev=570929&view=rev
Log:
Remove createSelfReferences() from CompositeConfigurationBuilderImpl and change
SCADomain.getService() to leverage ServiceReference and support remote target
which is not available in the local partition of the SCA domain. In the remote
case, the getService will return a non-null proxy even though the component
name cannot be matched locally. I have to adjust a few test cases to handle
this behavior.
Modified:
incubator/tuscany/java/sca/itest/extended-api/src/test/java/org/apache/tuscany/sca/test/extended/ServiceLocateTestCase.java
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
incubator/tuscany/java/sca/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
Modified:
incubator/tuscany/java/sca/itest/extended-api/src/test/java/org/apache/tuscany/sca/test/extended/ServiceLocateTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/extended-api/src/test/java/org/apache/tuscany/sca/test/extended/ServiceLocateTestCase.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/extended-api/src/test/java/org/apache/tuscany/sca/test/extended/ServiceLocateTestCase.java
(original)
+++
incubator/tuscany/java/sca/itest/extended-api/src/test/java/org/apache/tuscany/sca/test/extended/ServiceLocateTestCase.java
Wed Aug 29 13:48:35 2007
@@ -56,7 +56,8 @@
*/
@Test(expected = ServiceRuntimeException.class)
public void badComponentName() {
- domain.getService(BasicService.class, "IvalidServiceName");
+ BasicService service = domain.getService(BasicService.class,
"IvalidServiceName");
+ service.negate(-1);
}
@Before
Modified:
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java
(original)
+++
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceEmbeddedSCADomainTestCase.java
Wed Aug 29 13:48:35 2007
@@ -75,7 +75,8 @@
Source source;
try {
source = domain.getService(Source.class, "SourceComponentXXX");
- assertNull(source);
+ // The source proxy can be created for the remote target but it
will throw exception when a method is invoked
+ source.clientMethod("ABC");
fail("Expected to generate org.osoa.sca.ServiceRuntimeException
but did not when invoking service with async");
} catch (org.osoa.sca.ServiceRuntimeException e) {
// expected.
Modified:
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java
(original)
+++
incubator/tuscany/java/sca/itest/recursive/src/test/java/composite/LocateServiceSCADomainTestCase.java
Wed Aug 29 13:48:35 2007
@@ -52,7 +52,8 @@
Source source;
try {
source = domain.getService(Source.class, "SourceComponentXXX");
- assertNull(source);
+ // The source proxy can be created for the remote target but it
will throw exception when a method is invoked
+ source.clientMethod("ABC");
fail("Expected to generate org.osoa.sca.ServiceRuntimeException
but did not when invoking service with async");
} catch (org.osoa.sca.ServiceRuntimeException e) {
// expected.
Modified:
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java
Wed Aug 29 13:48:35 2007
@@ -38,7 +38,6 @@
import org.apache.tuscany.sca.assembly.CompositeReference;
import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.Implementation;
-import org.apache.tuscany.sca.assembly.Multiplicity;
import org.apache.tuscany.sca.assembly.Property;
import org.apache.tuscany.sca.assembly.Reference;
import org.apache.tuscany.sca.assembly.SCABinding;
@@ -319,9 +318,9 @@
configureCallbackReferences(component, componentReferences);
// Create self references to the component's services
- if (!(component.getImplementation() instanceof Composite)) {
- createSelfReferences(component);
- }
+// if (!(component.getImplementation() instanceof Composite)) {
+// createSelfReferences(component);
+// }
// Initialize service bindings
for (ComponentService componentService : component.getServices()) {
@@ -980,49 +979,6 @@
}
/**
- * Create a self-reference for a component service
- *
- * @param component
- * @param service
- */
- private ComponentReference createSelfReference(Component component,
ComponentService service) {
- ComponentReference componentReference =
assemblyFactory.createComponentReference();
- componentReference.setName("$self$." + service.getName());
- componentReference.getBindings().addAll(service.getBindings());
- componentReference.setCallback(service.getCallback());
- ComponentService componentService =
assemblyFactory.createComponentService();
- componentService.setName(component.getName() + '/' +
service.getName());
- componentService.setUnresolved(true);
- componentReference.getTargets().add(componentService);
- componentReference.getPolicySets().addAll(service.getPolicySets());
-
componentReference.getRequiredIntents().addAll(service.getRequiredIntents());
-
- // FIXME: What interface contract should be used?
- InterfaceContract interfaceContract = service.getInterfaceContract();
- Service componentTypeService = service.getService();
- if (componentTypeService != null &&
componentTypeService.getInterfaceContract() != null) {
- interfaceContract = componentTypeService.getInterfaceContract();
- }
- componentReference.setInterfaceContract(interfaceContract);
- componentReference.setMultiplicity(Multiplicity.ONE_ONE);
- component.getReferences().add(componentReference);
- return componentReference;
- }
-
- /**
- * For all the services, create a corresponding self-reference.
- *
- * @param component
- */
- private void createSelfReferences(Component component) {
- for (ComponentService service : component.getServices()) {
- if (!service.isCallback()) {
- createSelfReference(component, service);
- }
- }
- }
-
- /**
* Activate composite services in nested composites.
*
* @param composite
@@ -1081,17 +1037,6 @@
.addAll(compositeService.getCallback().getBindings());
}
}
-
- // Create a self-reference for the promoted service
- ComponentReference selfReference =
- createSelfReference(promotedComponent,
newComponentService);
- Binding binding =
- BindingUtil.resolveBindings(selfReference,
- promotedComponent,
-
newComponentService);
- selfReference.getBindings().clear();
- selfReference.getBindings().add(binding);
- selfReference.getTargets().clear();
// Change the composite service to now promote the
// newly created component service directly
Modified:
incubator/tuscany/java/sca/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
(original)
+++
incubator/tuscany/java/sca/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
Wed Aug 29 13:48:35 2007
@@ -19,7 +19,6 @@
package org.apache.tuscany.sca.binding.sca.impl;
-import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.WireableBinding;
import org.apache.tuscany.sca.binding.sca.DistributedSCABinding;
@@ -37,6 +36,7 @@
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceUnavailableException;
/**
* The sca reference binding provider mediates between the twin requirements
of
@@ -66,8 +66,8 @@
this.extensionPoints = extensionPoints;
this.component = component;
this.reference = reference;
- this.binding = binding;
-
+ this.binding = binding;
+
// look to see if a distributed SCA binding implementation has
// been included on the classpath. This will be needed by the
// provider itself to do it's thing
@@ -76,82 +76,81 @@
distributedProviderFactory =
(BindingProviderFactory<DistributedSCABinding>)factoryExtensionPoint
.getProviderFactory(DistributedSCABinding.class);
-
+
// Get the distributed domain
distributedDomain = ((SCABindingImpl)binding).getDistributedDomain();
-
+
// determine if the target is remote. If we can tell now then this will
// do some initialization before we get to run time
isTargetRemote();
}
-
-
+
public boolean isTargetRemote() {
boolean targetIsRemote = false;
-
+
// first look at the target service and see if this has been resolved
- if (((WireableBinding)binding).getTargetComponentService() != null ) {
- if
(((WireableBinding)binding).getTargetComponentService().isUnresolved() == true
) {
+ if (((WireableBinding)binding).getTargetComponentService() != null) {
+ if
(((WireableBinding)binding).getTargetComponentService().isUnresolved() == true)
{
targetIsRemote = true;
} else {
targetIsRemote = false;
}
- } else {
+ } else {
// if no target is found then this could be a completely dynamic
// reference, e.g. a callback, so check the domain to see if the
service is available
// at this node. The binding uri might be null here if the dynamic
reference has been
// fully configured yet. It won't have all of the information
until invocation time
- if ((distributedDomain != null) &&
- (binding.getURI() != null) ) {
+ if ((distributedDomain != null) && (binding.getURI() != null)) {
ServiceDiscovery serviceDiscovery =
distributedDomain.getServiceDiscovery();
-
- String serviceUrl =
serviceDiscovery.findServiceEndpoint(distributedDomain.getDomainName(),
-
binding.getURI(),
-
SCABinding.class.getName());
+
+ String serviceUrl =
+
serviceDiscovery.findServiceEndpoint(distributedDomain.getDomainName(),
+ binding.getURI(),
+
SCABinding.class.getName());
if (serviceUrl == null) {
targetIsRemote = false;
} else {
targetIsRemote = true;
}
-
+
}
}
-
+
// if we think the target is remote check that everything is
configured correctly
if (targetIsRemote) {
// initialize the remote provider if it hasn't been done already
- if (distributedProvider == null) {
+ if (distributedProvider == null) {
if
(!reference.getInterfaceContract().getInterface().isRemotable()) {
- throw new IllegalStateException("Reference interface not
remoteable for component: "+
- component.getName() +
- " and reference: " +
- reference.getName());
+ throw new IllegalStateException("Reference interface not
remoteable for component: " + component
+ .getName()
+ + " and reference: "
+ + reference.getName());
}
-
+
if (distributedProviderFactory == null) {
- throw new IllegalStateException("No distributed SCA
binding available for component: "+
- component.getName() +
- " and reference: " +
- reference.getName());
+ throw new IllegalStateException("No distributed SCA
binding available for component: " + component
+ .getName()
+ + " and reference: "
+ + reference.getName());
}
-
+
if (distributedDomain == null) {
- throw new IllegalStateException("No distributed domain
available for component: "+
- component.getName() +
- " and reference: " +
- reference.getName());
+ throw new IllegalStateException("No distributed domain
available for component: " + component
+ .getName()
+ + " and reference: "
+ + reference.getName());
}
-
+
// create the remote provider
DistributedSCABinding distributedBinding = new
DistributedSCABindingImpl();
distributedBinding.setSCABinging(binding);
-
+
distributedProvider =
(ReferenceBindingProvider2)distributedProviderFactory
.createReferenceBindingProvider(component, reference,
distributedBinding);
}
}
-
+
return targetIsRemote;
}
@@ -168,9 +167,9 @@
return distributedProvider.supportsAsyncOneWayInvocation();
} else {
return false;
- }
+ }
}
-
+
/**
* @param wire
*/
@@ -184,7 +183,7 @@
}
}
return null;
- }
+ }
public Invoker createInvoker(Operation operation) {
if (isTargetRemote()) {
@@ -193,7 +192,7 @@
RuntimeWire wire = reference.getRuntimeWire(binding);
Invoker invoker = getInvoker(wire, operation);
if (invoker == null) {
- throw new IllegalStateException("No service invoker");
+ throw new ServiceUnavailableException("No service invoker is
available for: " + binding.getURI());
}
return new RuntimeSCABindingInvoker(invoker);
}
@@ -215,15 +214,15 @@
started = true;
}
-// ComponentService service =
((WireableBinding)binding).getTargetComponentService();
-// if (service != null) {
-// RuntimeWire wire = reference.getRuntimeWire(binding);
-// InterfaceContract interfaceContract =
service.getInterfaceContract();
-// boolean dynamicService =
interfaceContract.getInterface().isDynamic();
-// if (!dynamicService) {
-// wire.getTarget().setInterfaceContract(interfaceContract);
-// }
-// }
+ // ComponentService service =
((WireableBinding)binding).getTargetComponentService();
+ // if (service != null) {
+ // RuntimeWire wire = reference.getRuntimeWire(binding);
+ // InterfaceContract interfaceContract =
service.getInterfaceContract();
+ // boolean dynamicService =
interfaceContract.getInterface().isDynamic();
+ // if (!dynamicService) {
+ //
wire.getTarget().setInterfaceContract(interfaceContract);
+ // }
+ // }
if (distributedProvider != null) {
distributedProvider.start();
Modified:
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
(original)
+++
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
Wed Aug 29 13:48:35 2007
@@ -23,6 +23,7 @@
import java.io.Reader;
import java.io.Writer;
+import org.apache.tuscany.sca.assembly.ComponentService;
import org.osoa.sca.CallableReference;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.ServiceReference;
@@ -86,4 +87,12 @@
<B> CallableReference<B> getCallableReference(Class<B> businessInterface,
RuntimeComponent
component,
RuntimeComponentService service);
+
+ /**
+ * @param <B>
+ * @param businessInterface
+ * @param service
+ * @return
+ */
+ <B> ServiceReference<B> createSelfReference(Class<B> businessInterface,
ComponentService service);
}
Modified:
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
Wed Aug 29 13:48:35 2007
@@ -120,11 +120,7 @@
public <B> ServiceReference<B> createSelfReference(Class<B>
businessInterface) {
ComponentService service =
ComponentContextHelper.getSingleService(component);
try {
- RuntimeComponentReference ref =
- (RuntimeComponentReference)createSelfReference(component,
service, businessInterface);
- ref.setComponent(component);
-
- return getServiceReference(businessInterface, ref);
+ return createSelfReference(businessInterface, service);
} catch (Exception e) {
throw new ServiceRuntimeException(e.getMessage(), e);
}
@@ -134,10 +130,7 @@
try {
for (ComponentService service : component.getServices()) {
if (serviceName.equals(service.getName())) {
- RuntimeComponentReference ref =
-
(RuntimeComponentReference)createSelfReference(component, service,
businessInterface);
- ref.setComponent(component);
- return getServiceReference(businessInterface, ref);
+ return createSelfReference(businessInterface, service);
}
}
throw new ServiceRuntimeException("Service not found: " +
serviceName);
@@ -145,6 +138,23 @@
throw e;
} catch (Exception e) {
throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * @param <B>
+ * @param businessInterface
+ * @param service
+ * @return
+ */
+ public <B> ServiceReference<B> createSelfReference(Class<B>
businessInterface, ComponentService service) {
+ try {
+ RuntimeComponentReference ref =
+ (RuntimeComponentReference)createSelfReference(component,
service, businessInterface);
+ ref.setComponent(component);
+ return getServiceReference(businessInterface, ref);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
}
}
Modified:
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
(original)
+++
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
Wed Aug 29 13:48:35 2007
@@ -37,23 +37,31 @@
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.WireableBinding;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.contribution.DeployedArtifact;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.service.ContributionException;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.contribution.service.util.FileHelper;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.osoa.sca.CallableReference;
-import org.osoa.sca.ComponentContext;
-import org.osoa.sca.Constants;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.ServiceRuntimeException;
@@ -111,7 +119,7 @@
try {
String contributionURI =
FileHelper.getName(contributionURL.getPath());
- if(contributionURI == null || contributionURI.length() == 0) {
+ if (contributionURI == null || contributionURI.length() == 0) {
contributionURI = contributionURL.toString();
}
contribution = contributionService.contribute(contributionURI,
contributionURL, false);
@@ -124,7 +132,7 @@
// Create an in-memory domain level composite
AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
domainComposite = assemblyFactory.createComposite();
- domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
+ domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
domainComposite.setURI(domainURI);
//when the deployable composites were specified when initializing the
runtime
@@ -142,19 +150,19 @@
throw new ServiceRuntimeException("Composite not found: "
+ compositePath);
}
domainComposite.getIncludes().add(composite);
- }
+ }
} else {
// in this case, a sca-contribution.xml should have been specified
- for(Composite composite : contribution.getDeployables()) {
+ for (Composite composite : contribution.getDeployables()) {
domainComposite.getIncludes().add(composite);
}
-
+
}
-
+
// Build the SCA composites
CompositeBuilder compositeBuilder = runtime.getCompositeBuilder();
-
- for (Composite composite: domainComposite.getIncludes()) {
+
+ for (Composite composite : domainComposite.getIncludes()) {
try {
compositeBuilder.build(composite);
} catch (CompositeBuilderException e) {
@@ -165,14 +173,14 @@
// Activate and start composites
CompositeActivator compositeActivator =
runtime.getCompositeActivator();
compositeActivator.setDomainComposite(domainComposite);
- for (Composite composite: domainComposite.getIncludes()) {
+ for (Composite composite : domainComposite.getIncludes()) {
try {
compositeActivator.activate(composite);
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
}
- for (Composite composite: domainComposite.getIncludes()) {
+ for (Composite composite : domainComposite.getIncludes()) {
try {
for (Component component : composite.getComponents()) {
compositeActivator.start(component);
@@ -183,23 +191,23 @@
}
// Index the top level components
- for (Composite composite: domainComposite.getIncludes()) {
+ for (Composite composite : domainComposite.getIncludes()) {
for (Component component : composite.getComponents()) {
components.put(component.getName(), component);
}
}
-
+
this.componentManager = new DefaultSCADomainComponentManager(this);
}
@Override
public void close() {
-
+
super.close();
// Stop and deactivate composites
CompositeActivator compositeActivator =
runtime.getCompositeActivator();
- for (Composite composite: domainComposite.getIncludes()) {
+ for (Composite composite : domainComposite.getIncludes()) {
try {
for (Component component : composite.getComponents()) {
compositeActivator.stop(component);
@@ -208,7 +216,7 @@
throw new ServiceRuntimeException(e);
}
}
- for (Composite composite: domainComposite.getIncludes()) {
+ for (Composite composite : domainComposite.getIncludes()) {
try {
compositeActivator.deactivate(composite);
} catch (ActivationException e) {
@@ -223,7 +231,7 @@
} catch (ContributionException e) {
throw new ServiceRuntimeException(e);
}
-
+
// Stop the runtime
try {
runtime.stop();
@@ -264,29 +272,30 @@
throw new IllegalArgumentException("Composite not found: " +
contributionArtifactPath);
}
} else {
-
+
// Here the SCADomain was started without any reference to a
composite file
// We are going to look for an sca-contribution.xml or
sca-contribution-generated.xml
-
+
// Look for META-INF/sca-contribution.xml
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
contributionArtifactURL =
classLoader.getResource(contributionArtifactPath);
-
+
// Look for META-INF/sca-contribution-generated.xml
- if( contributionArtifactURL == null ) {
+ if (contributionArtifactURL == null) {
contributionArtifactPath =
Contribution.SCA_CONTRIBUTION_GENERATED_META;
contributionArtifactURL =
classLoader.getResource(contributionArtifactPath);
}
-
- // Look for META-INF/sca-deployables directory
- if (contributionArtifactURL == null) {
- contributionArtifactPath =
Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
- contributionArtifactURL =
classLoader.getResource(contributionArtifactPath);
- }
+
+ // Look for META-INF/sca-deployables directory
+ if (contributionArtifactURL == null) {
+ contributionArtifactPath =
Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
+ contributionArtifactURL =
classLoader.getResource(contributionArtifactPath);
+ }
}
-
+
if (contributionArtifactURL == null) {
- throw new IllegalArgumentException("Can't determine contribution
deployables. Either specify a composite file, or use an sca-contribution.xml
file to specify the deployables.");
+ throw new IllegalArgumentException(
+ "Can't determine contribution
deployables. Either specify a composite file, or use an sca-contribution.xml
file to specify the deployables.");
}
URL contributionURL = null;
@@ -317,7 +326,7 @@
@Override
public <B, R extends CallableReference<B>> R cast(B target) throws
IllegalArgumentException {
- return (R) runtime.getProxyFactory().cast(target);
+ return (R)runtime.getProxyFactory().cast(target);
}
@Override
@@ -329,6 +338,38 @@
return serviceReference.getService();
}
+ private <B> ServiceReference<B> createServiceReference(Class<B>
businessInterface, String targetURI) {
+ try {
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(Constants.SCA10_TUSCANY_NS,
"default"));
+ RuntimeComponent component =
(RuntimeComponent)assemblyFactory.createComponent();
+ component.setName("default");
+ component.setURI("default");
+
runtime.getCompositeActivator().configureComponentContext(component);
+ composite.getComponents().add(component);
+ RuntimeComponentReference reference =
(RuntimeComponentReference)assemblyFactory.createComponentReference();
+ reference.setName("default");
+ ModelFactoryExtensionPoint factories =
+
runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
+ JavaInterfaceFactory javaInterfaceFactory =
factories.getFactory(JavaInterfaceFactory.class);
+ InterfaceContract interfaceContract =
javaInterfaceFactory.createJavaInterfaceContract();
+
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
+ reference.setInterfaceContract(interfaceContract);
+ component.getReferences().add(reference);
+ reference.setComponent(component);
+ SCABindingFactory scaBindingFactory =
factories.getFactory(SCABindingFactory.class);
+ SCABinding binding = scaBindingFactory.createSCABinding();
+ binding.setURI(targetURI);
+ ((WireableBinding)binding).setRemote(true);
+ reference.getBindings().add(binding);
+ return new ServiceReferenceImpl<B>(businessInterface, component,
reference, binding, runtime
+ .getProxyFactory(), runtime.getCompositeActivator());
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
@Override
public <B> ServiceReference<B> getServiceReference(Class<B>
businessInterface, String name) {
@@ -348,9 +389,10 @@
// Lookup the component in the domain
Component component = components.get(componentName);
if (component == null) {
- throw new ServiceRuntimeException("Component not found: " +
componentName);
+ // The component is not local in the partition, try to create a
remote service ref
+ return createServiceReference(businessInterface, name);
}
- ComponentContext componentContext = null;
+ RuntimeComponentContext componentContext = null;
// If the component is a composite, then we need to find the
// non-composite component that provides the requested service
@@ -362,26 +404,25 @@
if (serviceName != null) {
serviceName = "$promoted$." + serviceName;
}
- componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ componentContext =
+
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ return
componentContext.createSelfReference(businessInterface, compositeService
+ .getPromotedService());
}
break;
}
}
- if (componentContext == null) {
- throw new ServiceRuntimeException("Composite service not
found: " + name);
- }
+ // No matching service is found
+ throw new ServiceRuntimeException("Composite service not found: "
+ name);
} else {
componentContext =
((RuntimeComponent)component).getComponentContext();
+ if (serviceName != null) {
+ return componentContext.createSelfReference(businessInterface,
serviceName);
+ } else {
+ return componentContext.createSelfReference(businessInterface);
+ }
}
- ServiceReference<B> serviceReference;
- if (serviceName != null) {
- serviceReference =
componentContext.createSelfReference(businessInterface, serviceName);
- } else {
- serviceReference =
componentContext.createSelfReference(businessInterface);
- }
- return serviceReference;
-
}
@Override
@@ -405,8 +446,7 @@
}
return componentNames;
}
-
-
+
public Component getComponent(String componentName) {
for (DeployedArtifact artifact : contribution.getArtifacts()) {
if (artifact.getModel() instanceof Composite) {
@@ -419,7 +459,7 @@
}
return null;
}
-
+
public void startComponent(String componentName) throws
ActivationException {
Component component = getComponent(componentName);
if (component == null) {
Modified:
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
(original)
+++
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
Wed Aug 29 13:48:35 2007
@@ -26,16 +26,24 @@
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.WireableBinding;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
import org.apache.tuscany.sca.contribution.service.ContributionService;
import org.apache.tuscany.sca.core.assembly.ActivationException;
import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.osoa.sca.CallableReference;
-import org.osoa.sca.ComponentContext;
-import org.osoa.sca.Constants;
import org.osoa.sca.ServiceReference;
import org.osoa.sca.ServiceRuntimeException;
@@ -73,10 +81,11 @@
// Create an in-memory domain level composite
AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
domainComposite = assemblyFactory.createComposite();
- domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
+ domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
domainComposite.setURI(uri);
getCompositeActivator().setDomainComposite(domainComposite);
+
}
public void stop() throws ActivationException {
@@ -116,8 +125,7 @@
@Override
public <B, R extends CallableReference<B>> R cast(B target) throws
IllegalArgumentException {
- // TODO Auto-generated method stub
- return null;
+ return (R)runtime.getProxyFactory().cast(target);
}
@Override
@@ -129,6 +137,37 @@
return serviceReference.getService();
}
+ private <B> ServiceReference<B> createServiceReference(Class<B>
businessInterface, String targetURI) {
+ try {
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(Constants.SCA10_TUSCANY_NS,
"default"));
+ RuntimeComponent component =
(RuntimeComponent)assemblyFactory.createComponent();
+ component.setName("default");
+ component.setURI("default");
+
runtime.getCompositeActivator().configureComponentContext(component);
+ composite.getComponents().add(component);
+ RuntimeComponentReference reference =
(RuntimeComponentReference)assemblyFactory.createComponentReference();
+ reference.setName("default");
+ ModelFactoryExtensionPoint factories =
+
runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
+ JavaInterfaceFactory javaInterfaceFactory =
factories.getFactory(JavaInterfaceFactory.class);
+ InterfaceContract interfaceContract =
javaInterfaceFactory.createJavaInterfaceContract();
+
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
+ reference.setInterfaceContract(interfaceContract);
+ component.getReferences().add(reference);
+ reference.setComponent(component);
+ SCABindingFactory scaBindingFactory =
factories.getFactory(SCABindingFactory.class);
+ SCABinding binding = scaBindingFactory.createSCABinding();
+ binding.setURI(targetURI);
+ ((WireableBinding)binding).setRemote(true);
+ reference.getBindings().add(binding);
+ return new ServiceReferenceImpl<B>(businessInterface, component,
reference, binding, runtime
+ .getProxyFactory(), runtime.getCompositeActivator());
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
@Override
public <B> ServiceReference<B> getServiceReference(Class<B>
businessInterface, String name) {
@@ -146,53 +185,41 @@
}
// Lookup the component in the domain
- Component component = null;
- for (Composite composite: domainComposite.getIncludes()) {
- for (Component c: composite.getComponents()) {
- if (c.getName().equals(componentName)) {
- component = c;
- break;
- }
- }
- if (component != null)
- break;
- }
+ Component component = componentManager.getComponent(componentName);
if (component == null) {
- throw new ServiceRuntimeException("Component not found: " +
componentName);
+ // The component is not local in the partition, try to create a
remote service ref
+ return createServiceReference(businessInterface, name);
}
- ComponentContext componentContext = null;
+ RuntimeComponentContext componentContext = null;
// If the component is a composite, then we need to find the
- // non-composite
- // component that provides the requested service
+ // non-composite component that provides the requested service
if (component.getImplementation() instanceof Composite) {
for (ComponentService componentService : component.getServices()) {
if (serviceName == null ||
serviceName.equals(componentService.getName())) {
-
CompositeService compositeService =
(CompositeService)componentService.getService();
if (compositeService != null) {
if (serviceName != null) {
serviceName = "$promoted$." + serviceName;
}
- componentContext =
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ componentContext =
+
((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ return
componentContext.createSelfReference(businessInterface, compositeService
+ .getPromotedService());
}
break;
}
}
- if (componentContext == null) {
- throw new ServiceRuntimeException("Composite service not
found: " + name);
- }
+ // No matching service is found
+ throw new ServiceRuntimeException("Composite service not found: "
+ name);
} else {
componentContext =
((RuntimeComponent)component).getComponentContext();
+ if (serviceName != null) {
+ return componentContext.createSelfReference(businessInterface,
serviceName);
+ } else {
+ return componentContext.createSelfReference(businessInterface);
+ }
}
-
- ServiceReference<B> serviceReference;
- if (serviceName != null) {
- serviceReference =
componentContext.createSelfReference(businessInterface, serviceName);
- } else {
- serviceReference =
componentContext.createSelfReference(businessInterface);
- }
- return serviceReference;
}
Modified:
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java?rev=570929&r1=570928&r2=570929&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
(original)
+++
incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
Wed Aug 29 13:48:35 2007
@@ -239,4 +239,11 @@
return proxyFactory;
}
+ /**
+ * @return the registry
+ */
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return registry;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]