summaryrefslogtreecommitdiffstats
path: root/sandbox/giorgio/binding-p2p
diff options
context:
space:
mode:
authorgiorgio <giorgio@13f79535-47bb-0310-9956-ffa450edef68>2009-07-27 19:24:52 +0000
committergiorgio <giorgio@13f79535-47bb-0310-9956-ffa450edef68>2009-07-27 19:24:52 +0000
commit339cce2e53738e93c67d330c063bcce965399d35 (patch)
tree29ae5948d42d21e1a3e329c9df1b14d8564ac01f /sandbox/giorgio/binding-p2p
parentf18abd2aa0e272086f0e74f564285e449af79f16 (diff)
skeleton version of binding p2p
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@798265 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/giorgio/binding-p2p')
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBinding.java59
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingFactory.java30
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingInvoker.java71
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java31
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java156
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.p2p.P2PBindingFactory19
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory19
-rw-r--r--sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
8 files changed, 404 insertions, 0 deletions
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBinding.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBinding.java
new file mode 100644
index 0000000000..6674af748b
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBinding.java
@@ -0,0 +1,59 @@
+/*
+ * 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.binding.p2p;
+
+import org.apache.tuscany.sca.assembly.Binding;
+
+/**
+ * P2P Binding model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface P2PBinding extends Binding {
+
+ /**
+ * @return the host name of the P2P Service
+ */
+ String getHost();
+
+ /**
+ * @return the port number for the P2P Service
+ */
+ String getPort();
+
+
+ /**
+ * @param p2pHostName the hostname of the P2P Service
+ */
+ void setHost(String p2pHostName);
+
+ /**
+ * @param p2pPort the port number for the P2P Service
+ */
+ void setPort(String p2pPort);
+
+ /**
+ * Sets the service name for the P2P Server
+ *
+ * @param p2pServiceName the name of the P2P service
+ */
+ void setServiceName(String p2pServiceName);
+
+}
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingFactory.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingFactory.java
new file mode 100644
index 0000000000..416cb7244f
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingFactory.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binding.p2p;
+
+/**
+ * Factory to create éP2PBinding instances
+ *
+ * @version $Rev$ $Date$
+ */
+public interface P2PBindingFactory {
+
+ P2PBinding createP2PBinding();
+}
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingInvoker.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingInvoker.java
new file mode 100644
index 0000000000..13a95cedc9
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/P2PBindingInvoker.java
@@ -0,0 +1,71 @@
+/*
+ * 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.binding.p2p.provider;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
+
+
+public class P2PBindingInvoker implements Invoker, DataExchangeSemantics {
+
+ private String uri;
+ private XmlRpcClientConfigImpl config;
+ private XmlRpcClient client;
+ private Method remoteMethod;
+ public P2PBindingInvoker(String uri, Method remoteMethod) {
+ this.client = new XmlRpcClient();
+ this.config = new XmlRpcConfigImpl();
+ this.remoteMethod = remoteMethod;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+
+ Object[] args = msg.getBody();
+ Object resp = invokeTarget(args);
+ msg.setBody(resp);
+
+ } catch (InvocationTargetException e) {
+ msg.setFaultBody(e.getCause());
+ } catch (Throwable e) {
+ msg.setFaultBody(e);
+ }
+
+ return msg;
+ }
+
+ public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException
+ {
+
+ return client.execute(this.remoteMethod,payload);
+ }
+
+ public boolean allowsPassByReference() {
+ return true;
+ }
+
+}
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java
new file mode 100644
index 0000000000..02e18bafbb
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingFactoryImpl.java
@@ -0,0 +1,31 @@
+/*
+ * 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.binding.p2p.impl;
+
+import org.apache.tuscany.sca.binding.p2p.P2PBindingImpl;
+import org.apache.tuscany.sca.binding.p2p.P2PBindingFactory;
+
+public class P2PBindingFactoryImpl implements P2PBindingFactory, {
+ public P2Pinding createP2PBinding() {
+ // TODO Auto-generated method stub
+ return new P2PBindingImpl();
+ }
+
+}
diff --git a/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java
new file mode 100644
index 0000000000..acece50f9d
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/java/org/apache/tuscany/sca/binding/p2p/impl/P2PBindingImpl.java
@@ -0,0 +1,156 @@
+/*
+ * 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.binding.p2p.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.sca.binding.p2p.P2PBinding;
+
+/**
+ * Represents a binding to an overlay weaver P2P service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class P2PBindingImpl implements P2PBinding {
+ private String name;
+ private String uri;
+ private String host;
+ private String port;
+ private String serviceName;
+
+ /**
+ * @return the host name of the P2P Service
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * @param rmiHostName the hostname of the P2P Service
+ */
+ public void setHost(String rmiHostName) {
+ this.host = rmiHostName;
+ }
+
+ /**
+ * @return the port number for the RMI Service
+ */
+ public String getPort() {
+ return port;
+ }
+
+ /**
+ * @param rmiPort the port number for the RMI Service
+ */
+ public void setPort(String rmiPort) {
+ this.port = rmiPort;
+ }
+
+ /**
+ * @return returns the RMI Service Name
+ */
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ /**
+ * Sets the service name for the RMI Server
+ *
+ * @param rmiServiceName the name of the RMI service
+ */
+ public void setServiceName(String rmiServiceName) {
+ this.serviceName = rmiServiceName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getURI() {
+ compose();
+ return uri;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ parse(uri);
+ }
+
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // The sample binding is always resolved
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /*
+ p2p://[host][:port][/[object]]
+ */
+ private void parse(String uriStr) {
+ if (uriStr == null) {
+ return;
+ }
+ URI uri = URI.create(uriStr);
+ if (host == null) {
+ this.host = uri.getHost();
+ }
+ if (port == null) {
+ this.port = String.valueOf(uri.getPort());
+ }
+ if (serviceName == null) {
+ String path = uri.getPath();
+ if (path != null && path.charAt(0) == '/') {
+ path = path.substring(1);
+ }
+ this.serviceName = path;
+ }
+ }
+
+ private void compose() {
+ if (uri == null) {
+ int p = -1;
+ if (port != null && port.length() > 0) {
+ p = Integer.decode(port);
+ }
+ String path = serviceName;
+ if (path != null) {
+ path = "/" + path;
+ }
+ try {
+ uri = new URI("p2p", null, host, p, path, null, null).toString();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ }
+
+
+}
diff --git a/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.p2p.P2PBindingFactory b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.p2p.P2PBindingFactory
new file mode 100644
index 0000000000..bf608fd70b
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.p2p.P2PBindingFactory
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for model factory
+org.apache.tuscany.sca.binding.p2p.impl.P2PBindingFactoryImpl
diff --git a/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory
new file mode 100644
index 0000000000..bf608fd70b
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.rmi.RMIBindingFactory
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for model factory
+org.apache.tuscany.sca.binding.p2p.impl.P2PBindingFactoryImpl
diff --git a/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..9f279ecfc4
--- /dev/null
+++ b/sandbox/giorgio/binding-p2p/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.p2p,model=org.apache.tuscany.sca.binding.p2p.P2PBinding,factory=org.apache.tuscany.sca.binding.p2p.P2PBindingFactory