diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-12 20:57:24 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-12 20:57:24 +0000 |
commit | 667940fec12c91bb231d7f8ff477f9e78112b80b (patch) | |
tree | 3b3051540279487817ed2fef8bdbff6b85f0e5d6 /java/sca/modules/core | |
parent | c2b73c42cf96cb67efdf76a7c73635343a747ad3 (diff) |
Add methods to Endpoint/EndpointReference to set the ExtensionPointRegistry so that deserialized object can be resolved
Make the EndpointSerializer a declared utility
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@784270 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
5 files changed, 164 insertions, 79 deletions
diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java index bd8333ab70..0d9e4d1c86 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java @@ -6,15 +6,15 @@ * 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. + * under the License. */ package org.apache.tuscany.sca.runtime; @@ -29,54 +29,26 @@ import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Message; /** - * The runtime wire interface that connects a component reference to a + * The runtime wire interface that connects a component reference to a * component service (or an external service) over the selected binding - * + * * @version $Rev$ $Date$ */ public interface RuntimeWire extends Cloneable { - - - // ================================================================= - // TODO - EPR - remove the following three methods when we have - // changes the rest of the instructure over to using EndpointReference2 - // and EndpointReference2 throughout - /** - * Get the source of the wire - * - * @return The end point reference of the source - */ - // EndpointReference getSource(); - - /** - * Get the target of the wire - * - * @return The end point reference of the target - */ - // EndpointReference getTarget(); - - /** - * Rebind the runtime wire with the given target - * @param target The target endpoint reference - */ - // void setTarget(EndpointReference target); - - //================================================================== - /** * return the endpoint reference that configured this wire - * - * @return the endpoint reference that configured this wire + * + * @return the endpoint reference that configured this wire */ EndpointReference getEndpointReference(); - + /** * return the endpoint that configured this wire - * - * @return the endpoint that configured this wire + * + * @return the endpoint that configured this wire */ - Endpoint getEndpoint(); - + Endpoint getEndpoint(); + /** * Force the invocation chains to be rebuilt */ @@ -85,35 +57,35 @@ public interface RuntimeWire extends Cloneable { /** * Returns the invocation chains for service operations associated with the * wire - * + * * @return the invocation chains for service operations associated with the * wire */ List<InvocationChain> getInvocationChains(); - + /** * Lookup the invocation chain by operation * @param operation The operation * @return The invocation chain for the given operation */ InvocationChain getInvocationChain(Operation operation); - + /** * Get the invocation chain for the binding-specific handling * @return */ InvocationChain getBindingInvocationChain(); - + /** * This invoke method assumes that the binding invocation chain is in force * and that there will be an operation selector element there to - * determine which operation to call + * determine which operation to call * @param msg The message * @return The result * @throws InvocationTargetException */ - Object invoke(Message msg) throws InvocationTargetException; - + Object invoke(Message msg) throws InvocationTargetException; + /** * Invoke an operation with given arguments * @param operation The operation diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java index 73416f3a9f..8c84a9e399 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.core.assembly; import org.apache.tuscany.sca.assembly.AssemblyFactory; - import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; @@ -28,10 +27,11 @@ import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentServiceImpl; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl; /** @@ -59,25 +59,6 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As return new RuntimeComponentServiceImpl(); } - /* TODO - EPR - remove now - // FIXME: [rfeng] We need to find a more consistent story to deal with EPR, EP and CallableReference - public EndpointReference createEndpointReference(String uri) { - return new EndpointReferenceImpl(uri); - } - - public EndpointReference createEndpointReference(RuntimeComponent component, - Contract contract, - Binding binding, - InterfaceContract interfaceContract) { - return new EndpointReferenceImpl(component, contract, binding, interfaceContract); - } - - - public ReferenceParameters createReferenceParameters() { - return new ReferenceParametersImpl(); - } - */ - @Override public Endpoint createEndpoint() { // Create an instance of EndpointImpl that can be serialized/deserialized using the Tuscany @@ -87,7 +68,7 @@ public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements As @Override public EndpointReference createEndpointReference() { - return super.createEndpointReference(); + return new RuntimeEndpointReferenceImpl(registry); } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java index 770d94f211..f2ec7f8019 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointImpl.java @@ -26,17 +26,14 @@ import java.io.ObjectOutput; import org.apache.tuscany.sca.assembly.impl.EndpointImpl;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
/**
* Runtime model for Endpoint that supports java serialization
*/
public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable {
- /**
- * FIXME: What's the best way to get the extension point registry upon deserialization?
- * We can expose a method to receive the extension point registry
- */
- private static EndpointSerializer serializer;
+ private EndpointSerializer serializer;
private String xml;
/**
@@ -48,9 +45,6 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable public RuntimeEndpointImpl(ExtensionPointRegistry registry) {
super(registry);
- if (registry != null) {
- serializer = new EndpointSerializerImpl(registry);
- }
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
@@ -61,7 +55,19 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(getURI());
- out.writeUTF(serializer.write(this));
+ out.writeUTF(getSerializer().write(this));
+ }
+
+ private synchronized EndpointSerializer getSerializer() {
+ if (serializer == null) {
+ if (registry != null) {
+ serializer =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
+ } else {
+ throw new IllegalStateException("No extension registry is set");
+ }
+ }
+ return serializer;
}
@Override
@@ -74,7 +80,7 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable protected void resolve() {
if (component == null && xml != null) {
try {
- serializer.read(this, xml);
+ getSerializer().read(this, xml);
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -82,4 +88,13 @@ public class RuntimeEndpointImpl extends EndpointImpl implements Externalizable super.resolve();
}
+ @Override
+ public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
+ if (this.registry != registry) {
+ super.setExtensionPointRegistry(registry);
+ serializer = null;
+ }
+ // resolve();
+ }
+
}
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java new file mode 100644 index 0000000000..36f49eac5e --- /dev/null +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeEndpointReferenceImpl.java @@ -0,0 +1,100 @@ +/*
+ * 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.core.assembly.impl;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.EndpointSerializer;
+
+/**
+ * Runtime model for Endpoint that supports java serialization
+ */
+public class RuntimeEndpointReferenceImpl extends EndpointReferenceImpl implements Externalizable {
+ private EndpointSerializer serializer;
+ private String xml;
+
+ /**
+ * No-arg constructor for Java serilization
+ */
+ public RuntimeEndpointReferenceImpl() {
+ super(null);
+ }
+
+ public RuntimeEndpointReferenceImpl(ExtensionPointRegistry registry) {
+ super(registry);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ this.uri = in.readUTF();
+ this.xml = in.readUTF();
+ // Defer the loading to resolve();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(getURI());
+ out.writeUTF(getSerializer().write(this));
+ }
+
+ private synchronized EndpointSerializer getSerializer() {
+ if (serializer == null) {
+ if (registry != null) {
+ serializer =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(EndpointSerializer.class);
+ } else {
+ throw new IllegalStateException("No extension registry is set");
+ }
+ }
+ return serializer;
+ }
+
+ @Override
+ protected void reset() {
+ super.reset();
+ this.xml = null;
+ }
+
+ @Override
+ protected void resolve() {
+ if (component == null && xml != null) {
+ try {
+ getSerializer().read(this, xml);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ super.resolve();
+ }
+
+ @Override
+ public void setExtensionPointRegistry(ExtensionPointRegistry registry) {
+ if (this.registry != registry) {
+ super.setExtensionPointRegistry(registry);
+ serializer = null;
+ }
+ // resolve();
+ }
+
+}
diff --git a/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.EndpointSerializer b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.EndpointSerializer new file mode 100644 index 0000000000..cc3306b325 --- /dev/null +++ b/java/sca/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.assembly.EndpointSerializer @@ -0,0 +1,17 @@ +# 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.
+org.apache.tuscany.sca.core.assembly.impl.EndpointSerializerImpl
\ No newline at end of file |