< prev index next >

src/java.httpclient/share/classes/java/net/http/HttpClientImpl.java

Print this page
rev 15335 : Async Queues


 137 
 138     private static SSLParameters getDefaultParams(SSLContext ctx) {
 139         SSLParameters params = ctx.getSupportedSSLParameters();
 140         params.setProtocols(new String[]{"TLSv1.2"});
 141         return params;
 142     }
 143 
 144     /**
 145      * Wait for activity on given exchange (assuming blocking = false).
 146      * It's a no-op if blocking = true. In particular, the following occurs
 147      * in the SelectorManager thread.
 148      *
 149      *  1) mark the connection non-blocking
 150      *  2) add to selector
 151      *  3) If selector fires for this exchange then
 152      *  4)   - mark connection as blocking
 153      *  5)   - call AsyncEvent.handle()
 154      *
 155      * If exchange needs to block again, then call registerEvent() again
 156      */
 157     void registerEvent(AsyncEvent exchange) throws IOException {
 158         selmgr.register(exchange);
 159     }
 160 
 161     /**
 162      * Only used from RawChannel to disconnect the channel from
 163      * the selector
 164      */
 165     void cancelRegistration(SocketChannel s) {
 166         selmgr.cancel(s);
 167     }
 168 
 169 
 170     Http2ClientImpl client2() {
 171         return client2;
 172     }
 173 
 174     /**
 175      * We keep one size of buffer on free list. That size may increase
 176      * depending on demand. If that happens we dispose of free buffers
 177      * that are smaller than new size.


 210     }
 211 
 212     // Main loop for this client's selector
 213     private final class SelectorManager extends Thread {
 214 
 215         private final Selector selector;
 216         private volatile boolean closed;
 217         private final List<AsyncEvent> readyList;
 218         private final List<AsyncEvent> registrations;
 219 
 220         SelectorManager() throws IOException {
 221             super(null, null, "SelectorManager", 0, false);
 222             readyList = new ArrayList<>();
 223             registrations = new ArrayList<>();
 224             selector = Selector.open();
 225         }
 226 
 227         // This returns immediately. So caller not allowed to send/receive
 228         // on connection.
 229 
 230         synchronized void register(AsyncEvent e) throws IOException {
 231             registrations.add(e);
 232             selector.wakeup();
 233         }
 234 
 235         synchronized void cancel(SocketChannel e) {
 236             SelectionKey key = e.keyFor(selector);
 237             if (key != null)
 238                 key.cancel();
 239             selector.wakeup();
 240         }
 241 
 242         void wakeupSelector() {
 243             selector.wakeup();
 244         }
 245 
 246         synchronized void shutdown() {
 247             closed = true;
 248             try {
 249                 selector.close();
 250             } catch (IOException ignored) { }




 137 
 138     private static SSLParameters getDefaultParams(SSLContext ctx) {
 139         SSLParameters params = ctx.getSupportedSSLParameters();
 140         params.setProtocols(new String[]{"TLSv1.2"});
 141         return params;
 142     }
 143 
 144     /**
 145      * Wait for activity on given exchange (assuming blocking = false).
 146      * It's a no-op if blocking = true. In particular, the following occurs
 147      * in the SelectorManager thread.
 148      *
 149      *  1) mark the connection non-blocking
 150      *  2) add to selector
 151      *  3) If selector fires for this exchange then
 152      *  4)   - mark connection as blocking
 153      *  5)   - call AsyncEvent.handle()
 154      *
 155      * If exchange needs to block again, then call registerEvent() again
 156      */
 157     void registerEvent(AsyncEvent exchange) {
 158         selmgr.register(exchange);
 159     }
 160 
 161     /**
 162      * Only used from RawChannel to disconnect the channel from
 163      * the selector
 164      */
 165     void cancelRegistration(SocketChannel s) {
 166         selmgr.cancel(s);
 167     }
 168 
 169 
 170     Http2ClientImpl client2() {
 171         return client2;
 172     }
 173 
 174     /**
 175      * We keep one size of buffer on free list. That size may increase
 176      * depending on demand. If that happens we dispose of free buffers
 177      * that are smaller than new size.


 210     }
 211 
 212     // Main loop for this client's selector
 213     private final class SelectorManager extends Thread {
 214 
 215         private final Selector selector;
 216         private volatile boolean closed;
 217         private final List<AsyncEvent> readyList;
 218         private final List<AsyncEvent> registrations;
 219 
 220         SelectorManager() throws IOException {
 221             super(null, null, "SelectorManager", 0, false);
 222             readyList = new ArrayList<>();
 223             registrations = new ArrayList<>();
 224             selector = Selector.open();
 225         }
 226 
 227         // This returns immediately. So caller not allowed to send/receive
 228         // on connection.
 229 
 230         synchronized void register(AsyncEvent e) {
 231             registrations.add(e);
 232             selector.wakeup();
 233         }
 234 
 235         synchronized void cancel(SocketChannel e) {
 236             SelectionKey key = e.keyFor(selector);
 237             if (key != null)
 238                 key.cancel();
 239             selector.wakeup();
 240         }
 241 
 242         void wakeupSelector() {
 243             selector.wakeup();
 244         }
 245 
 246         synchronized void shutdown() {
 247             closed = true;
 248             try {
 249                 selector.close();
 250             } catch (IOException ignored) { }


< prev index next >