Author: jboynes
Date: Mon Apr 24 04:38:07 2006
New Revision: 396520
URL: http://svn.apache.org/viewcvs?rev=396520&view=rev
Log:
separate ScopeContext from Context hierarchy
Added:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
(with props)
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ScopeContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/AbstractScopeContext.java
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/CompositeScopeContext.java
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Context.java
Mon Apr 24 04:38:07 2006
@@ -23,21 +23,6 @@
* @version $Rev$ $Date$
*/
public interface Context extends EventPublisher, Lifecycle {
-
- /* A configuration error state */
- public static final int CONFIG_ERROR = -1;
-
- /**
- * Returns the name of the context
- */
- public String getName();
-
- /**
- * Sets the name of the context
- */
- public void setName(String name);
-
-
/**
* Returns the instance associated with the requested name, which may be
in a atomic or composite form. Atomic (i.e.
* leaf) contexts will return an instance associated with the service name
part of the compound name, which may be
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/Lifecycle.java
Mon Apr 24 04:38:07 2006
@@ -20,6 +20,8 @@
* @version $Rev$ $Date$
*/
public interface Lifecycle {
+ /* A configuration error state */
+ int CONFIG_ERROR = -1;
/* Has not been initialized */
int UNINITIALIZED = 0;
/* In the process of being configured and initialized */
@@ -50,16 +52,28 @@
int getLifecycleState();
/**
- * Starts the container
+ * Starts the Lifecycle.
*
- * @throws org.apache.tuscany.core.context.CoreRuntimeException
+ * @throws CoreRuntimeException
*/
void start() throws CoreRuntimeException;
/**
- * Stops the container
+ * Stops the Lifecycle.
*
- * @throws org.apache.tuscany.core.context.CoreRuntimeException
+ * @throws CoreRuntimeException
*/
void stop() throws CoreRuntimeException;
+
+ /**
+ * Returns the name of the Lifecycle.
+ * @return the name of the Lifecycle
+ */
+ String getName();
+
+ /**
+ * Sets the name of the Lifecycle.
+ * @param name the name of the Lifecycle
+ */
+ void setName(String name);
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ScopeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ScopeContext.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ScopeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/ScopeContext.java
Mon Apr 24 04:38:07 2006
@@ -27,7 +27,9 @@
*
* @version $Rev$ $Date$
*/
-public interface ScopeContext extends Context, RuntimeEventListener {
+public interface ScopeContext extends Lifecycle, RuntimeEventListener {
+
+ public Object getInstance(QualifiedName qName) throws TargetException;
/**
* Returns whether implementation instances may be held for the duration
of an wire
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractContext.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractContext.java
Mon Apr 24 04:38:07 2006
@@ -29,109 +29,17 @@
/**
* Functionality common to all <code>Context<code> implementations
- *
+ *
* @version $Rev$ $Date$
*/
-public abstract class AbstractContext implements Context {
-
- private static final EventFilter TRUE_FILTER = new TrueFilter();
+public abstract class AbstractContext extends AbstractLifecycle implements
Context {
public AbstractContext() {
}
public AbstractContext(String name) {
- this.name = name;
- }
-
- protected String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- protected int lifecycleState = UNINITIALIZED;
-
- public int getLifecycleState() {
- return lifecycleState;
- }
-
- // Listeners for context events
- private Map<EventFilter, List<RuntimeEventListener>> listeners;
-
-
- public void addListener(RuntimeEventListener listener) {
- addListener(TRUE_FILTER, listener);
- }
-
- public void removeListener(RuntimeEventListener listener) {
- assert (listener != null) : "Listener cannot be null";
- synchronized(getListeners()){
- for (List<RuntimeEventListener> currentList
:getListeners().values() ) {
- for(RuntimeEventListener current : currentList){
- if (current == listener){
- currentList.remove(current);
- return;
- }
- }
- }
- }
- }
-
- public void addListener(EventFilter filter, RuntimeEventListener listener){
- assert (listener != null) : "Listener cannot be null";
- synchronized (getListeners()){
- List<RuntimeEventListener> list = getListeners().get(filter);
- if (list == null){
- list = new CopyOnWriteArrayList<RuntimeEventListener>();
- listeners.put(filter,list);
- }
- list.add(listener);
- }
+ super(name);
}
- public void publish(Event event){
- assert(event != null): "Event object was null";
- for(Map.Entry<EventFilter,List<RuntimeEventListener>> entry
:getListeners().entrySet()){
- if(entry.getKey().match(event)){
- for(RuntimeEventListener listener : entry.getValue()){
- listener.onEvent(event);
- }
- }
- }
- }
-
- protected Map<EventFilter, List<RuntimeEventListener>> getListeners(){
- if (listeners == null) {
- listeners = new ConcurrentHashMap<EventFilter,
List<RuntimeEventListener>>();
- }
- return listeners;
- }
-
- public String toString() {
- switch (lifecycleState) {
- case (CONFIG_ERROR):
- return "Context [" + name + "] in state [CONFIG_ERROR]";
- case (ERROR):
- return "Context [" + name + "] in state [ERROR]";
- case (INITIALIZING):
- return "Context [" + name + "] in state [INITIALIZING]";
- case (INITIALIZED):
- return "Context [" + name + "] in state [INITIALIZED]";
- case (RUNNING):
- return "Context [" + name + "] in state [RUNNING]";
- case (STOPPING):
- return "Context [" + name + "] in state [STOPPING]";
- case (STOPPED):
- return "Context [" + name + "] in state [STOPPED]";
- case (UNINITIALIZED):
- return "Context [" + name + "] in state [UNINITIALIZED]";
- default:
- return "Context [" + name + "] in state [UNKNOWN]";
- }
- }
}
Added:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java?rev=396520&view=auto
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
(added)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
Mon Apr 24 04:38:07 2006
@@ -0,0 +1,129 @@
+/**
+ *
+ * Copyright 2006 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.context.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.core.context.RuntimeEventListener;
+import org.apache.tuscany.core.context.EventFilter;
+import org.apache.tuscany.core.context.Lifecycle;
+import org.apache.tuscany.core.context.filter.TrueFilter;
+import org.apache.tuscany.core.context.event.Event;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractLifecycle {
+ private static final EventFilter TRUE_FILTER = new TrueFilter();
+ protected String name;
+ protected int lifecycleState = Lifecycle.UNINITIALIZED;
+ // Listeners for context events
+ private Map<EventFilter, List<RuntimeEventListener>> listeners;
+
+ public AbstractLifecycle(String name) {
+ this.name = name;
+ }
+
+ public AbstractLifecycle() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getLifecycleState() {
+ return lifecycleState;
+ }
+
+ public void addListener(RuntimeEventListener listener) {
+ addListener(TRUE_FILTER, listener);
+ }
+
+ public void removeListener(RuntimeEventListener listener) {
+ assert (listener != null) : "Listener cannot be null";
+ synchronized(getListeners()){
+ for (List<RuntimeEventListener> currentList
:getListeners().values() ) {
+ for(RuntimeEventListener current : currentList){
+ if (current == listener){
+ currentList.remove(current);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ public void addListener(EventFilter filter, RuntimeEventListener listener){
+ assert (listener != null) : "Listener cannot be null";
+ synchronized (getListeners()){
+ List<RuntimeEventListener> list = getListeners().get(filter);
+ if (list == null){
+ list = new CopyOnWriteArrayList<RuntimeEventListener>();
+ listeners.put(filter,list);
+ }
+ list.add(listener);
+ }
+ }
+
+ public void publish(Event event){
+ assert(event != null): "Event object was null";
+ for(Map.Entry<EventFilter,List<RuntimeEventListener>> entry
:getListeners().entrySet()){
+ if(entry.getKey().match(event)){
+ for(RuntimeEventListener listener : entry.getValue()){
+ listener.onEvent(event);
+ }
+ }
+ }
+ }
+
+ protected Map<EventFilter, List<RuntimeEventListener>> getListeners(){
+ if (listeners == null) {
+ listeners = new ConcurrentHashMap<EventFilter,
List<RuntimeEventListener>>();
+ }
+ return listeners;
+ }
+
+ public String toString() {
+ switch (lifecycleState) {
+ case (Lifecycle.CONFIG_ERROR):
+ return "Context [" + name + "] in state [CONFIG_ERROR]";
+ case (Lifecycle.ERROR):
+ return "Context [" + name + "] in state [ERROR]";
+ case (Lifecycle.INITIALIZING):
+ return "Context [" + name + "] in state [INITIALIZING]";
+ case (Lifecycle.INITIALIZED):
+ return "Context [" + name + "] in state [INITIALIZED]";
+ case (Lifecycle.RUNNING):
+ return "Context [" + name + "] in state [RUNNING]";
+ case (Lifecycle.STOPPING):
+ return "Context [" + name + "] in state [STOPPING]";
+ case (Lifecycle.STOPPED):
+ return "Context [" + name + "] in state [STOPPED]";
+ case (Lifecycle.UNINITIALIZED):
+ return "Context [" + name + "] in state [UNINITIALIZED]";
+ default:
+ return "Context [" + name + "] in state [UNKNOWN]";
+ }
+ }
+}
Propchange:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractLifecycle.java
------------------------------------------------------------------------------
svn:keywords = Rev,Date
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/AbstractScopeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/AbstractScopeContext.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/AbstractScopeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/AbstractScopeContext.java
Mon Apr 24 04:38:07 2006
@@ -16,24 +16,24 @@
*/
package org.apache.tuscany.core.context.scope;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.tuscany.core.builder.ContextFactory;
import org.apache.tuscany.core.context.Context;
import org.apache.tuscany.core.context.EventContext;
import org.apache.tuscany.core.context.QualifiedName;
import org.apache.tuscany.core.context.ScopeContext;
import org.apache.tuscany.core.context.TargetException;
-import org.apache.tuscany.core.context.impl.AbstractContext;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.tuscany.core.context.impl.AbstractLifecycle;
/**
* Implements functionality common to scope contexts.
*
* @version $Rev$ $Date$
*/
-public abstract class AbstractScopeContext extends AbstractContext implements
ScopeContext {
+public abstract class AbstractScopeContext extends AbstractLifecycle
implements ScopeContext {
// The collection of runtime configurations for the scope
protected Map<String, ContextFactory<Context>> contextFactories = new
ConcurrentHashMap<String, ContextFactory<Context>>();
@@ -63,8 +63,8 @@
}
protected void checkInit() {
- if (lifecycleState != RUNNING) {
- throw new IllegalStateException("Scope not running [" +
lifecycleState + "]");
+ if (getLifecycleState() != RUNNING) {
+ throw new IllegalStateException("Scope not running [" +
getLifecycleState() + "]");
}
}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/CompositeScopeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/CompositeScopeContext.java?rev=396520&r1=396519&r2=396520&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/CompositeScopeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/scope/CompositeScopeContext.java
Mon Apr 24 04:38:07 2006
@@ -16,24 +16,24 @@
*/
package org.apache.tuscany.core.context.scope;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.apache.tuscany.core.builder.ContextFactory;
+import org.apache.tuscany.core.context.CompositeContext;
import org.apache.tuscany.core.context.Context;
import org.apache.tuscany.core.context.EventContext;
import org.apache.tuscany.core.context.QualifiedName;
import org.apache.tuscany.core.context.ScopeContext;
-import org.apache.tuscany.core.context.TargetException;
-import org.apache.tuscany.core.context.impl.AbstractContext;
-import org.apache.tuscany.core.context.CompositeContext;
import org.apache.tuscany.core.context.ScopeInitializationException;
import org.apache.tuscany.core.context.ScopeRuntimeException;
+import org.apache.tuscany.core.context.TargetException;
+import org.apache.tuscany.core.context.event.Event;
import org.apache.tuscany.core.context.event.ModuleStart;
import org.apache.tuscany.core.context.event.ModuleStop;
-import org.apache.tuscany.core.context.event.Event;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.tuscany.core.context.impl.AbstractLifecycle;
/**
* Manages the lifecycle of composite component contexts, i.e. contexts which
contain child contexts
@@ -41,7 +41,7 @@
* @see org.apache.tuscany.core.context.CompositeContext
* @version $Rev$ $Date$
*/
-public class CompositeScopeContext extends AbstractContext implements
ScopeContext {
+public class CompositeScopeContext extends AbstractLifecycle implements
ScopeContext {
private List<ContextFactory<Context>> configs = new
ArrayList<ContextFactory<Context>>();
@@ -53,7 +53,7 @@
public CompositeScopeContext(EventContext eventContext) {
assert (eventContext != null) : "Event context was null";
- name = "Composite Scope";
+ setName("Composite Scope");
}
public void start() throws ScopeInitializationException {
@@ -84,7 +84,7 @@
public void registerFactory(ContextFactory<Context> configuration) {
assert (configuration != null) : "Configuration was null";
configs.add(configuration);
- if (lifecycleState == RUNNING) {
+ if (getLifecycleState() == RUNNING) {
Context context = configuration.createContext();
if (!(context instanceof CompositeContext)) {
ScopeInitializationException e = new
ScopeInitializationException("Context not an composite type");
@@ -148,8 +148,8 @@
}
private void checkInit() {
- if (lifecycleState != RUNNING) {
- throw new IllegalStateException("Scope not running [" +
lifecycleState + "]");
+ if (getLifecycleState()!= RUNNING) {
+ throw new IllegalStateException("Scope not running [" +
getLifecycleState() + "]");
}
}
}