equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 package sun.nio.ch; |
26 package sun.nio.ch; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
29 import java.nio.channels.*; |
|
30 import java.nio.channels.spi.*; |
|
31 import java.net.SocketException; |
29 import java.net.SocketException; |
32 import java.util.*; |
30 import java.nio.channels.ClosedSelectorException; |
|
31 import java.nio.channels.IllegalSelectorException; |
|
32 import java.nio.channels.SelectionKey; |
|
33 import java.nio.channels.Selector; |
|
34 import java.nio.channels.spi.AbstractSelectableChannel; |
|
35 import java.nio.channels.spi.AbstractSelector; |
|
36 import java.nio.channels.spi.SelectorProvider; |
|
37 import java.util.Collections; |
|
38 import java.util.HashSet; |
|
39 import java.util.Iterator; |
|
40 import java.util.Set; |
33 |
41 |
34 |
42 |
35 /** |
43 /** |
36 * Base Selector implementation class. |
44 * Base Selector implementation class. |
37 */ |
45 */ |
52 |
60 |
53 protected SelectorImpl(SelectorProvider sp) { |
61 protected SelectorImpl(SelectorProvider sp) { |
54 super(sp); |
62 super(sp); |
55 keys = new HashSet<>(); |
63 keys = new HashSet<>(); |
56 selectedKeys = new HashSet<>(); |
64 selectedKeys = new HashSet<>(); |
57 if (Util.atBugLevel("1.4")) { |
65 publicKeys = Collections.unmodifiableSet(keys); |
58 publicKeys = keys; |
66 publicSelectedKeys = Util.ungrowableSet(selectedKeys); |
59 publicSelectedKeys = selectedKeys; |
|
60 } else { |
|
61 publicKeys = Collections.unmodifiableSet(keys); |
|
62 publicSelectedKeys = Util.ungrowableSet(selectedKeys); |
|
63 } |
|
64 } |
67 } |
65 |
68 |
66 public Set<SelectionKey> keys() { |
69 public Set<SelectionKey> keys() { |
67 if (!isOpen() && !Util.atBugLevel("1.4")) |
70 if (!isOpen()) |
68 throw new ClosedSelectorException(); |
71 throw new ClosedSelectorException(); |
69 return publicKeys; |
72 return publicKeys; |
70 } |
73 } |
71 |
74 |
72 public Set<SelectionKey> selectedKeys() { |
75 public Set<SelectionKey> selectedKeys() { |
73 if (!isOpen() && !Util.atBugLevel("1.4")) |
76 if (!isOpen()) |
74 throw new ClosedSelectorException(); |
77 throw new ClosedSelectorException(); |
75 return publicSelectedKeys; |
78 return publicSelectedKeys; |
76 } |
79 } |
77 |
80 |
78 protected abstract int doSelect(long timeout) throws IOException; |
81 protected abstract int doSelect(long timeout) throws IOException; |