summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/core-spi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-09-25 21:08:37 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-09-25 21:08:37 +0000
commitcfb7e9a18f0cfdc2ca01874902e95adb61b4c6b8 (patch)
treedecd5b28667e04d467af0a2cabefee310dc1708f /java/sca/modules/core-spi/src
parentd64d402c3cf248b93abdc01c3187ca5227512952 (diff)
Refactor CompositeActivator, ComponentContext and other related interfaces into core-spi module
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819009 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/core-spi/src')
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java215
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java57
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java37
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java127
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java38
-rw-r--r--java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java3
6 files changed, 477 insertions, 0 deletions
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java
new file mode 100644
index 0000000000..98a20d27d5
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/CompositeContext.java
@@ -0,0 +1,215 @@
+/*
+ * 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.sca.context;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.CompositeActivator;
+import org.apache.tuscany.sca.runtime.EndpointRegistry;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class CompositeContext {
+ /**
+ * Create a self-reference for a component service
+ * @param component
+ * @param service
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public abstract ComponentReference createSelfReference(Component component,
+ ComponentService service,
+ Class<?> businessInterface)
+ throws CloneNotSupportedException, InvalidInterfaceException;
+
+ /**
+ * Bind a component reference to a component service
+ * @param <B>
+ * @param businessInterface
+ * @param reference
+ * @param service
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public abstract RuntimeComponentReference bindComponentReference(Class<?> businessInterface,
+ RuntimeComponentReference reference,
+ RuntimeComponent component,
+ RuntimeComponentService service)
+ throws CloneNotSupportedException, InvalidInterfaceException;
+
+ /**
+ * @param component
+ * @param reference
+ * @param writer
+ * @throws IOException
+ */
+ public abstract void write(Component component, ComponentReference reference, Writer writer) throws IOException;
+
+ /**
+ * @param component
+ * @param reference
+ * @param service
+ * @param writer
+ * @throws IOException
+ */
+ public abstract void write(Component component,
+ ComponentReference reference,
+ ComponentService service,
+ Writer writer) throws IOException;
+
+ /**
+ * @param component
+ * @param reference
+ * @return
+ * @throws IOException
+ */
+ public abstract String toXML(Component component, ComponentReference reference) throws IOException;
+
+ /**
+ * @param component
+ * @param service
+ * @return
+ * @throws IOException
+ */
+ public abstract String toXML(Component component, ComponentService service) throws IOException;
+
+ /**
+ * @param reader
+ * @return
+ * @throws IOException
+ */
+ public abstract RuntimeComponent read(Reader reader) throws IOException;
+
+ /**
+ * @param streamReader
+ * @return
+ * @throws IOException
+ */
+ public abstract RuntimeComponent read(XMLStreamReader streamReader) throws IOException;
+
+ /**
+ * @param xml
+ * @return
+ * @throws IOException
+ */
+ public abstract Component fromXML(String xml) throws IOException;
+
+ /**
+ * @param streamReader
+ * @return
+ * @throws IOException
+ */
+ public abstract Component fromXML(XMLStreamReader streamReader) throws IOException;
+
+ /**
+ * @return
+ */
+ public static RuntimeComponent getCurrentComponent() {
+ Message message = ThreadMessageContext.getMessageContext();
+ if (message != null) {
+ Endpoint to = message.getTo();
+ if (to == null) {
+ return null;
+ }
+ RuntimeComponent component = (RuntimeComponent) message.getTo().getComponent();
+ return component;
+ }
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ public static CompositeActivator getCurrentCompositeActivator() {
+ RuntimeComponent component = getCurrentComponent();
+ if (component != null) {
+ RuntimeComponentContext context = component.getComponentContext();
+ return context.getCompositeActivator();
+ }
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ public static CompositeContext getCurrentCompositeContext() {
+ CompositeActivator activator = getCurrentCompositeActivator();
+ if (activator != null) {
+ return activator.getCompositeContext();
+ }
+ return null;
+ }
+
+ /**
+ * @param component
+ */
+ public static ComponentService getSingleService(Component component) {
+ ComponentService targetService;
+ List<ComponentService> services = component.getServices();
+ List<ComponentService> regularServices = new ArrayList<ComponentService>();
+ for (ComponentService service : services) {
+ if (service.isForCallback()) {
+ continue;
+ }
+ String name = service.getName();
+ if (!name.startsWith("$") || name.startsWith("$dynamic$")) {
+ regularServices.add(service);
+ }
+ }
+ if (regularServices.size() == 0) {
+ throw new ServiceRuntimeException("No service is declared on component " + component.getURI());
+ }
+ if (regularServices.size() != 1) {
+ throw new ServiceRuntimeException("More than one service is declared on component " + component.getURI()
+ + ". Service name is required to get the service.");
+ }
+ targetService = regularServices.get(0);
+ return targetService;
+ }
+
+ public abstract ExtensionPointRegistry getExtensionPointRegistry();
+
+ /**
+ * Get the EndpointRegistry
+ * @return
+ */
+ public abstract EndpointRegistry getEndpointRegistry();
+
+}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
new file mode 100644
index 0000000000..d6237b7ce3
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
@@ -0,0 +1,57 @@
+/*
+ * 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.sca.context;
+
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Class for tunnelling a WorkContext through the invocation of a user class.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class ThreadMessageContext {
+
+ private static final ThreadLocal<Message> CONTEXT = new ThreadLocal<Message>();
+
+ private ThreadMessageContext() {
+ }
+
+ public static Message setMessageContext(Message context) {
+ Message old = CONTEXT.get();
+ CONTEXT.set(context);
+ return old;
+ }
+
+ /**
+ * Returns the WorkContext for the current thread.
+ *
+ * @return the WorkContext for the current thread
+ */
+ public static Message getMessageContext() {
+ return CONTEXT.get();
+ }
+
+ /**
+ * Removes and state from the current thread to ensure that
+ * any associated classloaders can be GCd
+ */
+ public static void removeMessageContext() {
+ CONTEXT.remove();
+ }
+}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java
new file mode 100644
index 0000000000..b015891e93
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ActivationException.java
@@ -0,0 +1,37 @@
+/*
+ * 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.sca.runtime;
+
+
+/**
+ * Denotes an error starting the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public class ActivationException extends Exception {
+ private static final long serialVersionUID = 8612661660934426123L;
+
+ public ActivationException(String message) {
+ super(message);
+ }
+
+ public ActivationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java
new file mode 100644
index 0000000000..a80a14f7f2
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java
@@ -0,0 +1,127 @@
+/*
+ * 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.sca.runtime;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.context.CompositeContext;
+
+/**
+ * Start/stop a composite
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeActivator {
+ /**
+ * Activate a composite
+ * @param composite
+ */
+ void activate(Composite composite) throws ActivationException;
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void start(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * Stop a composite
+ * @param composite
+ */
+ void deactivate(Composite composite) throws ActivationException;
+
+ /**
+ * Start a component
+ * @param component
+ */
+ void start(Component component) throws ActivationException;
+
+ /**
+ * Stop a component
+ * @param component
+ */
+ void stop(Component component) throws ActivationException;
+
+ /**
+ * Start components in a composite
+ * @param composite
+ */
+ void start(Composite composite) throws ActivationException;
+
+ /**
+ * Stop components in a composite
+ * @param composite
+ */
+ void stop(Composite composite) throws ActivationException;
+
+ /**
+ * Get the component context helper
+ * @return
+ */
+ CompositeContext getCompositeContext();
+
+ /**
+ * Configure the runtime component with component context
+ * @param component
+ */
+ void configureComponentContext(RuntimeComponent component);
+
+ /**
+ * Set the domain composite
+ * @param domainComposite
+ */
+ void setDomainComposite(Composite domainComposite);
+
+ /**
+ * Get the domain composite
+ * @return
+ */
+ Composite getDomainComposite();
+
+}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java
new file mode 100644
index 0000000000..c56869170a
--- /dev/null
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointSerializer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.sca.runtime;
+
+import java.io.IOException;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+
+/**
+ * A utility to seralize/deserialize Endpoint/EndpointReference objects
+ */
+public interface EndpointSerializer {
+ void read(Endpoint endpoint, String xml) throws IOException;
+
+ String write(Endpoint endpoint) throws IOException;
+
+ void read(EndpointReference endpointReference, String xml) throws IOException;
+
+ String write(EndpointReference endpointReference) throws IOException;
+}
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
index 236a143fb3..eadfccf064 100644
--- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
+++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
@@ -25,6 +25,7 @@ import java.io.Writer;
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.context.CompositeContext;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.oasisopen.sca.ComponentContext;
import org.oasisopen.sca.ServiceReference;
@@ -102,4 +103,6 @@ public interface RuntimeComponentContext extends ComponentContext {
<B> ServiceReference<B> createSelfReference(Class<B> businessInterface, ComponentService service);
ExtensionPointRegistry getExtensionPointRegistry();
+ CompositeActivator getCompositeActivator();
+ CompositeContext getCompositeContext();
}