You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/04/10 02:38:36 UTC

svn commit: r526976 - in /incubator/tuscany/java/sca/modules/implementation-java-runtime/src: main/java/org/apache/tuscany/core/component/ main/java/org/apache/tuscany/core/implementation/ main/java/org/apache/tuscany/core/implementation/java/ test/jav...

Author: rfeng
Date: Mon Apr  9 17:38:35 2007
New Revision: 526976

URL: http://svn.apache.org/viewvc?view=rev&rev=526976
Log:
[work-in-progress] More code porting for implementation-java-runtime. Some test cases cannot be compiled.

Added:
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java   (with props)
Removed:
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProvider.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProviderTestCase.java
Modified:
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java
    incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java Mon Apr  9 17:38:35 2007
@@ -35,18 +35,10 @@
     /**
      * Sets an object factory for an injection site
      *
-     * @param name          the injection site name
+     * @param element          the injection site name
      * @param objectFactory the object factory
      */
-    void setObjectFactory(JavaElement name, ObjectFactory<?> objectFactory);
-
-    /**
-     * Returns the type for the injection site
-     *
-     * @param injectionSite the injection site name
-     * @return the required type
-     */
-    Class<?> getMemberType(JavaElement injectionSite);
+    void setObjectFactory(JavaElement element, ObjectFactory<?> objectFactory);
 
     /**
      * Create an instance factory that can be used to create component instances.

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java Mon Apr  9 17:38:35 2007
@@ -19,6 +19,7 @@
 package org.apache.tuscany.core.implementation;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Member;
@@ -49,7 +50,9 @@
 import org.apache.tuscany.core.injection.ObjectCallbackException;
 import org.apache.tuscany.core.injection.PojoObjectFactory;
 import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
 import org.apache.tuscany.implementation.java.impl.Parameter;
+import org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper;
 import org.apache.tuscany.interfacedef.java.JavaInterface;
 import org.apache.tuscany.spi.CoreRuntimeException;
 import org.apache.tuscany.spi.ObjectCreationException;
@@ -63,6 +66,7 @@
 import org.osoa.sca.CallableReference;
 import org.osoa.sca.ComponentContext;
 import org.osoa.sca.ServiceReference;
+import org.osoa.sca.annotations.ConversationID;
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
 
@@ -75,51 +79,25 @@
  *          2007) $$
  */
 public abstract class PojoAtomicComponent extends AtomicComponentExtension implements ComponentContextProvider {
-    protected EventInvoker<Object> initInvoker;
-    protected EventInvoker<Object> destroyInvoker;
-    protected PojoObjectFactory<?> instanceFactory;
-    protected InstanceFactory<?> instanceFactory2;
-    protected ConstructorDefinition<?> constructor;
-    // protected List<String> constructorParamNames;
-    protected Map<String, Member> referenceSites;
-    protected Map<String, Member> resourceSites;
-    protected Map<String, Member> propertySites;
-    protected Map<String, Member> callbackSites;
-    protected List<Injector<Object>> injectors;
-    protected Class implementationClass;
     protected Map<String, List<Wire>> wires = new HashMap<String, List<Wire>>();
     protected Map<String, List<Wire>> callBackwires = new HashMap<String, List<Wire>>();
 
+    protected PojoConfiguration<?> configuration;
+
     private final ComponentContext componentContext;
-    private final Map<String, ObjectFactory<?>> propertyFactories = new ConcurrentHashMap<String, ObjectFactory<?>>();
 
     public PojoAtomicComponent(PojoConfiguration configuration) {
         super(configuration.getName(), configuration.getProxyService(), configuration.getWorkContext(), configuration
-            .getGroupId(), configuration.getInitLevel(), configuration.getMaxIdleTime(), configuration.getMaxAge());
-        assert configuration.getInstanceFactory() != null : "Object factory was null";
-        initInvoker = configuration.getInitInvoker();
-        destroyInvoker = configuration.getDestroyInvoker();
-        instanceFactory = configuration.getInstanceFactory();
-        instanceFactory2 = configuration.getInstanceFactory2();
-        constructor = configuration.getConstructor();
-        injectors = new ArrayList<Injector<Object>>();
-        referenceSites = configuration.getReferenceSite() != null ? configuration.getReferenceSite()
-                                                                 : new HashMap<String, Member>();
-        propertySites = configuration.getPropertySites() != null ? configuration.getPropertySites()
-                                                                : new HashMap<String, Member>();
-        resourceSites = configuration.getResourceSites() != null ? configuration.getResourceSites()
-                                                                : new HashMap<String, Member>();
-        callbackSites = configuration.getCallbackSites() != null ? configuration.getCallbackSites()
-                                                                : new HashMap<String, Member>();
-        implementationClass = configuration.getImplementationClass();
-
+            .getGroupId(), 50, configuration.getDefinition().getMaxIdleTime(), configuration.getDefinition()
+            .getMaxAge());
+        this.configuration = configuration;
         componentContext = new ComponentContextImpl(this);
     }
 
     public void destroy(Object instance) throws TargetDestructionException {
-        if (destroyInvoker != null) {
+        if (configuration.getDestroyInvoker() != null) {
             try {
-                destroyInvoker.invokeEvent(instance);
+                configuration.getDestroyInvoker().invokeEvent(instance);
             } catch (ObjectCallbackException e) {
                 throw new TargetDestructionException("Error destroying component instance", getUri().toString(), e);
             }
@@ -130,7 +108,7 @@
         // stateless implementations that require a destroy callback cannot be
         // optimized since the callback is
         // performed by the JavaTargetInvoker
-        return !(getScope() == Scope.STATELESS && destroyInvoker != null);
+        return !(getScope() == Scope.STATELESS && configuration.getDestroyInvoker() != null);
     }
 
     public Object getTargetInstance() throws TargetResolutionException {
@@ -141,21 +119,8 @@
         return wrapper.getInstance();
     }
 
-    public Object createInstance() throws ObjectCreationException {
-        Object instance = instanceFactory.getInstance();
-        // inject the instance with properties and references
-        for (Injector<Object> injector : injectors) {
-            injector.inject(instance);
-        }
-        return instance;
-    }
-
     public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
-        /*
-         * FIXME make this work return instanceFactory2.newInstance();
-         */
-        Object instance = createInstance();
-        return new ReflectiveInstanceWrapper<Object>(instance, initInvoker, destroyInvoker);
+        return configuration.createFactory().newInstance();
     }
 
     public List<Wire> getWires(String name) {
@@ -171,32 +136,18 @@
             wires.put(referenceName, wireList);
         }
         wireList.add(wire);
-        Member member = referenceSites.get(referenceName);
-        if (member != null && !(member instanceof Constructor)) {
-            injectors.add(createInjector(member, wire));
-        }
 
-        configureConstructor(referenceName, Reference.class, wire);
+        JavaElement element = configuration.getDefinition().getReferenceMembers().get(referenceName);
+        if (element != null && !(element.getAnchor() instanceof Constructor)) {
+            configuration.getInjectionSites().add(element);
+        }
 
-        // TODO error if ref not set on constructor or ref site
+        configuration.setObjectFactory(element, createWireFactory(element.getType(), wire));
 
     }
 
-    private boolean configureConstructor(String name, Class<? extends Annotation> classifer, Wire wire) {
-        Parameter param = getParameter(name, classifer);
-        if (param != null) {
-            ObjectFactory[] initializerFactories = instanceFactory.getInitializerFactories();
-            initializerFactories[param.getIndex()] = createWireFactory(param.getType(), wire);
-            return true;
-        }
-        return false;
-    }
-
     private Parameter getParameter(String name, Class<? extends Annotation> classifer) {
-        if (constructor == null) {
-            return null;
-        }
-        for (Parameter param : constructor.getParameters()) {
+        for (Parameter param : configuration.getDefinition().getConstructorDefinition().getParameters()) {
             if (param.getClassifer() == classifer && param.getName().equals(name)) {
                 return param;
             }
@@ -204,16 +155,6 @@
         return null;
     }
 
-    private boolean configureConstructor(String name, Class<? extends Annotation> classifer, ObjectFactory<?> factory) {
-        Parameter param = getParameter(name, classifer);
-        if (param != null) {
-            ObjectFactory[] initializerFactories = instanceFactory.getInitializerFactories();
-            initializerFactories[param.getIndex()] = factory;
-            return true;
-        }
-        return false;
-    }
-
     public void attachWires(List<Wire> attachWires) {
         assert attachWires.size() > 0;
         assert attachWires.get(0).getSourceUri().getFragment() != null;
@@ -224,21 +165,19 @@
             wires.put(referenceName, wireList);
         }
         wireList.addAll(attachWires);
-        Member member = referenceSites.get(referenceName);
-        if (member == null) {
-            if (getParameter(referenceName, Reference.class) != null) {
-                // injected on the constructor
-                throw new UnsupportedOperationException();
-            } else {
-                throw new NoAccessorException(referenceName);
-            }
-        }
+        JavaElement element = configuration.getDefinition().getReferenceMembers().get(referenceName);
 
-        Class<?> type = ((JavaInterface) attachWires.get(0).getSourceContract().getInterface()).getJavaClass();
+        Class<?> type = ((JavaInterface)attachWires.get(0).getSourceContract().getInterface()).getJavaClass();
         if (type == null) {
             throw new NoMultiplicityTypeException("Java interface must be specified for multiplicity", referenceName);
         }
-        injectors.add(createMultiplicityInjector(member, type, wireList));
+
+        List<ObjectFactory<?>> factories = new ArrayList<ObjectFactory<?>>();
+        for (Wire wire : wireList) {
+            factories.add(createWireFactory(element.getType(), wire));
+        }
+        configuration.getInjectionSites().add(element);
+        configuration.setObjectFactories(element, factories);
 
     }
 
@@ -246,7 +185,7 @@
         assert wire.getSourceUri().getFragment() != null;
         // FIXME: [rfeng] This is a hack to get it compiled
         String callbackName = wire.getSourceContract().getCallbackInterface().toString();
-        assert callbackSites.get(callbackName) != null;
+        assert configuration.getDefinition().getCallbackMembers().get(callbackName) != null;
         List<Wire> wireList = callBackwires.get(callbackName);
         if (wireList == null) {
             wireList = new ArrayList<Wire>();
@@ -256,27 +195,18 @@
     }
 
     public void start() throws CoreRuntimeException {
-        if (!callbackSites.isEmpty()) {
-            for (Map.Entry<String, Member> entry : callbackSites.entrySet()) {
+        if (!configuration.getDefinition().getCallbackMembers().isEmpty()) {
+            for (Map.Entry<String, JavaElement> entry : configuration.getDefinition().getCallbackMembers().entrySet()) {
                 List<Wire> wires = callBackwires.get(entry.getKey());
                 if (wires == null) {
                     // this can happen when there are no client wires to a
                     // component that has a callback
                     continue;
                 }
-                Member member = entry.getValue();
-                if (member instanceof Field) {
-                    Field field = (Field)member;
-                    ObjectFactory<?> factory = new CallbackWireObjectFactory(field.getType(), proxyService, wires);
-                    injectors.add(new FieldInjector<Object>(field, factory));
-                } else if (member instanceof Method) {
-                    Method method = (Method)member;
-                    Class<?> type = method.getParameterTypes()[0];
-                    ObjectFactory<?> factory = new CallbackWireObjectFactory(type, proxyService, wires);
-                    injectors.add(new MethodInjector<Object>(method, factory));
-                } else {
-                    throw new InvalidAccessorException("Member must be a field or method", member.getName());
-                }
+                JavaElement element = entry.getValue();
+                ObjectFactory<?> factory = new CallbackWireObjectFactory(element.getType(), proxyService, wires);
+                configuration.getInjectionSites().add(element);
+                configuration.setObjectFactory(element, factory);
             }
         }
         super.start();
@@ -284,45 +214,45 @@
     }
 
     public void addPropertyFactory(String name, ObjectFactory<?> factory) {
-        Member member = propertySites.get(name);
-        if (member instanceof Field) {
-            injectors.add(new FieldInjector<Object>((Field)member, factory));
-        } else if (member instanceof Method) {
-            injectors.add(new MethodInjector<Object>((Method)member, factory));
-        }
+        JavaElement element = configuration.getDefinition().getPropertyMembers().get(name);
 
-        configureConstructor(name, Property.class, factory);
-
-        // FIXME throw an error if no injection site found
+        if (element != null && !(element.getAnchor() instanceof Constructor)) {
+            configuration.getInjectionSites().add(element);
+        }
 
-        propertyFactories.put(name, factory);
+        configuration.setObjectFactory(element, factory);
     }
 
     public void addResourceFactory(String name, ObjectFactory<?> factory) {
-        Member member = resourceSites.get(name);
-        if (member instanceof Field) {
-            injectors.add(new FieldInjector<Object>((Field)member, factory));
-        } else if (member instanceof Method) {
-            injectors.add(new MethodInjector<Object>((Method)member, factory));
+        org.apache.tuscany.implementation.java.impl.Resource<?> resource = configuration.getDefinition().getResources()
+            .get(name);
+
+        if (resource != null && !(resource.getElement().getAnchor() instanceof Constructor)) {
+            configuration.getInjectionSites().add(resource.getElement());
         }
 
-        configureConstructor(name, Resource.class, factory);
-        // FIXME throw an error if no injection site found
+        configuration.setObjectFactory(resource.getElement(), factory);
     }
 
     public void addConversationIDFactory(Member member) {
-        ObjectFactory<String> convIDObjectFactory = new ConversationIDObjectFactory(workContext);
+        ObjectFactory<String> factory = new ConversationIDObjectFactory(workContext);
+
         if (member instanceof Field) {
-            injectors.add(new FieldInjector<Object>((Field)member, convIDObjectFactory));
+            JavaElement element = new JavaElement((Field)member);
+            element.setClassifer(ConversationID.class);
+            configuration.setObjectFactory(element, factory);
         } else if (member instanceof Method) {
-            injectors.add(new MethodInjector<Object>((Method)member, convIDObjectFactory));
+            JavaElement element = new JavaElement((Method)member, 0);
+            element.setName(JavaIntrospectionHelper.toPropertyName(member.getName()));
+            element.setClassifer(ConversationID.class);
+            configuration.setObjectFactory(element, factory);
         } else {
             throw new InvalidAccessorException("Member must be a field or method", member.getName());
         }
     }
 
     public boolean implementsCallback(Class callbackClass) {
-        Class<?>[] implementedInterfaces = implementationClass.getInterfaces();
+        Class<?>[] implementedInterfaces = configuration.getDefinition().getJavaClass().getInterfaces();
         for (Class<?> implementedInterface : implementedInterfaces) {
             if (implementedInterface.isAssignableFrom(callbackClass)) {
                 return true;
@@ -379,12 +309,27 @@
     }
 
     public <B> B getProperty(Class<B> type, String propertyName) {
-        ObjectFactory<?> factory = propertyFactories.get(propertyName);
-        if (factory != null) {
-            return type.cast(factory.getInstance());
-        } else {
-            return null;
+        JavaElement element = configuration.getDefinition().getPropertyMembers().get(propertyName);
+        Object obj = configuration.getFactories().get(element);
+        if (obj instanceof ObjectFactory) {
+            return type.cast(((ObjectFactory<?>)obj).getInstance());
+        } else if (obj instanceof List) {
+            List<ObjectFactory<?>> factories = (List<ObjectFactory<?>>)obj;
+            if (type.isArray()) {
+                Object array = Array.newInstance(type, factories.size());
+                for (int i = 0; i < factories.size(); i++) {
+                    Array.set(array, i, factories.get(i).getInstance());
+                }
+                return type.cast(array);
+            } else {
+                List<Object> list = new ArrayList<Object>();
+                for (ObjectFactory factory : factories) {
+                    list.add(factory.getInstance());
+                }
+                return type.cast(list);
+            }
         }
+        return null;
 
     }
 
@@ -417,5 +362,12 @@
     }
 
     protected abstract <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire);
+
+    /**
+     * @see org.apache.tuscany.spi.component.AtomicComponent#createInstance()
+     */
+    public Object createInstance() throws ObjectCreationException {
+        return createInstanceWrapper().getInstance();
+    }
 
 }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java Mon Apr  9 17:38:35 2007
@@ -149,7 +149,7 @@
     }
 
     public Class<?> getMemberType(JavaElement injectionSite) {
-        return provider.getMemberType(injectionSite);
+        return injectionSite.getType();
     }
 
     @Deprecated

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java Mon Apr  9 17:38:35 2007
@@ -18,7 +18,10 @@
  */
 package org.apache.tuscany.core.implementation;
 
-import java.lang.reflect.Member;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -26,89 +29,57 @@
 import java.util.Map;
 
 import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.ReflectiveInstanceFactory;
+import org.apache.tuscany.core.injection.ArrayMultiplicityObjectFactory;
 import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.FieldInjector;
 import org.apache.tuscany.core.injection.Injector;
-import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.InvalidAccessorException;
+import org.apache.tuscany.core.injection.ListMultiplicityObjectFactory;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.MethodInjector;
 import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.processor.JavaIntrospectionHelper;
+import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.wire.ProxyService;
 
 /**
  * Encapsulates confuration for a Java-based atomic component
- *
+ * 
  * @version $Rev$ $Date$
  */
-public class PojoConfiguration {
-    private URI name;
-    private InstanceFactory<?> instanceFactory2;
-    private PojoObjectFactory<?> instanceFactory;
-    private ConstructorDefinition<?> constructor;
-    private int initLevel;
-    private EventInvoker<Object> initInvoker;
-    private EventInvoker<Object> destroyInvoker;
-    private List<Injector> propertyInjectors = new ArrayList<Injector>();
-    private Map<String, Member> referenceSites = new HashMap<String, Member>();
-    private Map<String, Member> propertySites = new HashMap<String, Member>();
-    private Map<String, Member> resourceSites = new HashMap<String, Member>();
-    private Map<String, Member> callbackSites = new HashMap<String, Member>();
+public class PojoConfiguration<T> implements InstanceFactoryProvider<T> {
+    private JavaImplementationDefinition definition;
     private ProxyService proxyService;
     private WorkContext workContext;
-    private long maxIdleTime = -1;
-    private long maxAge = -1;
-    private Class implementationClass;
     private URI groupId;
+    private URI name;
 
-    public URI getName() {
-        return name;
+    private final List<JavaElement> injectionSites;
+    private final EventInvoker<T> initInvoker;
+    private final EventInvoker<T> destroyInvoker;
+    private final Map<JavaElement, Object> factories = new HashMap<JavaElement, Object>();
+
+    public PojoConfiguration(JavaImplementationDefinition definition) {
+        this.definition = definition;
+        this.initInvoker = definition.getInitMethod() == null ? null : new MethodEventInvoker<T>(definition
+            .getInitMethod());
+        this.destroyInvoker = definition.getDestroyMethod() == null ? null : new MethodEventInvoker<T>(definition
+            .getDestroyMethod());
+        injectionSites = new ArrayList<JavaElement>();
     }
-
+    
     public void setName(URI name) {
         this.name = name;
     }
 
-    @Deprecated
-    public PojoObjectFactory<?> getInstanceFactory() {
-        return instanceFactory;
-    }
-
-    @Deprecated
-    public void setInstanceFactory(PojoObjectFactory<?> objectFactory) {
-        this.instanceFactory = objectFactory;
-    }
-
-    public InstanceFactory<?> getInstanceFactory2() {
-        return instanceFactory2;
-    }
-
-    public void setInstanceFactory2(InstanceFactory<?> instanceFactory2) {
-        this.instanceFactory2 = instanceFactory2;
-    }
-
-    /*
-    public List<String> getConstructorParamNames() {
-        return constructorParamNames;
-    }
-
-    public void setConstructorParamNames(List<String> names) {
-        constructorParamNames = names;
-    }
-
-    public void addConstructorParamName(String name) {
-        constructorParamNames.add(name);
-    }
-
-    public List<Class<?>> getConstructorParamTypes() {
-        return constructorParamTypes;
-    }
-
-    public void setConstructorParamTypes(List<Class<?>> constructorParamTypes) {
-        this.constructorParamTypes = constructorParamTypes;
-    }
-
-    public void addConstructorParamType(Class<?> type) {
-        constructorParamTypes.add(type);
+    public URI getName() {
+        return name;
     }
-    */
 
     public URI getGroupId() {
         return groupId;
@@ -118,84 +89,12 @@
         this.groupId = groupId;
     }
 
-    public int getInitLevel() {
-        return initLevel;
-    }
-
-    public void setInitLevel(int initLevel) {
-        this.initLevel = initLevel;
-    }
-
-    public long getMaxIdleTime() {
-        return maxIdleTime;
-    }
-
-    public void setMaxIdleTime(long maxIdleTime) {
-        this.maxIdleTime = maxIdleTime;
-    }
-
-    public long getMaxAge() {
-        return maxAge;
-    }
-
-    public void setMaxAge(long maxAge) {
-        this.maxAge = maxAge;
-    }
-
     public EventInvoker<Object> getInitInvoker() {
-        return initInvoker;
-    }
-
-    public void setInitInvoker(EventInvoker<Object> initInvoker) {
-        this.initInvoker = initInvoker;
+        return new MethodEventInvoker<Object>(definition.getInitMethod());
     }
 
     public EventInvoker<Object> getDestroyInvoker() {
-        return destroyInvoker;
-    }
-
-    public void setDestroyInvoker(EventInvoker<Object> destroyInvoker) {
-        this.destroyInvoker = destroyInvoker;
-    }
-
-    public List<Injector> getPropertyInjectors() {
-        return propertyInjectors;
-    }
-
-    public void addPropertyInjector(Injector injector) {
-        propertyInjectors.add(injector);
-    }
-
-    public Map<String, Member> getReferenceSite() {
-        return referenceSites;
-    }
-
-    public void addReferenceSite(String name, Member member) {
-        referenceSites.put(name, member);
-    }
-
-    public Map<String, Member> getResourceSites() {
-        return resourceSites;
-    }
-
-    public void addResourceSite(String name, Member member) {
-        resourceSites.put(name, member);
-    }
-
-    public Map<String, Member> getCallbackSites() {
-        return callbackSites;
-    }
-
-    public void addCallbackSite(String name, Member member) {
-        callbackSites.put(name, member);
-    }
-
-    public Map<String, Member> getPropertySites() {
-        return propertySites;
-    }
-
-    public void addPropertySite(String name, Member member) {
-        propertySites.put(name, member);
+        return new MethodEventInvoker<Object>(definition.getDestroyMethod());
     }
 
     public ProxyService getProxyService() {
@@ -214,25 +113,110 @@
         this.workContext = workContext;
     }
 
-    public Class getImplementationClass() {
-        return implementationClass;
+    /**
+     * @return the constructor
+     */
+    public ConstructorDefinition<?> getConstructor() {
+        return definition.getConstructorDefinition();
     }
 
-    public void setImplementationClass(Class implementationClass) {
-        this.implementationClass = implementationClass;
+    /**
+     * @return the definition
+     */
+    public JavaImplementationDefinition getDefinition() {
+        return definition;
+    }
+
+    @SuppressWarnings("unchecked")
+    public InstanceFactory<T> createFactory() {
+        ObjectFactory<?>[] initArgs = getConstructorArgs();
+        Injector<T>[] injectors = getInjectors();
+        return new ReflectiveInstanceFactory<T>((Constructor<T>)definition.getConstructorDefinition().getConstructor(),
+                                                initArgs, injectors, initInvoker, destroyInvoker);
+    }
+
+    protected ObjectFactory<?>[] getConstructorArgs() {
+        ConstructorDefinition<?> constructor = definition.getConstructorDefinition();
+        ObjectFactory<?>[] initArgs = new ObjectFactory<?>[constructor.getParameters().length];
+        for (int i = 0; i < initArgs.length; i++) {
+            ObjectFactory<?> factory = (ObjectFactory<?>)factories.get(constructor.getParameters()[i]);
+            assert factory != null;
+            initArgs[i] = factory;
+        }
+        return initArgs;
+    }
+
+    protected Injector<T>[] getInjectors() {
+        // work around JDK1.5 issue with allocating generic arrays
+        @SuppressWarnings("unchecked")
+        Injector<T>[] injectors = (Injector<T>[])new Injector[injectionSites.size()];
+
+        int i = 0;
+        for (JavaElement element : injectionSites) {
+            Object obj = factories.get(element);
+            if (obj instanceof ObjectFactory) {
+                ObjectFactory<?> factory = (ObjectFactory<?>)obj;
+                if (element.getElementType() == ElementType.FIELD) {
+                    injectors[i++] = new FieldInjector<T>((Field)element.getAnchor(), factory);
+                } else if (element.getElementType() == ElementType.PARAMETER && element.getAnchor() instanceof Method) {
+                    injectors[i++] = new MethodInjector<T>((Method)element.getAnchor(), factory);
+                } else {
+                    throw new AssertionError(String.valueOf(element));
+                }
+            } else {
+                injectors[i++] = createMultiplicityInjector(element, (List<ObjectFactory<?>>)factories);
+            }
+        }
+        return injectors;
+    }
+
+    protected Injector<T> createMultiplicityInjector(JavaElement element, List<ObjectFactory<?>> factories) {
+        Class<?> interfaceType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+
+        if (element.getAnchor() instanceof Field) {
+            Field field = (Field)element.getAnchor();
+            if (field.getType().isArray()) {
+                return new FieldInjector<T>(field, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+            } else {
+                return new FieldInjector<T>(field, new ListMultiplicityObjectFactory(factories));
+            }
+        } else if (element.getAnchor() instanceof Method) {
+            Method method = (Method)element.getAnchor();
+            if (method.getParameterTypes()[0].isArray()) {
+                return new MethodInjector<T>(method, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+            } else {
+                return new MethodInjector<T>(method, new ListMultiplicityObjectFactory(factories));
+            }
+        } else {
+            throw new InvalidAccessorException("Member must be a field or method", element.getName());
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public Class<T> getImplementationClass() {
+        return (Class<T>)definition.getJavaClass();
+    }
+
+    public void setObjectFactory(JavaElement element, ObjectFactory<?> objectFactory) {
+        factories.put(element, objectFactory);
+    }
+
+    public void setObjectFactories(JavaElement element, List<ObjectFactory<?>> objectFactory) {
+        factories.put(element, objectFactory);
     }
 
     /**
-     * @return the constructor
+     * @return the injectionSites
      */
-    public ConstructorDefinition<?> getConstructor() {
-        return constructor;
+    public List<JavaElement> getInjectionSites() {
+        return injectionSites;
     }
 
     /**
-     * @param constructor the constructor to set
+     * @return the factories
      */
-    public void setConstructor(ConstructorDefinition<?> constructor) {
-        this.constructor = constructor;
+    public Map<JavaElement, Object> getFactories() {
+        return factories;
     }
+
 }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java Mon Apr  9 17:38:35 2007
@@ -49,7 +49,7 @@
         if (isCallback) {
             implClass = ((JavaInterface) operation.getInterface()).getJavaClass();
         } else {
-            implClass = implementationClass;
+            implClass = configuration.getImplementationClass();
         }
         try {
             Method method = JavaIDLUtils.findMethod(implClass, operation);

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java Mon Apr  9 17:38:35 2007
@@ -66,67 +66,15 @@
         JavaImplementationDefinition componentType = (JavaImplementationDefinition)
             definition.getImplementation();
 
-        PojoConfiguration configuration = new PojoConfiguration();
-        if (componentType.getMaxAge() > 0) {
-            configuration.setMaxAge(componentType.getMaxAge());
-        } else if (componentType.getMaxIdleTime() > 0) {
-            configuration.setMaxIdleTime(componentType.getMaxIdleTime());
-        }
-        Method initMethod = componentType.getInitMethod();
-        if (initMethod != null) {
-            configuration.setInitInvoker(new MethodEventInvoker(initMethod));
-        }
-        Method destroyMethod = componentType.getDestroyMethod();
-        if (destroyMethod != null) {
-            configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
-        }
+        PojoConfiguration configuration = new PojoConfiguration(componentType);
 
+        configuration.setName(URI.create(definition.getName()));
         configuration.setGroupId(context.getGroupId());
         configuration.setProxyService(proxyService);
         configuration.setWorkContext(workContext);
-        configuration.setImplementationClass(((JavaImplementation) definition.getImplementation()).getJavaClass());
-
-        // setup property injection sites
-        for (JavaElement property : componentType.getPropertyMembers().values()) {
-            configuration.addPropertySite(property.getName(), (Member) property.getAnchor());
-        }
-
-        // setup reference injection sites
-        for (JavaElement reference : componentType.getReferenceMembers().values()) {
-            Member member = (Member) reference.getAnchor();
-            if (member != null) {
-                // could be null if the reference is mapped to a constructor
-                configuration.addReferenceSite(reference.getName(), member);
-            }
-        }
-
-        for (Resource resource : componentType.getResources().values()) {
-            Member member = resource.getMember();
-            if (member != null) {
-                // could be null if the resource is mapped to a constructor
-                configuration.addResourceSite(resource.getName(), member);
-            }
-        }
-
-        // setup constructor injection
-        ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
-        Constructor<?> constr = ctorDef.getConstructor();
-        PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
-        configuration.setInstanceFactory(instanceFactory);
-        configuration.setConstructor(ctorDef);
-
-        // FIXME: [rfeng] Hack
-        configuration.setName(URI.create(definition.getName()));
-        handleCallbackSites(componentType, configuration);
 
         JavaAtomicComponent component = new JavaAtomicComponent(configuration);
 
-        // handle properties
-        handleProperties(definition, component);
-
-        // handle resources
-        handleResources(componentType, component);
-
         if (componentType.getConversationIDMember() != null) {
             component.addConversationIDFactory(componentType.getConversationIDMember());
         }
@@ -134,19 +82,6 @@
         return component;
     }
 
-    private void handleCallbackSites(
-        JavaImplementationDefinition componentType,
-        PojoConfiguration configuration) {
-        for (Service service : componentType.getServices()) {
-            // setup callback injection sites
-            JavaElement element = componentType.getCallbackMembers().get(service.getName());
-            if (element != null) {
-                // Only if there is a callback reference in the service
-                configuration.addCallbackSite(service.getName(), (Member) element.getAnchor());
-            }
-        }
-    }
-
     private void handleResources(
         JavaImplementationDefinition componentType,
         JavaAtomicComponent component) {
@@ -154,7 +89,7 @@
             String name = resource.getName();
             ObjectFactory<?> objectFactory = null;
             if (objectFactory == null) {
-                Class<?> type = resource.getType();
+                Class<?> type = resource.getElement().getType();
                 if (ComponentContext.class.equals(type)) {
                     objectFactory = new PojoComponentContextFactory(component);
                 } else {
@@ -172,18 +107,6 @@
                                                                      boolean optional,
                                                                      ResourceHost host) {
         return new ResourceObjectFactory<T>(type, mappedName, optional, host);
-    }
-
-    private void handleProperties(Component definition, JavaAtomicComponent component) {
-        throw new UnsupportedOperationException("Not implemented");
-        /*
-        for (ComponentProperty property : definition.getProperties()) {
-            ObjectFactory<?> factory = property.getValueFactory();
-            if (factory != null) {
-                component.addPropertyFactory(property.getName(), factory);
-            }
-        }
-        */
     }
 
     protected Class<JavaImplementation> getImplementationType() {

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java Mon Apr  9 17:38:35 2007
@@ -24,6 +24,8 @@
 
 import org.apache.tuscany.core.injection.EventInvoker;
 import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
+import org.apache.tuscany.implementation.java.introspection.impl.IntrospectionRegistryImpl;
 import org.apache.tuscany.interfacedef.Operation;
 import org.apache.tuscany.spi.ObjectFactory;
 import org.apache.tuscany.spi.Scope;
@@ -114,11 +116,13 @@
 
     protected void setUp() throws Exception {
         super.setUp();
+        
+        JavaImplementationDefinition definition = new JavaImplementationDefinition();
+        definition.setName("foo");
+        
         PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor());
 
-        config = new PojoConfiguration();
-        config.setInstanceFactory(factory);
-        config.setName(URI.create("foo"));
+        config = new PojoConfiguration(definition);
         groupId = URI.create("parent");
         config.setGroupId(groupId);
     }

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java Mon Apr  9 17:38:35 2007
@@ -64,8 +64,8 @@
         type.setConstructorDefinition(ctorDef);
         type.setJavaClass(Foo.class);
 
-        URI uri = URI.create("foo");
         Component definition = new DefaultAssemblyFactory().createComponent();
+        definition.setName("foo");
         definition.setImplementation(type);
         JavaAtomicComponent component = (JavaAtomicComponent)builder.build(definition, ctx);
         Foo foo = (Foo)component.createInstance();

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java Mon Apr  9 17:38:35 2007
@@ -25,6 +25,7 @@
 import org.apache.tuscany.assembly.Component;
 import org.apache.tuscany.assembly.impl.DefaultAssemblyFactory;
 import org.apache.tuscany.implementation.java.impl.ConstructorDefinition;
+import org.apache.tuscany.implementation.java.impl.JavaElement;
 import org.apache.tuscany.implementation.java.impl.JavaImplementationDefinition;
 import org.apache.tuscany.implementation.java.impl.Resource;
 import org.apache.tuscany.spi.Scope;
@@ -57,7 +58,7 @@
         builder.setScopeRegistry(registry);
         ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
         JavaImplementationDefinition type = new JavaImplementationDefinition();
-        Resource resource = new Resource("resource", String.class, Foo.class.getDeclaredField("resource"));
+        Resource resource = new Resource(new JavaElement(Foo.class.getDeclaredField("resource")));
         type.add(resource);
         type.setScope(org.apache.tuscany.implementation.java.impl.Scope.STATELESS);
         type.setConstructorDefinition(ctorDef);

Modified: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java?view=diff&rev=526976&r1=526975&r2=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java Mon Apr  9 17:38:35 2007
@@ -22,7 +22,6 @@
 
 import org.apache.tuscany.core.component.WorkContextImpl;
 import org.apache.tuscany.core.component.scope.ConversationalScopeContainer;
-import org.apache.tuscany.core.services.store.memory.MemoryStore;
 import org.apache.tuscany.spi.component.ScopeContainer;
 import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.services.store.StoreMonitor;

Added: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java?view=auto&rev=526976
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java Mon Apr  9 17:38:35 2007
@@ -0,0 +1,196 @@
+/*
+ * 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.core.integration.conversation;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.tuscany.spi.annotation.Monitor;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.event.AbstractEventPublisher;
+import org.apache.tuscany.spi.services.store.DuplicateRecordException;
+import org.apache.tuscany.spi.services.store.RecoveryListener;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+import org.apache.tuscany.spi.services.store.StoreWriteException;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Implements a non-durable, non-transactional store using a simple in-memory map
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(Store.class)
+@EagerInit
+public class MemoryStore extends AbstractEventPublisher implements Store {
+    private Map<SCAObject, Map<String, Record>> store;
+    // TODO integrate with a core threading scheme
+    private ScheduledExecutorService scheduler;
+    private long reaperInterval = 300000;
+    private StoreMonitor monitor;
+    private long defaultExpirationOffset = 600000; // 10 minutes
+
+    public MemoryStore(@Monitor StoreMonitor monitor) {
+        this.monitor = monitor;
+        this.store = new ConcurrentHashMap<SCAObject, Map<String, Record>>();
+        this.scheduler = Executors.newSingleThreadScheduledExecutor();
+    }
+
+    /**
+     * Returns the maximum default expiration offset for records in the store
+     *
+     * @return the maximum default expiration offset for records in the store
+     */
+    public long getDefaultExpirationOffset() {
+        return defaultExpirationOffset;
+    }
+
+    /**
+     * Sets the maximum default expiration offset for records in the store
+     */
+    @Property
+    public void setDefaultExpirationOffset(long defaultExpirationOffset) {
+        this.defaultExpirationOffset = defaultExpirationOffset;
+    }
+
+    /**
+     * Sets the interval for expired entry scanning to be performed
+     */
+    @Property
+    public void setReaperInterval(long reaperInterval) {
+        this.reaperInterval = reaperInterval;
+    }
+
+    public long getReaperInterval() {
+        return reaperInterval;
+    }
+
+    @Init
+    public void init() {
+        scheduler.scheduleWithFixedDelay(new Reaper(), reaperInterval, reaperInterval, TimeUnit.MILLISECONDS);
+        monitor.start("In-memory store started");
+    }
+
+    @Destroy
+    public void destroy() {
+        scheduler.shutdown();
+        monitor.stop("In-memory store stopped");
+    }
+
+    public void insertRecord(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException {
+        Map<String, Record> map = store.get(owner);
+        if (map == null) {
+            map = new ConcurrentHashMap<String, Record>();
+            store.put(owner, map);
+        }
+        if (map.containsKey(id)) {
+            throw new DuplicateRecordException(owner.getUri().toString(), id);
+        }
+        map.put(id, new Record(object, expiration));
+    }
+
+    public void updateRecord(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException {
+        Map<String, Record> map = store.get(owner);
+        if (map == null) {
+            throw new StoreWriteException("Record not found", owner.getUri().toString(), id);
+        }
+        Record record = map.get(id);
+        if (record == null) {
+            throw new StoreWriteException("Record not found", owner.getUri().toString(), id);
+        }
+        record.data = object;
+    }
+
+    public Object readRecord(SCAObject owner, String id) {
+        Map<String, Record> map = store.get(owner);
+        if (map == null) {
+            return null;
+        }
+        Record record = map.get(id);
+        if (record != null) {
+            return record.data;
+        }
+        return null;
+    }
+
+    public void removeRecords() {
+        store.clear();
+    }
+
+    public void removeRecord(SCAObject owner, String id) throws StoreWriteException {
+        Map<String, Record> map = store.get(owner);
+        if (map == null) {
+            throw new StoreWriteException("Owner not found", owner.getUri().toString(), id);
+        }
+        if (map.remove(id) == null) {
+            throw new StoreWriteException("Owner not found", owner.getUri().toString(), id);
+        }
+    }
+
+    public void recover(RecoveryListener listener) {
+        throw new UnsupportedOperationException();
+    }
+
+    private class Record {
+        private Object data;
+        private long expiration = NEVER;
+
+        public Record(Object data, long expiration) {
+            this.data = data;
+            this.expiration = expiration;
+        }
+
+        public Object getData() {
+            return data;
+        }
+
+        public long getExpiration() {
+            return expiration;
+        }
+    }
+
+    private class Reaper implements Runnable {
+
+        public void run() {
+            long now = System.currentTimeMillis();
+            for (Map.Entry<SCAObject, Map<String, Record>> entries : store.entrySet()) {
+                for (Map.Entry<String, Record> entry : entries.getValue().entrySet()) {
+                    final long expiration = entry.getValue().expiration;
+                    if (expiration != NEVER && now >= expiration) {
+                        SCAObject owner = entries.getKey();
+                        Object instance = entry.getValue().getData();
+                        // notify listeners of the expiration 
+                        StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance);
+                        publish(event);
+                        entries.getValue().remove(entry.getKey());
+                    }
+                }
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/core/integration/conversation/MemoryStore.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org