diff options
Diffstat (limited to 'tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context')
5 files changed, 0 insertions, 455 deletions
diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java deleted file mode 100644 index 374555bfb6..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemAtomicContext.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.ObjectCallbackException; -import org.apache.tuscany.core.injection.ObjectCreationException; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.TargetException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.ContextInitException; -import org.apache.tuscany.core.context.event.InstanceCreated; - -/** - * Manages system component implementation instances - * - * @version $Rev$ $Date$ - */ -public class SystemAtomicContext extends AbstractContext implements AtomicContext { - - private boolean eagerInit; - - private EventInvoker<Object> initInvoker; - - private EventInvoker<Object> destroyInvoker; - - private boolean stateless; - - // the cached target instance - private Object cachedTargetInstance; - - // responsible for creating a new implementation instance with injected references and properties - private ObjectFactory objectFactory; - - public SystemAtomicContext(String name, ObjectFactory objectFactory, boolean eagerInit, EventInvoker<Object> initInvoker, - EventInvoker<Object> destroyInvoker, boolean stateless) { - super(name); - assert (objectFactory != null) : "Object factory was null"; - if (eagerInit && initInvoker == null) { - throw new AssertionError("No intialization method found for eager init implementation"); - } - this.objectFactory = objectFactory; - this.eagerInit = eagerInit; - this.initInvoker = initInvoker; - this.destroyInvoker = destroyInvoker; - this.stateless = stateless; - } - - public void setName(String name) { - super.setName(name); - } - - protected int type; - - public int getType() { - return type; - } - - public void setType(int type) { - this.type = type; - } - - public void init() throws TargetException{ - getInstance(null); - } - - public void destroy() throws TargetException { - if (cachedTargetInstance != null) { - if (destroyInvoker != null) { - try { - destroyInvoker.invokeEvent(cachedTargetInstance); - } catch (ObjectCallbackException e) { - throw new TargetException(e.getCause()); - } - } - } - lifecycleState = STARTED; - } - - public synchronized Object getInstance(QualifiedName qName) throws TargetException { - if (cachedTargetInstance != null) { - return cachedTargetInstance; // already cached, just return - } - - if (getLifecycleState() == ERROR || getLifecycleState() == CONFIG_ERROR) { - return null; - } - synchronized (this) { - try { - Object instance = objectFactory.getInstance(); - // handle @Init - if (initInvoker != null) { - initInvoker.invokeEvent(instance); - } - publish(new InstanceCreated(this)); - lifecycleState = RUNNING; - if (stateless) { - return instance; - } else { - // cache the actual instance - cachedTargetInstance = instance; - return cachedTargetInstance; - } - } catch (ObjectCreationException e) { - lifecycleState = ERROR; - TargetException te = new TargetException("Error creating component instance", e); - te.setIdentifier(getName()); - throw te; - } - } - - } - - public Object getTargetInstance() throws TargetException { - return getInstance(null); - } - - public boolean isEagerInit() { - return eagerInit; - } - - public boolean isDestroyable() { - return (destroyInvoker != null); - } - - public void start() throws ContextInitException { - if (getLifecycleState() != UNINITIALIZED && getLifecycleState() != STOPPED) { - throw new IllegalStateException("Component must be in UNINITIALIZED state [" + getLifecycleState() + "]"); - } - if (objectFactory == null) { - lifecycleState = ERROR; - ContextInitException e = new ContextInitException("Object factory not found "); - e.setIdentifier(getName()); - throw e; - } - lifecycleState = INITIALIZED; - } - - public void stop() { - lifecycleState = STOPPED; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java deleted file mode 100644 index 9ac0abe38a..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemCompositeContextImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.tuscany.core.config.ConfigurationException; -import org.apache.tuscany.core.context.AutowireContext; -import org.apache.tuscany.core.context.AutowireResolutionException; -import org.apache.tuscany.core.context.CompositeContext; -import org.apache.tuscany.core.context.ConfigurationContext; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.ScopeStrategy; -import org.apache.tuscany.core.context.SystemCompositeContext; -import org.apache.tuscany.core.context.impl.AbstractCompositeContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; -import org.apache.tuscany.core.system.config.SystemObjectContextFactory; -import org.apache.tuscany.core.wire.WireFactoryFactory; -import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory; - - -/** - * Implements an composite context for system components. By default a system context uses the scopes specified by - * {@link org.apache.tuscany.core.system.context.SystemScopeStrategy}. In addition, it implements an autowire policy - * where entry points configured with a {@link org.apache.tuscany.core.system.assembly.SystemBinding} are matched - * according to their exposed interface. A system context may contain child composite contexts but an entry point in a - * child context will only be outwardly accessible if there is an entry point that exposes it configured in the - * top-level system context. - * - * @version $Rev$ $Date$ - */ -public class SystemCompositeContextImpl extends AbstractCompositeContext implements SystemCompositeContext { - public SystemCompositeContextImpl() { - super(); - eventContext = new EventContextImpl(); - scopeStrategy = new SystemScopeStrategy(); - } - - public SystemCompositeContextImpl(String name, - CompositeContext parent, - AutowireContext autowire, - ScopeStrategy strategy, - EventContext ctx, - ConfigurationContext configCtx - ) { - super(name, parent, strategy, ctx, configCtx); - setAutowireContext(autowire); - scopeIndex = new ConcurrentHashMap<String, ScopeContext>(); - } - - public void registerJavaObject(String componentName, Class<?> service, Object instance) throws ConfigurationException { - SystemObjectContextFactory configuration = new SystemObjectContextFactory(componentName, instance); - registerConfiguration(configuration); - ScopeContext scope = scopeContexts.get(configuration.getScope()); - registerAutowireInternal(service, componentName, scope); - } - - // FIXME These should be removed and configured - private static final MessageFactory messageFactory = new MessageFactoryImpl(); - - private static final WireFactoryFactory WIRE_FACTORY_FACTORY = new JDKWireFactoryFactory(); - - public <T> T resolveInstance(Class<T> instanceInterface) throws AutowireResolutionException { - if (CompositeContext.class.equals(instanceInterface)) { - return instanceInterface.cast(this); - } else if (MessageFactory.class.equals(instanceInterface)) { - return instanceInterface.cast(messageFactory); - } else if (WireFactoryFactory.class.equals(instanceInterface)) { - return instanceInterface.cast(WIRE_FACTORY_FACTORY); - } else { - return super.resolveInstance(instanceInterface); - } - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java deleted file mode 100644 index 107e676c47..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemEntryPointContext.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import org.apache.tuscany.core.builder.ContextResolver; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.CoreRuntimeException; -import org.apache.tuscany.core.context.EntryPointContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.TargetException; - -/** - * Manages an entry point into a system module. System entry points cache a direct (i.e. non-proxied) reference to a - * component instance. - * - * @version $Rev$ $Date$ - */ -public class SystemEntryPointContext extends AbstractContext implements EntryPointContext { - - // a reference to the component's implementation instance exposed by the entry point - private Object cachedInstance; - - private ContextResolver resolver; - - private QualifiedName targetName; - - private Class serviceInterface; - - public SystemEntryPointContext(String name, String targetName, Class serviceInterface, ContextResolver resolver) { - super(name); - assert (resolver != null) : "Context resolver was null"; - assert (targetName != null) : "Target name was null"; - assert (serviceInterface != null) : "Service interface is null"; - this.serviceInterface = serviceInterface; - this.resolver = resolver; - this.targetName = new QualifiedName(targetName); - } - - public Object getInstance(QualifiedName qName) throws TargetException { - try { - if (cachedInstance == null) { - Context ctx = resolver.getCurrentContext().getContext(targetName.getPartName()); - if (ctx == null){ - return null; - } - cachedInstance = ctx.getInstance(targetName); - } - return cachedInstance; - } catch (TargetException e) { - e.addContextName(getName()); - throw e; - } - } - - public void start() throws CoreRuntimeException { - lifecycleState = RUNNING; - } - - public void stop() throws CoreRuntimeException { - lifecycleState = STOPPED; - } - - public Object getHandler() throws TargetException { - return getInstance(null); - } - - public Class getServiceInterface() { - return serviceInterface; - } -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java deleted file mode 100644 index b85bd2722b..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemExternalServiceContext.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import org.apache.tuscany.core.builder.ObjectFactory; -import org.apache.tuscany.core.context.impl.AbstractContext; -import org.apache.tuscany.core.context.ExternalServiceContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.TargetException; - -/** - * An implementation of an external service for system wiring. As system components are not proxied and the system - * binding is by-reference, the implementation caches a reference to its configured target. - * - * @version $Rev$ $Date$ - */ -public class SystemExternalServiceContext extends AbstractContext implements ExternalServiceContext { - - // a factory for retrieving the target of the external service wire - private ObjectFactory factory; - - // the cached target - private Object cachedInstance; - - public SystemExternalServiceContext(String name, ObjectFactory factory) { - super(name); - assert (factory != null) : "Object factory was null"; - this.factory = factory; - } - - public Object getInstance(QualifiedName qName) throws TargetException { - try { - if (cachedInstance == null) { - cachedInstance = factory.getInstance(); - } - return cachedInstance; - } catch (TargetException e) { - e.addContextName(getName()); - throw e; - } - - } - - public void start() { - lifecycleState = RUNNING; - } - - public void stop() { - lifecycleState = STOPPED; - } - - public Object getHandler() throws TargetException { - return this; - } - -} diff --git a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java b/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java deleted file mode 100644 index 76b9f2856d..0000000000 --- a/tags/java-M1-final/java/sca/core/src/main/java/org/apache/tuscany/core/system/context/SystemScopeStrategy.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed 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.system.context; - -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.scope.AbstractScopeStrategy; -import org.apache.tuscany.core.context.scope.CompositeScopeContext; -import org.apache.tuscany.core.context.scope.ModuleScopeContext; -import org.apache.tuscany.core.context.scope.StatelessScopeContext; -import org.apache.tuscany.model.assembly.Scope; - -import java.util.HashMap; -import java.util.Map; - -/** - * Implements a {@link org.apache.tuscany.core.context.ScopeStrategy} for a system composite context with the following scopes: - * <ul> - * <li>{@link org.apache.tuscany.model.assembly.Scope#AGGREGATE}</li> - * <li>{@link org.apache.tuscany.model.assembly.Scope#MODULE}</li> - * <li>{@link org.apache.tuscany.model.assembly.Scope#INSTANCE}</li> - * </ul> - * - * @version $Rev$ $Date$ - */ -public class SystemScopeStrategy extends AbstractScopeStrategy { - - public SystemScopeStrategy() { - } - - public Map<Scope, ScopeContext> getScopeContexts(EventContext eventContext) { - ScopeContext aggregrateScope = new CompositeScopeContext(eventContext); - ScopeContext moduleScoper = new ModuleScopeContext(eventContext); - ScopeContext statelessScope = new StatelessScopeContext(eventContext); - Map<Scope, ScopeContext> scopes = new HashMap<Scope, ScopeContext>(); - scopes.put(Scope.AGGREGATE, aggregrateScope); - scopes.put(Scope.MODULE, moduleScoper); - scopes.put(Scope.INSTANCE, statelessScope); - return scopes; - } - -} |