# Buffering Methods and Callbacks

You can add a buffer to a method of your Web Service control to ensure that your application need not wait for the Web Service control before processing other requests. Calls to a buffered method are queued so that the server is not overwhelmed with requests. This topic describes how buffers aid communication between applications and services, and explains how to add a buffer to a method or callback. It also provides an example of code containing buffers.

## Using Buffers

If you add a message buffer to a Web Service control's method, outgoing messages (invocations of the method) are buffered on the local machine and the method invocation returns void immediately. This prevents your application from having to wait for a response. In other words, your application doesn't have to wait for the network roundtrip to occur.

If you add a message buffer to a Web Service control's callback, incoming messages (invocations of the callback) are buffered on the local machine. The callback invocation returns to the target web service immediately. This prevents the target service from waiting until your application processes the request. Note that since the buffering occurs on your end of the wire, the target service must wait for the network roundtrip even though it will return a void result. But the target service does not have to wait for your application to process the message.

## Adding a Buffer to a Method or Callback

You can add message buffers to the methods and callback handlers of any Service control provided it has a void return type. Remember, though, that a Service control is a proxy for a target web service. The target service is often located on a remote server, so even if you add message buffers to a Web Service control where this is the case, the buffering always occurs on the local server.

To add a buffer to a method or callback handler:

1. If you are not in Design View, click the Design View tab.
2. Select the method or callback handler you want to buffer.
3. In the Property Editor pane, expand the message-buffer property.
4. Set the enabled attribute to true.
   Design View displays the message buffer with a "spring" icon on the method or callback, as shown here:

Note that WebLogic Workshop draws message buffers on the "near" end of the wire. In general, you have no control over the execution environment or configuration of remote web services. In other words, you can't change what happens on the "far" end of the wire.

Adding a message buffer to a method makes the method asynchronous, meaning that callers to that method do not wait for a response.

In the case of a Web Service control, your application is the client when sending outgoing messages (invocations of the method) and the target service is the client when sending incoming messages (control callbacks) to your service.

## How Message Buffers are Specified in Code

Message buffers are specific in code using the @common:message-buffer annotation. In a Web Service control, you can place the @common:message-buffer annotation on a method or a callback.

To learn about the @common:message-buffer annotation, see @common:message-buffer annotation.

The following example contains a @common:message-buffer annotation on a Web Service control method:

    public interface QuoteServiceControl extends ServiceControl
    {
    ...
       /**
         * @common:message-buffer enable="true"
         */
        public void getQuote (int customerID, java.lang.String tickerSymbol);
    ...
    }

The following example contains a @common:message-buffer annotation on a Web Service control callback:

    public interface QuoteServiceControl extends ServiceControl
    {
    ...
        public interface Callback
        {
            /**
             * @common:message-buffer enable="true"
             */
            public void onQuoteReady (java.lang.String tickerSymbol, double dQuote);
        }
    ...
    }

Related Topics

Designing Asynchronous Interfaces

Using Buffering to Create Asynchronous Methods and Callbacks