You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/05/13 08:50:44 UTC
svn commit: r406026 - in /incubator/tuscany/sandbox/jboynes/sca:
containers/container.java/src/main/java/org/apache/tuscany/container/java/context/
core2/src/main/java/org/apache/tuscany/core/context/
core2/src/main/java/org/apache/tuscany/core/system/...
Author: jmarino
Date: Fri May 12 23:50:42 2006
New Revision: 406026
URL: http://svn.apache.org/viewcvs?rev=406026&view=rev
Log:
more minor context refactors
Modified:
incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/AbstractCompositeContext.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java
incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemServiceContextImpl.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ComponentContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/Context.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ServiceContext.java
incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicContextExtension.java
Modified: incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/containers/container.java/src/main/java/org/apache/tuscany/container/java/context/JavaAtomicContext.java Fri May 12 23:50:42 2006
@@ -45,7 +45,7 @@
import org.apache.tuscany.container.java.invocation.ScopedJavaComponentInvoker;
/**
- * Manages Java component implementation instances
+ * Provides a runtime context for Java component implementations
*
* @version $Rev$ $Date$
*/
@@ -63,6 +63,19 @@
this.members = members != null ? members : new HashMap<String, Member>();
}
+ public Object getService(String name) throws TargetException {
+ // TODO implement proxying
+ return getTargetInstance();
+ }
+
+ public T getService() throws TargetException {
+ if (serviceInterfaces.size() == 1){
+ return getTargetInstance();
+ }else{
+ throw new TargetException("Context must contain exactly one service");
+ }
+ }
+
public InstanceWrapper createInstance() throws ObjectCreationException {
Object instance = objectFactory.getInstance();
// inject the instance with properties and references
@@ -74,17 +87,6 @@
return ctx;
}
- public void prepare() {
- }
-
- public Object getService(String name) throws TargetException {
- return getTargetInstance();
- }
-
- public T getService() throws TargetException {
- return getTargetInstance();
- }
-
public void addTargetWire(TargetWire wire) {
targetWires.put(wire.getServiceName(), wire);
}
@@ -122,6 +124,12 @@
return sourceWires;
}
+ public TargetInvoker createTargetInvoker(String serviceName, Method operation) {
+ return new ScopedJavaComponentInvoker(operation, this);
+ }
+
+ public void prepare() {
+ }
private Injector createInjector(Member member, SourceWire wire) {
ObjectFactory<?> factory = new ProxyObjectFactory(wire);
@@ -161,10 +169,5 @@
throw e;
}
}
-
- public TargetInvoker createTargetInvoker(String serviceName, Method operation) {
- return new ScopedJavaComponentInvoker(operation, this);
- }
-
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/AbstractCompositeContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/AbstractCompositeContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/AbstractCompositeContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/AbstractCompositeContext.java Fri May 12 23:50:42 2006
@@ -2,16 +2,14 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import java.lang.reflect.Member;
import org.apache.tuscany.core.system.context.SystemServiceContext;
-import org.apache.tuscany.core.injection.Injector;
import org.apache.tuscany.spi.CoreRuntimeException;
import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.context.AtomicContext;
@@ -243,7 +241,7 @@
List<Class<?>> serviceInterfaces = new ArrayList<Class<?>>(services.size());
synchronized (services) {
for (ServiceContext serviceContext : services) {
- serviceInterfaces.add(serviceContext.getInterface());
+ serviceInterfaces.add(serviceContext.getInterface());
}
}
return serviceInterfaces;
@@ -251,7 +249,7 @@
public void addTargetWire(TargetWire wire) {
- targetWires.put(wire.getServiceName(),wire);
+ targetWires.put(wire.getServiceName(), wire);
}
public TargetWire getTargetWire(String serviceName) {
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/context/ServiceContextImpl.java Fri May 12 23:50:42 2006
@@ -54,7 +54,7 @@
return proxy;
}
- public Object getHandler() {
+ public InvocationHandler getHandler() {
return invocationHandler;
}
Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemServiceContextImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemServiceContextImpl.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemServiceContextImpl.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/system/context/SystemServiceContextImpl.java Fri May 12 23:50:42 2006
@@ -1,6 +1,7 @@
package org.apache.tuscany.core.system.context;
import java.lang.reflect.Method;
+import java.lang.reflect.InvocationHandler;
import org.apache.tuscany.core.context.AbstractContext;
import org.apache.tuscany.spi.CoreRuntimeException;
@@ -30,10 +31,6 @@
setParent(parent);
}
- public TargetInvoker createTargetInvoker(String serviceName, Method operation) {
- return null; //TOD implement
- }
-
@SuppressWarnings("unchecked")
public T getService() {
if (cachedInstance == null) {
@@ -41,7 +38,7 @@
if ((ctx instanceof AtomicContext)) {
cachedInstance = (T) ((AtomicContext) ctx).getService(target.getPortName());
} else if ((ctx instanceof ReferenceContext)) {
- cachedInstance = (T) ((ReferenceContext) ctx).getService();
+ cachedInstance = (T) ctx.getService();
} else if (ctx == null){
TargetNotFoundException e = new TargetNotFoundException(name);
e.addContextName(getName());
@@ -57,12 +54,16 @@
}
- public Object getHandler() {
+ public InvocationHandler getHandler() {
return null;
}
public Class<T> getInterface() {
return interfaze;
+ }
+
+ public TargetInvoker createTargetInvoker(String serviceName, Method operation) {
+ return null; //TOD implement
}
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/AtomicContext.java Fri May 12 23:50:42 2006
@@ -57,7 +57,7 @@
/**
* Returns the target instance associated with the context. A target instance is the actual object a
- * request is dispatched to sans proxy wire chain.
+ * request is dispatched to sans wire chain.
*
* @throws TargetException
*/
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ComponentContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ComponentContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ComponentContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ComponentContext.java Fri May 12 23:50:42 2006
@@ -3,63 +3,60 @@
import java.util.List;
import java.util.Map;
-import org.apache.tuscany.spi.wire.TargetWire;
import org.apache.tuscany.spi.wire.SourceWire;
+import org.apache.tuscany.spi.wire.TargetWire;
/**
+ * Provides a runtime context for application artifacts configured as components
+ *
* @version $$Rev$$ $$Date$$
*/
public interface ComponentContext<T> extends Context<T> {
/**
- * Returns an instance associated with the given service name
+ * Returns a service associated with the given name
*
- * @throws TargetException if an error occurs retrieving the instance
+ * @throws TargetException if an error occurs retrieving the service instance
*/
Object getService(String name) throws TargetException;
-
+
/**
- * Returns the service interfaces implemented by the component the context represents
+ * Returns the service interfaces implemented by the context
*/
List<Class<?>>getServiceInterfaces();
/**
- * Adds a target-side wire factory for the given service name. Target-side wire factories contain the
- * invocation chains associated with the destination service of a wire and are responsible for generating
- * proxies
+ * Adds a target-side wire. Target-side wire factories contain the invocation chains associated with the
+ * destination service of a wire
*/
void addTargetWire(TargetWire wire);
/**
- * Returns the target-side wire factory associated with the given service name
+ * Returns the target-side wire associated with the given service name
*/
TargetWire getTargetWire(String serviceName);
/**
- * Returns a collection of target-side wire factories keyed by service name
+ * Returns a collection of target-side wires keyed by service name
*/
Map<String, TargetWire> getTargetWires();
/**
- * Adds a source-side wire factory for the given reference. Source-side wire factories contain the
- * invocation chains for a reference in the implementation associated with the instance context created by
- * this configuration. Source-side wire factories also produce proxies that are injected on a reference in
- * a component implementation.
+ * Adds a source-side wire for the given reference. Source-side wires contain the invocation chains for a
+ * reference in the implementation associated with the instance wrapper created by this configuration.
*/
void addSourceWire(SourceWire wire);
/**
- * Adds a set of source-side wire multiplicity factories for the given reference. Source-side wire
- * factories contain the invocation chains for a reference in the implementation associated with the
- * instance context created by this configuration. Source-side wire factories also produce proxies that
- * are injected on a reference in a component implementation.
+ * Adds a set of source-side multiplicity wires for the given reference. Source-side wires contain the
+ * invocation chains for a reference in the implementation associated with the instance wrapper created by
+ * this configuration.
*/
void addSourceWires(Class<?> multiplicityClass, List<SourceWire> wires);
/**
- * Returns a collection of source-side wire factories for references. There may 1..n wire factories per
- * reference.
+ * Returns a collection of source-side wires for references. There may 1..n wires per reference.
*/
List<SourceWire> getSourceWires();
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/Context.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/Context.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/Context.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/Context.java Fri May 12 23:50:42 2006
@@ -23,23 +23,23 @@
import org.apache.tuscany.spi.wire.TargetInvoker;
/**
- * An entity that provides an execution context for a runtime artifact or artifacts. A <code>Context</code>
- * may be a composite, managing child contexts or it may be an atomic, i.e. leaf, context.
+ * Provides an execution context for application artifacts derived from an assembly
*
* @version $Rev: 396520 $ $Date: 2006-04-24 12:38:07 +0100 (Mon, 24 Apr 2006) $
*/
public interface Context<T> extends EventPublisher, Lifecycle {
+
/**
- * Returns the name of the Context.
+ * Returns the name of the context.
*
- * @return the name of the Context
+ * @return the name of the context
*/
String getName();
/**
- * Sets the name of the Context.
+ * Sets the name of the context.
*
- * @param name the name of the Context
+ * @param name the name of the context
*/
void setName(String name);
@@ -54,18 +54,21 @@
void setParent(CompositeContext parent);
/**
- * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to this context
- * @param serviceName
- * @param operation the operation being invoked
- */
- TargetInvoker createTargetInvoker(String serviceName, Method operation);
-
- /**
* Returns an instance associated with the default service for the context
*
* @throws TargetException if an error occurs retrieving the instance
*/
T getService() throws TargetException;
+
+ /**
+ * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service
+ * contained by the context
+ *
+ * @param serviceName the name of the service
+ * @param operation the operation to invoke
+ */
+ TargetInvoker createTargetInvoker(String serviceName, Method operation);
+
}
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ReferenceContext.java Fri May 12 23:50:42 2006
@@ -3,7 +3,7 @@
import java.lang.reflect.InvocationHandler;
/**
- * Manages a bound reference
+ * Manages a reference configured for a binding
*
* @version $Rev: 399161 $ $Date: 2006-05-02 23:09:37 -0700 (Tue, 02 May 2006) $
*/
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ServiceContext.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ServiceContext.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ServiceContext.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/context/ServiceContext.java Fri May 12 23:50:42 2006
@@ -1,21 +1,14 @@
package org.apache.tuscany.spi.context;
+import java.lang.reflect.InvocationHandler;
+
/**
- * The runtime artifact representing an entry point, <code>ServiceContext</code> manages wire handler
- * instances that expose service operations offered by a component in the parent composite. The wire handler
- * instance is responsible for dispatching the request down an wire chain to the target instance. The wire
- * chain may contain {@link org.apache.tuscany.spi.wire.Interceptor}s and
- * {@link org.apache.tuscany.spi.wire.MessageHandler}s that implement policies or perform mediations on the
- * wire.
- * <p>
- * Service contexts are used by transport binding artifacts to invoke an operation on a service. The transport
- * binding uses an {@link java.lang.reflect.InvocationHandler} instance obtained from the <code>ServiceContext</code>
- * to perform the wire as in:
+ * Manages the context for a service configured for a binding. Bindings uses an {@link java.lang.reflect.InvocationHandler}
+ * to perform an invocation as in:
*
* <pre>
* CompositeContext compositeContext = ...
- * ServiceContext ctx = (ServiceContext) compositeContext.getContext("source");
- * Assert.assertNotNull(ctx);
+ * ServiceContext ctx = compositeContext.getServiceContext("source");
* InvocationHandler handler = (InvocationHandler) ctx.getHandler();
* Object response = handler.invoke(null, operation, new Object[] { param });
* </pre>
@@ -27,22 +20,21 @@
*
* <pre>
* CompositeContext compositeContext = ...
- * ServiceContext ctx = (ServiceContext) compositeContext.getContext("source");
- * Assert.assertNotNull(ctx);
- * HelloWorld proxy = (Helloworld) ctx.getInstance(null); // service name not necessary
+ * ServiceContext ctx = compositeContext.getServiceContext("source");
+ * HelloWorld proxy = (Helloworld) ctx.getInstance();
* </pre>
*
- * The proxy returned will be backed by the entry point wire chain.
+ * The proxy returned will be backed by the econtext wire chain.
*
* @version $Rev: 399161 $ $Date: 2006-05-02 23:09:37 -0700 (Tue, 02 May 2006) $
*/
public interface ServiceContext<T> extends Context<T> {
/**
- * Returns the handler responsible for flowing a request through the entry point
+ * Returns the handler responsible for flowing a request through the service context
* @throws org.apache.tuscany.spi.context.TargetException
*/
- public Object getHandler() throws TargetException;
+ public InvocationHandler getHandler() throws TargetException;
/**
* Returns the service interface configured for the service
Modified: incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicContextExtension.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicContextExtension.java?rev=406026&r1=406025&r2=406026&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicContextExtension.java (original)
+++ incubator/tuscany/sandbox/jboynes/sca/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicContextExtension.java Fri May 12 23:50:42 2006
@@ -1,5 +1,7 @@
package org.apache.tuscany.spi.extension;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -24,6 +26,8 @@
protected String name;
protected CompositeContext parent;
protected int lifecycleState = UNINITIALIZED;
+ protected Map<String, TargetWire> targetWires = new HashMap<String, TargetWire>();
+ protected List<SourceWire> sourceWires = new ArrayList<SourceWire>();
public List getServiceInterfaces() {
return null;
@@ -37,30 +41,6 @@
}
}
- public void addTargetWire(TargetWire wire) {
-
- }
-
- public TargetWire getTargetWire(String serviceName) {
- return null;
- }
-
- public Map getTargetWires() {
- return null;
- }
-
- public void addSourceWire(SourceWire wire) {
-
- }
-
- public List getSourceWires() {
- return null;
- }
-
- public void addSourceWires(Class multiplicityClass, List wires) {
-
- }
-
public void setScopeContext(ScopeContext context) {
scopeContext = context;
}
@@ -74,7 +54,7 @@
}
public void setName(String name) {
- this.name = name;
+ this.name = name;
}
public CompositeContext getParent() {
@@ -82,7 +62,7 @@
}
public void setParent(CompositeContext parent) {
- this.parent = parent;
+ this.parent = parent;
}
public void publish(Event object) {
@@ -106,10 +86,40 @@
}
public void start() throws CoreRuntimeException {
- lifecycleState = RUNNING;
+ lifecycleState = RUNNING;
}
public void stop() throws CoreRuntimeException {
- lifecycleState = STOPPED;
+ lifecycleState = STOPPED;
}
+
+ public void addTargetWire(TargetWire wire) {
+ targetWires.put(wire.getServiceName(), wire);
+ }
+
+ public TargetWire getTargetWire(String serviceName) {
+ return targetWires.get(serviceName);
+ }
+
+ public Map<String, TargetWire> getTargetWires() {
+ return targetWires;
+ }
+
+ public void addSourceWire(SourceWire wire) {
+ sourceWires.add(wire);
+ }
+
+ public List<SourceWire> getSourceWires() {
+ return sourceWires;
+ }
+
+ public void prepare() {
+
+ }
+
+ public void addSourceWires(Class multiplicityClass, List wires) {
+ // TODO implement
+ }
+
+
}