Search |
||
The World's Slowest Web ServicePosted by campbell on April 26, 2006 at 5:03 PM PDT
The Set Up
Person: This rendering op is so slow...
Audience: How slow is it?
Person: It's so slow that it would be faster to air mail each
individual pixel to Timbuktu and back.
A few years ago when the phrase "web services" became all the rage we had to update the punchline:
Person: It's so slow that it would be faster to implement this
op as a web service and host the server in Timbuktu.
Okay, so you're not laughing, but I warned you earlier, I did. Plus, it doesn't help that our collective senses of humor have all been addled recently by Chet and his killer puns (Minneapplet anyone?)... But seriously forks, all the web service yumminess being integrated into Mustang has peaked my interest, especially from the desktop Java standpoint. I've seen a few JAX-WS 2.0 tutorials recently (see "Useful Resources" section below), but most are written from the server-side perspective, and therefore start out with "download the latest GlassFish build" or "grab the latest JWSDP release" or something similar. Already that's one too many steps for my lazy self. I'm a minimalist at heart, so what I really wanted to know was how quickly one could get up and running with JAX-WS using only the latest Mustang binaries. And what better way to learn than to bring that old "joke" to life, so I now present to a truly contrived example: a pixel blender service (and client).
Step 1: Write and compile the endpoint
package blend.endpoint;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService(serviceName="BlenderService")
public class Blender {
@WebMethod
public int blend(int src, int dst) {
int srcA = src >>> 24;
int srcR = (src >> 16) & 0xff;
int srcG = (src >> 8) & 0xff;
int srcB = (src ) & 0xff;
int dstA = dst >>> 24;
int dstR = (dst >> 16) & 0xff;
int dstG = (dst >> 8) & 0xff;
int dstB = (dst ) & 0xff;
int resA = (int)((srcA * 0.5) + (dstA * 0.5));
int resR = (int)((srcR * 0.5) + (dstR * 0.5));
int resG = (int)((srcG * 0.5) + (dstG * 0.5));
int resB = (int)((srcB * 0.5) + (dstB * 0.5));
return (resA << 24) | (resR << 16) | (resG << 8) | resB;
}
}
The "serviceName" parameter on
As the final part of this step, we will simply compile this source file:
Step 2: Generate the endpoint "portable artifacts"
We pass the
Step 3: Generate the client "portable artifacts"
The
Step 4: Write and compile the client application
package blend.client;
public class Test {
public static void main(String[] args) throws Exception {
BlenderService service = new BlenderService();
Blender blender = service.getBlenderPort();
int src = 0xff00ff00;
int dst = 0xff0000ff;
int res = blender.blend(src, dst);
System.out.printf("src=%08x dst=%08x result=%08x\n",
src, dst, res);
}
}
Note that by default this testcase will talk to the web service endpoint running at
Step 5: Publish the endpoint
package blend.endpoint;
import javax.xml.ws.Endpoint;
public class Test {
public static void main(String[] args) throws Exception {
Endpoint e = Endpoint.create(new Blender());
e.publish("http://127.0.0.1:8084/blend");
System.out.println("Endpoint running");
try {
Thread.sleep(300000);
} catch (InterruptedException ex) {
}
e.stop();
System.out.println("Endpoint stopped");
}
}
This code will publish the web service endpoint on the local machine on port 8084, and will keep it running for 5 minutes. You can run compile and run this testcase easily:
Note that the Endpoint API in Mustang is mainly useful for testing purposes. If you were to publish this for real, you'd probably want to deploy it on one of them application server things the server-side folks like to talk about these days.
Step 6: Run the client application
First fire up the endpoint (Blender Endpoint) using this link (thanks to Romain for hosting the binaries):
Then once the endpoint is running, try running the client app (Blender Client):
Click the button and behold, it should look something like this:
If all goes well, you should see the blended image filling in very, very slowly in the middle of the window. Basically, the app is consulting the Blender web service running on your machine, one pixel and one scanline at a time. Scary, and useless! (By the way, the source code for this application demonstrates a couple other Mustang features, namely SwingWorker and the Desktop integration API, in case you're curious.)
Conclusion
At some point I'd like to go into more detail about my issues with JAX-WS, but I've got a plane to catch! I'll be away for a couple weeks, so hopefully you'll understand if I don't respond to any comments right away. Useful Resources
In my ears: Destroyer, "Destroyer's Rubies"
»
Related Topics >>
Java Desktop Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|