1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 package org.logicblaze.lingo.example;
19
20 import junit.framework.Assert;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 /***
25 * @version $Revision: 1.2 $
26 */
27 public class ExampleServiceImpl extends Assert implements ExampleService {
28 private static final transient Log log = LogFactory.getLog(ExampleServiceImpl.class);
29
30 private static String lastMethod;
31 private Object[] lastArguments;
32 private int delay = 10000;
33
34 public synchronized void someOneWayMethod(String name, int age) {
35 System.out.println("#### starting server side method for: " + name + " with age: " + age + " on instance: " + this);
36
37
38
39 System.out.println("####Ęsleeping for: " + delay + " millis to simulate slow server");
40
41 try {
42 Thread.sleep(delay);
43 }
44 catch (InterruptedException e) {
45 log.error("Caught: " + e, e);
46 }
47 lastMethod = "someOneWayMethod";
48 lastArguments = new Object[]{name, new Integer(age)};
49
50 System.out.println("#### completed server side method for: " + name + " with age: " + age);
51 }
52
53 public int regularRPC(String name) {
54 lastMethod = "regularRPC";
55 lastArguments = new Object[]{name};
56 return 55;
57 }
58
59 public void anotherRPC() throws Exception {
60 lastMethod = "anotherRPC";
61 lastArguments = new Object[0];
62 }
63
64 public void asyncRequestResponse(String stock, ResultListener listener) {
65 lastMethod = "asyncRequestResponse";
66 lastArguments = new Object[]{stock, listener};
67
68
69 try {
70 System.out.println("##### inside asyncRequestResponse() and about to call onResult()");
71 System.out.println("Remote proxy is: " + listener);
72
73 listener.onResult("Price for " + stock + " is 10");
74 try {
75 Thread.sleep(500);
76 }
77 catch (InterruptedException e) {
78
79 }
80 listener.onResult("Price for " + stock + " is 11");
81 listener.stop();
82 }
83 catch (Exception e) {
84 System.out.println("#### error: " + e);
85 e.printStackTrace();
86 }
87 }
88
89
90
91 public String getLastMethod() {
92 return lastMethod;
93 }
94
95 public Object[] getLastArguments() {
96 return lastArguments;
97 }
98
99 public synchronized void assertOneWayCalled() {
100 assertNotNull("lastMethod should not be null if we have been invoked on instance: " + this, lastMethod);
101 }
102
103 public synchronized void assertOneWayNotCompletedYet() {
104 assertEquals("lastMethod not have a value yet on instance: " + this, null, lastMethod);
105 }
106
107 public int getDelay() {
108 return delay;
109 }
110
111 public void setDelay(int delay) {
112 this.delay = delay;
113 }
114 }