< prev index next >

src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/Transmitter.java

Print this page

        

*** 38,75 **** * No matter whether the message has been fully sent or an error has occurred, * the transmitter reports the outcome to the supplied handler and becomes ready * to accept a new message. Until then, the transmitter is considered "busy" and * an IllegalStateException will be thrown on each attempt to invoke send. */ ! final class Transmitter { /* This flag is used solely for assertions */ private final AtomicBoolean busy = new AtomicBoolean(); private OutgoingMessage message; private Consumer<Exception> completionHandler; private final RawChannel channel; private final RawChannel.RawEvent event; ! Transmitter(RawChannel channel) { ! this.channel = requireNonNull(channel); this.event = createHandler(); } /** * The supplied handler may be invoked in the calling thread. * A {@code StackOverflowError} may thus occur if there's a possibility * that this method is called again by the supplied handler. */ ! void send(OutgoingMessage message, Consumer<Exception> completionHandler) { requireNonNull(message); requireNonNull(completionHandler); if (!busy.compareAndSet(false, true)) { throw new IllegalStateException(); } send0(message, completionHandler); } private RawChannel.RawEvent createHandler() { return new RawChannel.RawEvent() { @Override public int interestOps() { --- 38,81 ---- * No matter whether the message has been fully sent or an error has occurred, * the transmitter reports the outcome to the supplied handler and becomes ready * to accept a new message. Until then, the transmitter is considered "busy" and * an IllegalStateException will be thrown on each attempt to invoke send. */ ! public class Transmitter { /* This flag is used solely for assertions */ private final AtomicBoolean busy = new AtomicBoolean(); private OutgoingMessage message; private Consumer<Exception> completionHandler; private final RawChannel channel; private final RawChannel.RawEvent event; ! public Transmitter(RawChannel channel) { ! this.channel = channel; this.event = createHandler(); } /** * The supplied handler may be invoked in the calling thread. * A {@code StackOverflowError} may thus occur if there's a possibility * that this method is called again by the supplied handler. */ ! public void send(OutgoingMessage message, ! Consumer<Exception> completionHandler) ! { requireNonNull(message); requireNonNull(completionHandler); if (!busy.compareAndSet(false, true)) { throw new IllegalStateException(); } send0(message, completionHandler); } + public void close() throws IOException { + channel.shutdownOutput(); + } + private RawChannel.RawEvent createHandler() { return new RawChannel.RawEvent() { @Override public int interestOps() {
< prev index next >