src/share/jaxws_classes/com/sun/xml/internal/ws/api/server/AsyncProvider.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.api.server;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29
ohair@286 30 import javax.xml.ws.Provider;
ohair@286 31 import javax.xml.ws.WebServiceContext;
ohair@286 32 import java.util.concurrent.Executor;
ohair@286 33
ohair@286 34 /**
ohair@286 35 * Asynchronous version of {@link Provider}.
ohair@286 36 *
ohair@286 37 * <p>
ohair@286 38 * Applications that use the JAX-WS RI can implement this interface instead of
ohair@286 39 * {@link Provider} to implement asynchronous web services (AWS.) AWS enables
ohair@286 40 * applications to perform operations with long latency without blocking a thread,
ohair@286 41 * and thus particularly suitable for highly scalable service implementation,
ohair@286 42 * at the expesnce of implementation complexity.
ohair@286 43 *
ohair@286 44 * <h2>Programming Model</h2>
ohair@286 45 * <p>
ohair@286 46 * Whenever a new reuqest arrives, the JAX-WS RI invokes the {@link #invoke} method
ohair@286 47 * to notify the application. Normally, the application then schedules an execution
ohair@286 48 * of this request, and exit from this method immediately (the point of AWS is not
ohair@286 49 * to use this calling thread for request processing.)
ohair@286 50 *
ohair@286 51 * <p>
ohair@286 52 * Unlike the synchronous version, which requires the response to be given as the return value,
ohair@286 53 * with AWS the JAX-WS RI will keep the connection with client open, until the application
ohair@286 54 * eventually notifies the JAX-WS RI via {@link AsyncProviderCallback}. When that
ohair@286 55 * happens that causes the JAX-WS RI to send back a response to the client.
ohair@286 56 *
ohair@286 57 * <p>
ohair@286 58 * The following code shows a very simple AWS example:
ohair@286 59 *
ohair@286 60 * <pre>
ohair@286 61 * &#64;WebService
ohair@286 62 * class MyAsyncEchoService implements AsyncProvider&lt;Source> {
ohair@286 63 * private static final {@link Executor} exec = ...;
ohair@286 64 *
ohair@286 65 * public void invoke( final Source request, final AsyncProviderCallback&lt;Source> callback, final WebServiceContext context) {
ohair@286 66 * exec.execute(new {@link Runnable}() {
ohair@286 67 * public void run() {
ohair@286 68 * Thread.sleep(1000); // kill time.
ohair@286 69 * callback.send(request); // just echo back
ohair@286 70 * }
ohair@286 71 * });
ohair@286 72 * }
ohair@286 73 * }
ohair@286 74 * </pre>
ohair@286 75 *
ohair@286 76 * <p>
ohair@286 77 * Please also check the {@link Provider} and its programming model for general
ohair@286 78 * provider programming model.
ohair@286 79 *
ohair@286 80 *
ohair@286 81 * <h2>WebServiceContext</h2>
ohair@286 82 * <p>
ohair@286 83 * In synchronous web services, the injected {@link WebServiceContext} instance uses
ohair@286 84 * the calling {@link Thread} to determine which request it should return information about.
ohair@286 85 * This no longer works with AWS, as you may need to call {@link WebServiceContext}
ohair@286 86 * much later, possibly from entirely different thread.
ohair@286 87 *
ohair@286 88 * <p>
ohair@286 89 * For this reason, {@link AsyncProvider} passes in {@link WebServiceContext} as
ohair@286 90 * a parameter. This object remains usable until you invoke {@link AsyncProviderCallback},
ohair@286 91 * and it can be invoked from any thread, even concurrently. AWS must not use the injected
ohair@286 92 * {@link WebServiceContext}, as its behavior is undefined.
ohair@286 93 *
ohair@286 94 * @see Provider
ohair@286 95 * @author Jitendra Kotamraju
ohair@286 96 * @author Kohsuke Kawaguchi
ohair@286 97 * @since 2.1
ohair@286 98 */
ohair@286 99 public interface AsyncProvider<T> {
ohair@286 100 /**
ohair@286 101 * Schedules an execution of a request.
ohair@286 102 *
ohair@286 103 * @param request
ohair@286 104 * Represents the request message or payload.
ohair@286 105 * @param callback
ohair@286 106 * Application must notify this callback interface when the processing
ohair@286 107 * of a request is complete.
ohair@286 108 * @param context
ohair@286 109 * The web service context instance that can be used to retrieve
ohair@286 110 * context information about the given request.
ohair@286 111 */
ohair@286 112 public void invoke(
ohair@286 113 @NotNull T request,
ohair@286 114 @NotNull AsyncProviderCallback<T> callback,
ohair@286 115 @NotNull WebServiceContext context);
ohair@286 116 }

mercurial