23 */ |
23 */ |
24 |
24 |
25 package java.net.http; |
25 package java.net.http; |
26 |
26 |
27 import java.nio.channels.SelectableChannel; |
27 import java.nio.channels.SelectableChannel; |
|
28 import java.nio.channels.SelectionKey; |
|
29 import java.nio.channels.SocketChannel; |
28 |
30 |
29 /** |
31 /** |
30 * Event handling interface from HttpClientImpl's selector. |
32 * Event handling interface from HttpClientImpl's selector. |
31 * |
33 * |
32 * <p> If blockingChannel is true, then the channel will be put in blocking |
34 * If BLOCKING is set, then the channel will be put in blocking |
33 * mode prior to handle() being called. If false, then it remains non-blocking. |
35 * mode prior to handle() being called. If false, then it remains non-blocking. |
|
36 * |
|
37 * If REPEATING is set then the event is not cancelled after being posted. |
34 */ |
38 */ |
35 abstract class AsyncEvent { |
39 abstract class AsyncEvent { |
36 |
40 |
37 /** |
41 public static final int BLOCKING = 0x1; // non blocking if not set |
38 * Implement this if channel should be made blocking before calling handle() |
42 public static final int REPEATING = 0x2; // one off event if not set |
39 */ |
|
40 public interface Blocking { } |
|
41 |
43 |
42 /** |
44 protected final int flags; |
43 * Implement this if channel should remain non-blocking before calling handle() |
45 |
44 */ |
46 AsyncEvent(int flags) { |
45 public interface NonBlocking { } |
47 this.flags = flags; |
|
48 } |
46 |
49 |
47 /** Returns the channel */ |
50 /** Returns the channel */ |
48 public abstract SelectableChannel channel(); |
51 public abstract SelectableChannel channel(); |
49 |
52 |
50 /** Returns the selector interest op flags OR'd */ |
53 /** Returns the selector interest op flags OR'd */ |
53 /** Called when event occurs */ |
56 /** Called when event occurs */ |
54 public abstract void handle(); |
57 public abstract void handle(); |
55 |
58 |
56 /** Called when selector is shutting down. Abort all exchanges. */ |
59 /** Called when selector is shutting down. Abort all exchanges. */ |
57 public abstract void abort(); |
60 public abstract void abort(); |
|
61 |
|
62 public boolean blocking() { |
|
63 return (flags & BLOCKING) != 0; |
|
64 } |
|
65 |
|
66 public boolean repeating() { |
|
67 return (flags & REPEATING) != 0; |
|
68 } |
58 } |
69 } |