src/share/jaxws_classes/com/sun/xml/internal/ws/api/pipe/NextAction.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.pipe;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.ws.api.message.Packet;
alanb@368 29 import java.util.concurrent.Executor;
ohair@286 30
ohair@286 31 /**
ohair@286 32 * Indicates what shall happen after {@link Tube#processRequest(Packet)} or
ohair@286 33 * {@link Tube#processResponse(Packet)} returns.
ohair@286 34 *
ohair@286 35 * <p>
ohair@286 36 * To allow reuse of this object, this class is mutable.
ohair@286 37 *
ohair@286 38 * @author Kohsuke Kawaguchi
ohair@286 39 */
ohair@286 40 public final class NextAction {
ohair@286 41 int kind;
ohair@286 42 Tube next;
ohair@286 43 Packet packet;
ohair@286 44 /**
ohair@286 45 * Really either {@link RuntimeException} or {@link Error}.
ohair@286 46 */
ohair@286 47 Throwable throwable;
alanb@368 48 Runnable onExitRunnable;
ohair@286 49
ohair@286 50 // public enum Kind { INVOKE, INVOKE_AND_FORGET, RETURN, SUSPEND }
ohair@286 51
ohair@286 52 static final int INVOKE = 0;
ohair@286 53 static final int INVOKE_AND_FORGET = 1;
ohair@286 54 static final int RETURN = 2;
ohair@286 55 static final int THROW = 3;
ohair@286 56 static final int SUSPEND = 4;
ohair@286 57 // Used to abort processResponse chain if a fatal exception is encountered
ohair@286 58 static final int THROW_ABORT_RESPONSE = 5;
ohair@286 59 // Used to abort processResponse chain if a response should be aborted
ohair@286 60 static final int ABORT_RESPONSE = 6;
ohair@286 61 // Used to switch a tubeline from synchronous to asynchronous execution
ohair@286 62 // with respect to the thread that started this tubeline.
ohair@286 63 static final int INVOKE_ASYNC = 7;
ohair@286 64
ohair@286 65 private void set(int k, Tube v, Packet p, Throwable t) {
ohair@286 66 this.kind = k;
ohair@286 67 this.next = v;
ohair@286 68 this.packet = p;
ohair@286 69 this.throwable = t;
ohair@286 70 }
ohair@286 71
ohair@286 72 /**
ohair@286 73 * Indicates that the next action should be to
ohair@286 74 * invoke the next tube's {@link Tube#processRequest(Packet)},
ohair@286 75 * then later invoke the current tube's {@link Tube#processResponse(Packet)}
ohair@286 76 * with the response packet.
ohair@286 77 */
ohair@286 78 public void invoke(Tube next, Packet p) {
ohair@286 79 set(INVOKE, next, p, null);
ohair@286 80 }
ohair@286 81
ohair@286 82 /**
ohair@286 83 * Indicates that the next action should be to
ohair@286 84 * invoke the next tube's {@link Tube#processRequest(Packet)},
ohair@286 85 * but the current tube doesn't want to receive the response packet to
ohair@286 86 * its {@link Tube#processResponse(Packet)}.
ohair@286 87 */
ohair@286 88 public void invokeAndForget(Tube next, Packet p) {
ohair@286 89 set(INVOKE_AND_FORGET, next, p, null);
ohair@286 90 }
ohair@286 91
ohair@286 92 /**
ohair@286 93 * Indicates that the next action is to flip the processing direction
ohair@286 94 * and starts response processing.
ohair@286 95 */
ohair@286 96 public void returnWith( Packet response ) {
ohair@286 97 set(RETURN, null, response, null);
ohair@286 98 }
ohair@286 99
ohair@286 100 /**
ohair@286 101 * Indicates that the next action is to flip the processing direction
alanb@368 102 * and starts exception processing, but with the indicated context.
alanb@368 103 *
alanb@368 104 * @param t
alanb@368 105 * Either {@link RuntimeException} or {@link Error}, but defined to
alanb@368 106 * take {@link Throwable} because {@link Tube#processException(Throwable)}
alanb@368 107 * takes {@link Throwable}.
alanb@368 108 */
alanb@368 109 public void throwException( Packet response, Throwable t ) {
alanb@368 110 // Use of RETURN is correct -- Fiber processing does not set packet for type of THROW
alanb@368 111 set(RETURN, null, response, t);
alanb@368 112 }
alanb@368 113
alanb@368 114 /**
alanb@368 115 * Indicates that the next action is to flip the processing direction
ohair@286 116 * and starts exception processing.
ohair@286 117 *
ohair@286 118 * @param t
ohair@286 119 * Either {@link RuntimeException} or {@link Error}, but defined to
ohair@286 120 * take {@link Throwable} because {@link Tube#processException(Throwable)}
ohair@286 121 * takes {@link Throwable}.
ohair@286 122 */
ohair@286 123 public void throwException(Throwable t) {
ohair@286 124 assert t instanceof RuntimeException || t instanceof Error;
ohair@286 125 set(THROW,null,null,t);
ohair@286 126 }
ohair@286 127
ohair@286 128 /**
ohair@286 129 * Indicates that the next action is to abort the processResponse chain
ohair@286 130 * because of an exception. How that exception is processed is not
ohair@286 131 * defined.
ohair@286 132 *
ohair@286 133 * @param t
ohair@286 134 * Either {@link RuntimeException} or {@link Error}
ohair@286 135 */
ohair@286 136 public void throwExceptionAbortResponse(Throwable t) {
ohair@286 137 set(THROW_ABORT_RESPONSE,null,null,t);
ohair@286 138 }
ohair@286 139
ohair@286 140 /**
ohair@286 141 * Indicates that the next action is to abort the processResponse chain
ohair@286 142 * because of some non-exception condition.
ohair@286 143 *
ohair@286 144 * @param response The response that is being aborted
ohair@286 145 */
ohair@286 146 public void abortResponse(Packet response) {
ohair@286 147 set(ABORT_RESPONSE,null,response,null);
ohair@286 148 }
ohair@286 149
ohair@286 150 /**
ohair@286 151 * Indicates that the next action is to invoke the next tube in the
ohair@286 152 * tubeline async from the thread that started the tubeline. Only fibers
ohair@286 153 * that were started using startSync should use this next action kind.
ohair@286 154 * @param next The next tube in the tubeline
ohair@286 155 * @param p The request to pass to the next tube
ohair@286 156 */
ohair@286 157 public void invokeAsync(Tube next, Packet p) {
ohair@286 158 set(INVOKE_ASYNC,next,p,null);
ohair@286 159 }
ohair@286 160
ohair@286 161 /**
ohair@286 162 * Indicates that the fiber should be suspended.
ohair@286 163 * Once {@link Fiber#resume(Packet) resumed}, return the response processing.
alanb@368 164 * @deprecated Use variants that pass {@link Runnable}
ohair@286 165 */
ohair@286 166 public void suspend() {
alanb@368 167 suspend(null, null);
alanb@368 168 }
alanb@368 169
alanb@368 170 /**
alanb@368 171 * Indicates that the fiber should be suspended. Once the current {@link Thread}
alanb@368 172 * exits the fiber's control loop, the onExitRunnable will be invoked. This {@link Runnable}
alanb@368 173 * may call {@link Fiber#resume(Packet)}; however it is still guaranteed that the current
alanb@368 174 * Thread will return control, therefore, further processing will be handled on a {@link Thread}
alanb@368 175 * from the {@link Executor}. For synchronous cases, the Thread invoking this fiber cannot return
alanb@368 176 * until fiber processing is complete; therefore, the guarantee is only that the onExitRunnable
alanb@368 177 * will be invoked prior to completing the suspension.
alanb@368 178 * @since 2.2.7
alanb@368 179 */
alanb@368 180 public void suspend(Runnable onExitRunnable) {
alanb@368 181 suspend(null, onExitRunnable);
ohair@286 182 }
ohair@286 183
ohair@286 184 /**
ohair@286 185 * Indicates that the fiber should be suspended.
ohair@286 186 * Once {@link Fiber#resume(Packet) resumed}, resume with the
ohair@286 187 * {@link Tube#processRequest(Packet)} on the given next tube.
alanb@368 188 * @deprecated Use variants that pass {@link Runnable}
ohair@286 189 */
ohair@286 190 public void suspend(Tube next) {
alanb@368 191 suspend(next, null);
alanb@368 192 }
alanb@368 193
alanb@368 194 /**
alanb@368 195 * Indicates that the fiber should be suspended. Once the current {@link Thread}
alanb@368 196 * exits the fiber's control loop, the onExitRunnable will be invoked. This {@link Runnable}
alanb@368 197 * may call {@link Fiber#resume(Packet)}; however it is still guaranteed that the current
alanb@368 198 * fiber will return control, therefore, further processing will be handled on a {@link Thread}
alanb@368 199 * from the {@link Executor}. For synchronous cases, the Thread invoking this fiber cannot return
alanb@368 200 * until fiber processing is complete; therefore, the guarantee is only that the onExitRunnable
alanb@368 201 * will be invoked prior to completing the suspension.
alanb@368 202 * <p>
alanb@368 203 * Once {@link Fiber#resume(Packet) resumed}, resume with the
alanb@368 204 * {@link Tube#processRequest(Packet)} on the given next tube.
alanb@368 205 * @since 2.2.7
alanb@368 206 */
alanb@368 207 public void suspend(Tube next, Runnable onExitRunnable) {
ohair@286 208 set(SUSPEND, next, null, null);
alanb@368 209 this.onExitRunnable = onExitRunnable;
ohair@286 210 }
ohair@286 211
ohair@286 212 /** Returns the next tube
ohair@286 213 * @return Next tube
ohair@286 214 */
ohair@286 215 public Tube getNext() {
ohair@286 216 return next;
ohair@286 217 }
ohair@286 218
ohair@286 219 /** Sets the next tube
ohair@286 220 * @param next Next tube
ohair@286 221 */
ohair@286 222 public void setNext(Tube next) {
ohair@286 223 this.next = next;
ohair@286 224 }
ohair@286 225
ohair@286 226 /**
ohair@286 227 * Returns the last Packet
ohair@286 228 * @return Packet
ohair@286 229 */
ohair@286 230 public Packet getPacket() {
ohair@286 231 return packet;
ohair@286 232 }
ohair@286 233
ohair@286 234 /**
ohair@286 235 * Returns the Throwable generated by the last Tube
ohair@286 236 * @return the Throwable
ohair@286 237 */
ohair@286 238 public Throwable getThrowable() {
ohair@286 239 return throwable;
ohair@286 240 }
ohair@286 241
ohair@286 242 /**
ohair@286 243 * Dumps the contents to assist debugging.
ohair@286 244 */
ohair@286 245 @Override
ohair@286 246 public String toString() {
ohair@286 247 StringBuilder buf = new StringBuilder();
ohair@286 248 buf.append(super.toString()).append(" [");
ohair@286 249 buf.append("kind=").append(getKindString()).append(',');
ohair@286 250 buf.append("next=").append(next).append(',');
ohair@286 251 buf.append("packet=").append(packet != null ? packet.toShortString() : null).append(',');
ohair@286 252 buf.append("throwable=").append(throwable).append(']');
ohair@286 253 return buf.toString();
ohair@286 254 }
ohair@286 255
ohair@286 256 /**
ohair@286 257 * Returns {@link #kind} in a human readable string, to assist debugging.
ohair@286 258 */
ohair@286 259 public String getKindString() {
ohair@286 260 switch(kind) {
ohair@286 261 case INVOKE: return "INVOKE";
ohair@286 262 case INVOKE_AND_FORGET: return "INVOKE_AND_FORGET";
ohair@286 263 case RETURN: return "RETURN";
ohair@286 264 case THROW: return "THROW";
ohair@286 265 case SUSPEND: return "SUSPEND";
ohair@286 266 case THROW_ABORT_RESPONSE: return "THROW_ABORT_RESPONSE";
ohair@286 267 case ABORT_RESPONSE: return "ABORT_RESPONSE";
ohair@286 268 case INVOKE_ASYNC: return "INVOKE_ASYNC";
ohair@286 269 default: throw new AssertionError(kind);
ohair@286 270 }
ohair@286 271 }
ohair@286 272 }

mercurial