# Buffer.jws Sample

This topic inludes the source code for the Buffer.jws Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/async/

## Sample Source Code

`01 package async; 02 03 import com.bea.control.JwsContext; 04 05 /** 06 * <p>A web service that demonstrates the @jws:buffer tag to queue high-traffic requests.</p> 07 * 08 * <p>Uses a TimerControl to delay sending a response back to the client, simulating waiting 09 * for a slow back-end service to respond to requests from this web service. The start method 10 * is buffered, in order to accept many requests without blocking.</p> 11 * @common:target-namespace namespace="http://workshop.bea.com/Buffer" 12 */ 13 14 15 public class Buffer implements com.bea.jws.WebService 16 { 17 /** @common:context */ 18 JwsContext context; 19 20 /** 21 * @jc:timer timeout="10 seconds" 22 * @common:control 23 */ 24 private com.bea.control.TimerControl delayTimer; 25 26 /** 27 * <p>the Callback interface is the definition of which messages the client will 28 * accept from us via the callback variable.</p> 29 */ 30 public interface Callback 31 { 32 /** 33 * <p>BufferResult is the message we will send back to the client when the result for 34 * that client is ready.</p> 35 * @jws:conversation phase="finish" 36 */ 37 public void BufferResult(String hello); 38 } 39 40 /** 41 * <p>callback is the variable that represents the client connection. It's used 42 * to enable our methods and events to send messages back to the client.</p> 43 */ 44 public Callback callback; 45 46 /** 47 * <p>Starts the client interaction with Buffer.jws.</p> 48 * 49 * <p>It is difficult to demonstrate using the Test View and a simple web service, but 50 * the @common:message-buffer tag causes WebLogic Server to implement a message queue for 51 * each method that is marked with @common:message-buffer. Requests to this method are then 52 * automatically queued and are fed to the web service as resources allow. This can 53 * vastly increase the load that your web service is able to handle.</p> 54 * 55 * <p>The client sends this, and some time later Buffer replies by calling BufferResult. 56 * Because this is an ongoing transaction, startBufferAsync is marked as a 57 * "conversation start" method. This means the system will track which clients 58 * have called us, and where to send the result for each. This is known as 59 * <i>correlation</i>.</p> 60 * 61 * @common:operation 62 * @jws:conversation phase="start" 63 * @common:message-buffer enable="true" 64 */ 65 public void startBufferAsync() 66 { 67 // all we do here is start the timer. 68 delayTimer.start(); 69 } 70 71 /** 72 * <p>The handler for delayTimer's onTimeout event.</p> 73 * 74 * <p>When the timer expires, this code will be run 75 * to send the result back to the client who asked for it.</p> 76 */ 77 private void delayTimer_onTimeout(long time) 78 { 79 // send the client a hello message. 80 callback.BufferResult("Hello, asynchronous world!"); 81 82 // we don't want any more timer events for this conversation. 83 delayTimer.stop(); 84 85 // this conversation is over, we don't need to remember anything about the client anymore. 86 // finish() is a method of Buffer's superclass, ServiceControl. 87 context.finishConversation(); 88 } 89 90 }`