001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api.server;
038:
039: import com.sun.istack.NotNull;
040:
041: import javax.xml.ws.Provider;
042: import javax.xml.ws.WebServiceContext;
043: import java.util.concurrent.Executor;
044:
045: /**
046: * Asynchronous version of {@link Provider}.
047: *
048: * <p>
049: * Applications that use the JAX-WS RI can implement this interface instead of
050: * {@link Provider} to implement asynchronous web services (AWS.) AWS enables
051: * applications to perform operations with long latency without blocking a thread,
052: * and thus particularly suitable for highly scalable service implementation,
053: * at the expesnce of implementation complexity.
054: *
055: * <h2>Programming Model</h2>
056: * <p>
057: * Whenever a new reuqest arrives, the JAX-WS RI invokes the {@link #invoke} method
058: * to notify the application. Normally, the application then schedules an execution
059: * of this request, and exit from this method immediately (the point of AWS is not
060: * to use this calling thread for request processing.)
061: *
062: * <p>
063: * Unlike the synchronous version, which requires the response to be given as the return value,
064: * with AWS the JAX-WS RI will keep the connection with client open, until the application
065: * eventually notifies the JAX-WS RI via {@link AsyncProviderCallback}. When that
066: * happens that causes the JAX-WS RI to send back a response to the client.
067: *
068: * <p>
069: * The following code shows a very simple AWS example:
070: *
071: * <pre>
072: * @WebService
073: * class MyAsyncEchoService implements AsyncProvider<Source> {
074: * private static final {@link Executor} exec = ...;
075: *
076: * public void invoke( final Source request, final AsyncProviderCallback<Source> callback, final WebServiceContext context) {
077: * exec.execute(new {@link Runnable}() {
078: * public void run() {
079: * Thread.sleep(1000); // kill time.
080: * callback.send(request); // just echo back
081: * }
082: * });
083: * }
084: * }
085: * </pre>
086: *
087: * <p>
088: * Please also check the {@link Provider} and its programming model for general
089: * provider programming model.
090: *
091: *
092: * <h2>WebServiceContext</h2>
093: * <p>
094: * In synchronous web services, the injected {@link WebServiceContext} instance uses
095: * the calling {@link Thread} to determine which request it should return information about.
096: * This no longer works with AWS, as you may need to call {@link WebServiceContext}
097: * much later, possibly from entirely different thread.
098: *
099: * <p>
100: * For this reason, {@link AsyncProvider} passes in {@link WebServiceContext} as
101: * a parameter. This object remains usable until you invoke {@link AsyncProviderCallback},
102: * and it can be invoked from any thread, even concurrently. AWS must not use the injected
103: * {@link WebServiceContext}, as its behavior is undefined.
104: *
105: * @see Provider
106: * @author Jitendra Kotamraju
107: * @author Kohsuke Kawaguchi
108: * @since 2.1
109: */
110: public interface AsyncProvider<T> {
111: /**
112: * Schedules an execution of a request.
113: *
114: * @param request
115: * Represents the request message or payload.
116: * @param callback
117: * Application must notify this callback interface when the processing
118: * of a request is complete.
119: * @param context
120: * The web service context instance that can be used to retrieve
121: * context information about the given request.
122: */
123: public void invoke(@NotNull
124: T request, @NotNull
125: AsyncProviderCallback<T> callback, @NotNull
126: WebServiceContext context);
127: }
|