From a24d6e044cdcf39d7a5045623e4eed78968b8c64 Mon Sep 17 00:00:00 2001 From: fmoga Date: Mon, 21 Feb 2011 12:00:24 +0000 Subject: Copy 2.0-Beta2-RC3 tag as 2.0-Beta2 final release tag. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1072933 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/sample/CallBack.java | 33 +++++++ .../callback-api/src/main/java/sample/Client.java | 28 ++++++ .../src/main/java/sample/ClientImpl.java | 108 +++++++++++++++++++++ .../src/main/java/sample/Launcher.java | 60 ++++++++++++ .../callback-api/src/main/java/sample/Service.java | 36 +++++++ .../src/main/java/sample/ServiceImpl.java | 96 ++++++++++++++++++ 6 files changed, 361 insertions(+) create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/CallBack.java create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Client.java create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ClientImpl.java create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Launcher.java create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Service.java create mode 100644 sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ServiceImpl.java (limited to 'sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample') diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/CallBack.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/CallBack.java new file mode 100644 index 0000000000..16e4297e9d --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/CallBack.java @@ -0,0 +1,33 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The callback interface. + */ +@Remotable +public interface CallBack { + + void callBackMessage(String aString); + + void callBackIncrement(); + +} diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Client.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Client.java new file mode 100644 index 0000000000..7e0709e660 --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Client.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Client { + + void run(); + +} diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ClientImpl.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ClientImpl.java new file mode 100644 index 0000000000..01219aa608 --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ClientImpl.java @@ -0,0 +1,108 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + +@Service(Client.class) +public class ClientImpl implements Client, CallBack { + + public static final String DELIMITER = "\n----------------------------"; + + @Reference + protected sample.Service service; + + private static int callBackCount = 0; + + /** + * This function prints the message received from the service + * implementation. + * + * @param String the message received from the service + */ + public void callBackMessage(String aString) { + System.out.println("ClientImpl - Received callback message: " + aString); + } + + /** + * This function increments the callBackCount variable when called from the + * service implementation. + */ + public void callBackIncrement() { + System.out.println("ClientImpl - Received increment callback"); + callBackCount++; + System.out.println("ClientImpl - Callback counter incremented to : " + getCallBackCount()); + } + + /** + * This method runs different kinds of service calls implying callbacks. + */ + public void run() { + simpleCallBack(); + simpleCallBackByRef(); + noCallBack(); + multipleCallBack(); + } + + /** + * The basic callback where the target calls back prior to returning to the + * client. + */ + private void simpleCallBack() { + System.out.println(DELIMITER + "\nSimple callback" + DELIMITER); + service.knockKnock("Knock Knock"); + } + + /** + * The basic callback where the target calls back prior to returning to the + * client. + */ + private void simpleCallBackByRef() { + System.out.println(DELIMITER + "\nSimple callback by reference" + DELIMITER); + service.knockKnockByRef("Knock Knock by reference"); + } + + /** + * The basic callback where the target does not call back to the client. + */ + private void noCallBack() { + System.out.println(DELIMITER + "\nNo callback" + DELIMITER); + service.noCallBack("No Reply Desired"); + } + + /** + * The basic callback where the target calls back multiple times to the + * client. + */ + private void multipleCallBack() { + System.out.println(DELIMITER + "\nMultiple callbacks" + DELIMITER); + service.multiCallBack("Call me back 3 times"); + } + + /** + * This function returns the callBackCount variable. + * + * @return Integer the callBackCount variable + */ + public int getCallBackCount() { + return callBackCount; + } + +} diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Launcher.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Launcher.java new file mode 100644 index 0000000000..fa1a59d726 --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Launcher.java @@ -0,0 +1,60 @@ +/* + * 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 sample; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +/** + * This class starts the Tuscany Runtime and runs the client calls to the + * service. + */ +public class Launcher { + + public static void main(String[] args) { + Node node = startRuntime(); + Client client = node.getService(Client.class, "Client"); + client.run(); + stopRuntime(node); + } + + /** + * Starts a Tuscany node with the predefined contribution. + * + * @return the running node + */ + private static Node startRuntime() { + String location = ContributionLocationHelper.getContributionLocation("CallBackApi.composite"); + Node node = NodeFactory.newInstance().createNode("CallBackApi.composite", new Contribution("c1", location)); + node.start(); + return node; + } + + /** + * Stops a Tuscany node. + * + * @param node the node to stop + */ + private static void stopRuntime(Node node) { + node.stop(); + } +} diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Service.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Service.java new file mode 100644 index 0000000000..6723af2adf --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/Service.java @@ -0,0 +1,36 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Callback; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +@Callback(CallBack.class) +public interface Service { + + void knockKnock(String aString); + + void knockKnockByRef(String aString); + + void noCallBack(String aString); + + void multiCallBack(String aString); + +} diff --git a/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ServiceImpl.java b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ServiceImpl.java new file mode 100644 index 0000000000..4850f434ff --- /dev/null +++ b/sca-java-2.x/tags/2.0-Beta2/samples/getting-started/callback-api/src/main/java/sample/ServiceImpl.java @@ -0,0 +1,96 @@ +/* + * 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 sample; + +import org.oasisopen.sca.ComponentContext; +import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.annotation.Callback; +import org.oasisopen.sca.annotation.Context; +import org.oasisopen.sca.annotation.Service; + +@Service(sample.Service.class) +public class ServiceImpl implements sample.Service { + + public static final String MESSAGE_RECEIVED = "ServiceImpl - Received message: "; + + @Context + protected ComponentContext componentContext; + + @Callback + protected ServiceReference callbackRef; + + /** + * This function gets an object of ServiceImpl by calling + * getCallBackInterface function and calls the callBackMessage function. + * + * @param aString String passed by a function call + */ + public void knockKnock(String aString) { + System.out.println(MESSAGE_RECEIVED + aString); + CallBack callback = this.getCallBackFromComponentContext(); + callback.callBackMessage("Who's There"); + } + + /** + * This function calls the callBackMessage function. The reference to this + * function is received from the callback reference to the Service class. + * + * @param aString String passed by a function call + */ + public void knockKnockByRef(String aString) { + System.out.println(MESSAGE_RECEIVED + aString); + callbackRef.getService().callBackMessage("Who's There"); + } + + /** + * This function gets an object of ServiceImpl by calling + * getCallBackInterface function. This function then places multiple + * callbacks using the callbackIncrement function defined in the callback + * implementation. + * + * @param aString String passed by a function call + */ + public void multiCallBack(String aString) { + CallBack callback = this.getCallBackFromComponentContext(); + System.out.println(MESSAGE_RECEIVED + aString); + callback.callBackIncrement(); + callback.callBackIncrement(); + callback.callBackIncrement(); + } + + /** + * This function does not callBack any function. + * + * @param aString String passed by a function call + */ + public void noCallBack(String aString) { + System.out.println(MESSAGE_RECEIVED + aString); + } + + /** + * This function gets an object of ServiceImpl from the present + * componentContext. + * + * @return the callback + */ + private CallBack getCallBackFromComponentContext() { + return componentContext.getRequestContext().getCallback(); + } + +} -- cgit v1.2.3