< prev index next >

src/java.base/share/classes/sun/nio/ch/SelectorImpl.java

Print this page
rev 49242 : [mq]: selector-cleanup

*** 1,7 **** /* ! * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 28,38 **** import java.io.IOException; import java.net.SocketException; import java.nio.channels.ClosedSelectorException; import java.nio.channels.IllegalSelectorException; import java.nio.channels.SelectionKey; - import java.nio.channels.Selector; import java.nio.channels.spi.AbstractSelectableChannel; import java.nio.channels.spi.AbstractSelector; import java.nio.channels.spi.SelectorProvider; import java.util.Collections; import java.util.HashSet; --- 28,37 ----
*** 45,80 **** */ public abstract class SelectorImpl extends AbstractSelector { // The set of keys with data ready for an operation ! protected Set<SelectionKey> selectedKeys; ! ! // The set of keys registered with this Selector ! protected HashSet<SelectionKey> keys; // Public views of the key sets ! private Set<SelectionKey> publicKeys; // Immutable ! private Set<SelectionKey> publicSelectedKeys; // Removal allowed, but not addition protected SelectorImpl(SelectorProvider sp) { super(sp); keys = new HashSet<>(); selectedKeys = new HashSet<>(); publicKeys = Collections.unmodifiableSet(keys); publicSelectedKeys = Util.ungrowableSet(selectedKeys); } ! public Set<SelectionKey> keys() { if (!isOpen()) throw new ClosedSelectorException(); return publicKeys; } ! public Set<SelectionKey> selectedKeys() { if (!isOpen()) throw new ClosedSelectorException(); return publicSelectedKeys; } --- 44,80 ---- */ public abstract class SelectorImpl extends AbstractSelector { + // The set of keys registered with this Selector + protected final HashSet<SelectionKey> keys; // The set of keys with data ready for an operation ! protected final Set<SelectionKey> selectedKeys; // Public views of the key sets ! private final Set<SelectionKey> publicKeys; // Immutable ! private final Set<SelectionKey> publicSelectedKeys; // Removal allowed, but not addition protected SelectorImpl(SelectorProvider sp) { super(sp); keys = new HashSet<>(); selectedKeys = new HashSet<>(); publicKeys = Collections.unmodifiableSet(keys); publicSelectedKeys = Util.ungrowableSet(selectedKeys); } ! @Override ! public final Set<SelectionKey> keys() { if (!isOpen()) throw new ClosedSelectorException(); return publicKeys; } ! @Override ! public final Set<SelectionKey> selectedKeys() { if (!isOpen()) throw new ClosedSelectorException(); return publicSelectedKeys; }
*** 90,116 **** } } } } ! public int select(long timeout) throws IOException { if (timeout < 0) throw new IllegalArgumentException("Negative timeout"); return lockAndDoSelect((timeout == 0) ? -1 : timeout); } ! public int select() throws IOException { return select(0); } ! public int selectNow() throws IOException { return lockAndDoSelect(0); } ! public void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (publicKeys) { synchronized (publicSelectedKeys) { implClose(); --- 90,120 ---- } } } } ! @Override ! public final int select(long timeout) throws IOException { if (timeout < 0) throw new IllegalArgumentException("Negative timeout"); return lockAndDoSelect((timeout == 0) ? -1 : timeout); } ! @Override ! public final int select() throws IOException { return select(0); } ! @Override ! public final int selectNow() throws IOException { return lockAndDoSelect(0); } ! @Override ! public final void implCloseSelector() throws IOException { wakeup(); synchronized (this) { synchronized (publicKeys) { synchronized (publicSelectedKeys) { implClose();
*** 119,130 **** } } protected abstract void implClose() throws IOException; ! public void putEventOps(SelectionKeyImpl sk, int ops) { } protected final SelectionKey register(AbstractSelectableChannel ch, int ops, Object attachment) { if (!(ch instanceof SelChImpl)) --- 123,135 ---- } } protected abstract void implClose() throws IOException; ! public abstract void putEventOps(SelectionKeyImpl sk, int ops); + @Override protected final SelectionKey register(AbstractSelectableChannel ch, int ops, Object attachment) { if (!(ch instanceof SelChImpl))
*** 138,148 **** return k; } protected abstract void implRegister(SelectionKeyImpl ski); ! void processDeregisterQueue() throws IOException { // Precondition: Synchronized on this, keys, and selectedKeys Set<SelectionKey> cks = cancelledKeys(); synchronized (cks) { if (!cks.isEmpty()) { Iterator<SelectionKey> i = cks.iterator(); --- 143,155 ---- return k; } protected abstract void implRegister(SelectionKeyImpl ski); ! protected abstract void implDereg(SelectionKeyImpl ski) throws IOException; ! ! protected final void processDeregisterQueue() throws IOException { // Precondition: Synchronized on this, keys, and selectedKeys Set<SelectionKey> cks = cancelledKeys(); synchronized (cks) { if (!cks.isEmpty()) { Iterator<SelectionKey> i = cks.iterator();
*** 157,167 **** } } } } } - - protected abstract void implDereg(SelectionKeyImpl ski) throws IOException; - - public abstract Selector wakeup(); - } --- 164,169 ----
< prev index next >