Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 147 148 149 150 151 152 < 153 > 154 155 156 157 158 159 .. 166 >> Next

058 preInvokeTime = afterproxy - initial;
059 System.out.println("Invocation setup took " +
060 preInvokeTime + " milliseconds.");
061
062 String response = (String)call.invoke(params);
063 }
064 catch ( Exception ex )
065 {
066 ex.printStackTrace();
067 }
068 }
069 }
Listing 48.5 (continued)
Performance Pitfalls in JAX-RPC Application Clients 425
Our example in Listing 48.5 requires no precompilation or WSDL lookups. Because we knew the information in advance, we could hard-code it into our application. On line 59, we made sure to print out the milliseconds for invocation setup.
Our final client code example is another example of using DII. DII is quite powerful, because you can dynamically determine your interfaces at runtime, looking at the WSDL, and discover information about the operations that a Web service supports. Listing 48.6 is such an example. Like the last example, using DII is convenient because it requires no precompilation of code or local Java interfaces at compile time. Everything with DII occurs at runtime.
In this example, we ask the service for the first method, and we simply invoke the method. In our example, we know the method takes a string as a parameter. Because we pass the URL of the WSDL in lines 31 to 33 of Listing 48.6, our Service object will have the ability to download the WSDL and get call information for the Web service. In line 38, we ask the Web service for the names of available calls. On line 48, we request the first call available, which we know is the method we would like to invoke. Finally, we set up the parameter on line 52, and we invoke the method on line 63.
001 package 8 4 m e t i s l l a LM t i p a v a j g. r o
002
003 import java.net.*;
004 import javax.xml.rpc.*;
005 import javax.xml.namespace.*;
006
007 public class DIILookupClient
008 {
009
010
011 public static void main(String[] args)
012 {
013 try
014 {
015 long initial, afterproxy, prelnvokeTime, invokeTime;
016
017 initial = System.currentTimeMillis();
018
019 String UrlString =
020 "http://localhost:8080/simpletest-jaxrpc/simpletest?WSDL";
021 String nameSpaceUri =
022 "http://org.javapitfalls.item48/wsdl/SimpleTest";
023 String serviceName = "SimpleTest";
024 String portName = "SimpleTestlFPort";
025 String qnamePort = "SimpleTestIF";
026
027 URL wsdlUrl = new URL(UrlString);
Listing 48.6 A simple client using DII with lookups (continued)
426 Item 48
028
029 ServiceFactory serviceFactory =
030 ServiceFactory.newInstance();
031 Service simpleService =
032 serviceFactory.createService(wsdlUrl,
033 new QName(nameSpaceUri,serviceName));
034
035 QName port = new QName(nameSpaceUri, portName);
036
037
038 Call[] servicecalls = simpleService.getCalls(port);
039 Call mycall = null;
040
041 /*
042 * We will assume that we know to call the first method &
043 * pass it a string..
044 */
045
046 if ( servicecalls != null )
047 {
048 mycall = servicecalls[0];
049 String operationName =
050 mycall.getOperationName().toString();
051
052 String[] params = { "Hello from DII Client!"};
053
054
055 afterproxy = System.currentTimeMillis();
056 preInvokeTime = afterproxy - initial;
057
058 System.out.println("Invocation setup took "
059 + preInvokeTime + " milliseconds.);
060 System.out.println("About to call the "
061 + operationName + " operation..);
062
063 String response = (String)mycall.invoke(params);
064 System.out.println("Received '"
065 + response + "' as a response..);
066
067
068 }
069 else
070
071 System.out.println("Problem with DII command..);
Listing 48.6 (continued)
Performance Pitfalls in JAX-RPC Application Clients 427
072 }
073
074 }
075 catch ( Exception ex )
076 {
077 ex.printStackTrace();
077 }
078 }
079 }
Listing 48.6 (continued)
Everything in this example used the capabilities of DII, getting call information at runtime. Many more methods on the javax.xml.rpc.Call interface could be used, but for the purpose of simplicity, this example doesn't use them all. For more information about the JAX-RPC API and specification, go to Sun's JAX-RPC Web page at http://java.sun.com/xml/jaxrpc/.
Performance Results
For our experiment, we deployed our Web service and used the code from Listings 48.3, 48.4, 48.5, and 48.6. Our experiment was run with the Web service and the client running on a 1300-MHz Pentium IV PC with 1 GB RAM, using the Windows 2000 operating system. Each "run" was done by running each client, in random order, one after another. The client VM was Java HotSpot Client VM (build 1.4.0-b92, mixed mode), and the tools and Web services were running with the Java Web Services Developer's Pack, version 1.0_01. Table 48.1 shows the results.
As you can see, there is an obvious trade-off between flexibility at runtime and performance. The best performing clients (with respect to invocation setup) were those in Listings 48.3 and 48.5. Our hard-coded DII example in Listing 48.5 matched the performance of our precompiled stubs example. This makes sense, because no WSDL lookup was necessary in the hard-coded example.
Previous << 1 .. 147 148 149 150 151 152 < 153 > 154 155 156 157 158 159 .. 166 >> Next