jdk/src/java.httpclient/share/classes/java/net/http/AsyncEvent.java
author michaelm
Sat, 30 Apr 2016 00:30:31 +0100
changeset 37720 45cd7cc65382
parent 36131 379db4b2f95d
child 39730 196f4e25d9f5
permissions -rw-r--r--
8087124: HTTP/2 implementation Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     1
/*
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     4
 *
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    10
 *
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    15
 * accompanied this code).
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    16
 *
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    20
 *
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    23
 */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    24
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    25
package java.net.http;
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    26
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    27
import java.nio.channels.SelectableChannel;
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    28
import java.nio.channels.SelectionKey;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    29
import java.nio.channels.SocketChannel;
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    30
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    31
/**
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    32
 * Event handling interface from HttpClientImpl's selector.
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    33
 *
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    34
 * If BLOCKING is set, then the channel will be put in blocking
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    35
 * mode prior to handle() being called. If false, then it remains non-blocking.
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    36
 *
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    37
 * If REPEATING is set then the event is not cancelled after being posted.
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    38
 */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    39
abstract class AsyncEvent {
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    40
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    41
    public static final int BLOCKING = 0x1; // non blocking if not set
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    42
    public static final int REPEATING = 0x2; // one off event if not set
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    43
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    44
    protected final int flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    45
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    46
    AsyncEvent(int flags) {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    47
        this.flags = flags;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    48
    }
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    49
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    50
    /** Returns the channel */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    51
    public abstract SelectableChannel channel();
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    52
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    53
    /** Returns the selector interest op flags OR'd */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    54
    public abstract int interestOps();
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    55
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    56
    /** Called when event occurs */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    57
    public abstract void handle();
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    58
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    59
    /** Called when selector is shutting down. Abort all exchanges. */
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    60
    public abstract void abort();
37720
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    61
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    62
    public boolean blocking() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    63
        return (flags & BLOCKING) != 0;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    64
    }
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    65
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    66
    public boolean repeating() {
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    67
        return (flags & REPEATING) != 0;
45cd7cc65382 8087124: HTTP/2 implementation
michaelm
parents: 36131
diff changeset
    68
    }
36131
379db4b2f95d 8087112: HTTP API and HTTP/1.1 implementation
michaelm
parents:
diff changeset
    69
}