1 /* 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4511624 26 * @summary Test Making lots of Selectors 27 * @library .. 28 */ 29 30 import java.io.*; 31 import java.net.*; 32 import java.nio.*; 33 import java.nio.channels.*; 34 import java.util.*; 35 import java.nio.channels.spi.SelectorProvider; 36 37 public class Connect { 38 39 static int success = 0; 40 static int LIMIT = 100; 41 42 public static void main(String[] args) throws Exception { 43 scaleTest(); 44 } 45 46 public static void scaleTest() throws Exception { 47 InetAddress myAddress=InetAddress.getByName(TestUtil.HOST); 48 InetSocketAddress isa = new InetSocketAddress(myAddress,13); 49 50 for (int j=0; j<LIMIT; j++) { 51 SocketChannel sc = SocketChannel.open(); 52 sc.configureBlocking(false); 53 boolean connected = sc.connect(isa); 54 if (!connected) { 55 Selector RSelector = SelectorProvider.provider().openSelector(); 56 SelectionKey RKey = sc.register (RSelector, SelectionKey.OP_CONNECT); 57 while (!connected) { 58 int keysAdded = RSelector.select(100); 59 if (keysAdded > 0) { 60 Set<SelectionKey> readyKeys = RSelector.selectedKeys(); 61 Iterator<SelectionKey> i = readyKeys.iterator(); 62 while (i.hasNext()) { 63 SelectionKey sk = i.next(); 64 SocketChannel nextReady = (SocketChannel)sk.channel(); 65 connected = nextReady.finishConnect(); 66 } 67 readyKeys.clear(); 68 } | 1 /* 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4511624 26 * @summary Test Making lots of Selectors 27 * @library .. 28 */ 29 30 import java.net.*; 31 import java.nio.*; 32 import java.nio.channels.*; 33 import java.nio.channels.spi.SelectorProvider; 34 import java.util.*; 35 36 public class Connect { 37 38 static int success = 0; 39 static int LIMIT = 100; 40 41 public static void main(String[] args) throws Exception { 42 try (TestClass.DayTimeServer daytimeServer 43 = TestClass.DayTimeServer.startNewServer(50)) { 44 scaleTest(daytimeServer); 45 } 46 } 47 48 static void scaleTest(TestClass.DayTimeServer daytimeServer) 49 throws Exception 50 { 51 InetAddress myAddress = daytimeServer.getAddress(); 52 InetSocketAddress isa 53 = new InetSocketAddress(myAddress, daytimeServer.getPort()); 54 55 for (int j=0; j<LIMIT; j++) { 56 SocketChannel sc = SocketChannel.open(); 57 sc.configureBlocking(false); 58 boolean connected = sc.connect(isa); 59 if (!connected) { 60 Selector RSelector = SelectorProvider.provider().openSelector(); 61 SelectionKey RKey = sc.register (RSelector, SelectionKey.OP_CONNECT); 62 while (!connected) { 63 int keysAdded = RSelector.select(100); 64 if (keysAdded > 0) { 65 Set<SelectionKey> readyKeys = RSelector.selectedKeys(); 66 Iterator<SelectionKey> i = readyKeys.iterator(); 67 while (i.hasNext()) { 68 SelectionKey sk = i.next(); 69 SocketChannel nextReady = (SocketChannel)sk.channel(); 70 connected = nextReady.finishConnect(); 71 } 72 readyKeys.clear(); 73 } |