All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.xml.ws.api.server.AsyncProvider Maven / Gradle / Ivy

There is a newer version: 4.0.3
Show newest version
/*
 * Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0, which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package com.sun.xml.ws.api.server;

import com.sun.istack.NotNull;

import jakarta.xml.ws.Provider;
import jakarta.xml.ws.WebServiceContext;
import java.util.concurrent.Executor;

/**
 * Asynchronous version of {@link Provider}.
 *
 * 

* Applications that use the JAX-WS RI can implement this interface instead of * {@link Provider} to implement asynchronous web services (AWS.) AWS enables * applications to perform operations with long latency without blocking a thread, * and thus particularly suitable for highly scalable service implementation, * at the expesnce of implementation complexity. * *

Programming Model

*

* Whenever a new reuqest arrives, the JAX-WS RI invokes the {@link #invoke} method * to notify the application. Normally, the application then schedules an execution * of this request, and exit from this method immediately (the point of AWS is not * to use this calling thread for request processing.) * *

* Unlike the synchronous version, which requires the response to be given as the return value, * with AWS the JAX-WS RI will keep the connection with client open, until the application * eventually notifies the JAX-WS RI via {@link AsyncProviderCallback}. When that * happens that causes the JAX-WS RI to send back a response to the client. * *

* The following code shows a very simple AWS example: * *

 * @WebService
 * class MyAsyncEchoService implements AsyncProvider<Source> {
 *     private static final {@link Executor} exec = ...;
 *
 *     public void invoke( final Source request, final AsyncProviderCallback<Source> callback, final WebServiceContext context) {
 *         exec.execute(new {@link Runnable}() {
 *             public void run() {
 *                 Thread.sleep(1000);     // kill time.
 *                 callback.send(request); // just echo back
 *             }
 *         });
 *     }
 * }
 * 
* *

* Please also check the {@link Provider} and its programming model for general * provider programming model. * * *

WebServiceContext

*

* In synchronous web services, the injected {@link WebServiceContext} instance uses * the calling {@link Thread} to determine which request it should return information about. * This no longer works with AWS, as you may need to call {@link WebServiceContext} * much later, possibly from entirely different thread. * *

* For this reason, {@link AsyncProvider} passes in {@link WebServiceContext} as * a parameter. This object remains usable until you invoke {@link AsyncProviderCallback}, * and it can be invoked from any thread, even concurrently. AWS must not use the injected * {@link WebServiceContext}, as its behavior is undefined. * * @see Provider * @author Jitendra Kotamraju * @author Kohsuke Kawaguchi * @since 2.1 */ public interface AsyncProvider { /** * Schedules an execution of a request. * * @param request * Represents the request message or payload. * @param callback * Application must notify this callback interface when the processing * of a request is complete. * @param context * The web service context instance that can be used to retrieve * context information about the given request. */ public void invoke( @NotNull T request, @NotNull AsyncProviderCallback callback, @NotNull WebServiceContext context); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy