AbstractSelectableChannel configureBlocking - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AbstractSelectableChannel configureBlocking method.

This code example shows how to use the following methods:register, bind, isOpen, configureBlocking
This code example shows how to use the following methods:socket, isOpen, configureBlocking, isBlocking
        // same 
        assertSame(s1, s2);
    } 
 
    public void testSocket_NonBlock_Closed() throws Exception { 
        this.serverChannel.configureBlocking(false);
        this.serverChannel.close();
        assertFalse(this.serverChannel.isBlocking());
        assertFalse(this.serverChannel.isOpen());
        ServerSocket s1 = this.serverChannel.socket();
        assertTrue(s1.isClosed());
        assertSocketNotAccepted(s1);
        ServerSocket s2 = this.serverChannel.socket();
        // same 
        assertSame(s1, s2);
    } 
 
    private void assertSocketNotAccepted(ServerSocket s) throws IOException {
        assertFalse(s.isBound());
        assertNull(s.getInetAddress());
6
CodeRank
This code example shows how to use the following methods:register, write, configureBlocking
 
	/***/ 
	private void writeToCommonChannel(SelectionKey key, Object message)
			throws IOException { 
		SocketChannel client = (SocketChannel) key.channel();
		client.configureBlocking(false);
		client.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
		ByteBuffer dst = ByteBuffer.allocate(1024);
		dst.put(message.toString().getBytes());
		dst.flip();
		client.write(dst);
	} 
} 
6
CodeRank
This code example shows how to use the following methods:connect, socket, register, configureBlocking
    } 
 
    private void connect() throws IOException, ClosedChannelException { 
         
        channel = DatagramChannel.open();
        channel.configureBlocking(false);
        channel.socket().bind(new InetSocketAddress(data_port));
        channel.connect(new InetSocketAddress(drone_addr, data_port));
 
        selector = Selector.open();
        channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
    } 
 
    private void disconnect() { 
        try { 
            if (selector.isOpen())
                selector.close();
        } catch (IOException iox) 
        { 
            // ignore 
6
CodeRank
This code example shows how to use the following methods:socket, configureBlocking
    ServerSocketChannel ssc;
 
    protected void setUp() throws Exception { 
        super.setUp(); 
        ssc = ServerSocketChannel.open();
        ssc.configureBlocking(false);
        ServerSocket ss = ssc.socket();
        InetSocketAddress address = new InetSocketAddress(PORT);
        ss.bind(address);
        selector = Selector.open();
    } 
 
    protected void tearDown() throws Exception { 
        try { 
            ssc.close();
        } catch (Exception e) {
            // do nothing 
        } 
        try { 
            selector.close();
5
CodeRank
This code example shows how to use the following methods:isConnected, socket, configureBlocking
   * @param socketChannel Already created SocketChannel object 
   * @throws IOException if there is an error setting up the streams 
   */ 
  public TNonblockingSocket(SocketChannel socketChannel) throws IOException {
    this(socketChannel, 0, null);
    if (!socketChannel.isConnected()) throw new IOException("Socket must already be connected");
  } 
 
  private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress)
      throws IOException { 
    socketChannel_ = socketChannel;
    socketAddress_ = socketAddress;
 
    // make it a nonblocking channel 
    socketChannel.configureBlocking(false);
 
    // set options 
    Socket socket = socketChannel.socket();
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);

6
CodeRank
This code example shows how to use the following methods:register, socket, configureBlocking
     
    public Listener() throws IOException { 
      address = new InetSocketAddress(bindAddress, port);
      // Create a new server socket and set to non blocking mode 
      acceptChannel = ServerSocketChannel.open();
      acceptChannel.configureBlocking(false);
 
      // Bind the server socket to the local host and port 
      bind(acceptChannel.socket(), address, backlogLength);
      port = acceptChannel.socket().getLocalPort(); //Could be an ephemeral port
      // create a selector; 
      selector= Selector.open();
 
      // Register accepts on the server socket with the selector. 
      acceptChannel.register(selector, SelectionKey.OP_ACCEPT);
      this.setName("IPC Server listener on " + port);
      this.setDaemon(true);
    } 
    /** cleanup connections from connectionList. Choose a random range 
     * to scan and also have a limit on the number of the connections 
5
CodeRank
This code example shows how to use the following methods:socket, configureBlocking
 
  public TNonblockingServerSocket(InetSocketAddress bindAddr, int clientTimeout) throws TTransportException {
    clientTimeout_ = clientTimeout;
    try { 
      serverSocketChannel = ServerSocketChannel.open();
      serverSocketChannel.configureBlocking(false);
 
      // Make server socket 
      serverSocket_ = serverSocketChannel.socket();
      // Prevent 2MSL delay problem on server restarts 
      serverSocket_.setReuseAddress(true);
      // Bind to listening port 
      serverSocket_.bind(bindAddr);
    } catch (IOException ioe) {
      serverSocket_ = null;
      throw new TTransportException("Could not create ServerSocket on address " + bindAddr.toString() + ".");
    } 
  } 
 
  public void listen() throws TTransportException { 
5
CodeRank
This code example shows how to use the following methods:configureBlocking
ServerSocketChannel serverChannel = (ServerSocketChannel)key.channel();
            SocketChannel client = serverChannel.accept();
            if ( client != null )
            { 
                client.configureBlocking(false);            
                SelectionKeyHandler handler = new HttpConnection();
                SelectorManager.getSelectorManager().register(client, handler, SelectionKey.OP_READ);
            } 
        }  
        catch(IOException e) 
        { 
            logger_.warn(e);
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:register, configureBlocking
this.server = server;
		this.bindEndpoint = bindEndpoint;
 
		socketChannel = ServerSocketChannel.open();
		socketChannel.configureBlocking(false);
 
		acceptSelector = Selector.open();
		socketChannel.register(acceptSelector, SelectionKey.OP_ACCEPT);
 
		keepRunning = true;
	} 
 
	/** 
	 * Runs in a loop, accepting connections and forwarding them to the server 
	 */ 
	@Override 
	public void run() 
	{ 
		try { 
5
CodeRank

Related AbstractSelectableChannel configureBlocking Questions & Answers:

configureBlocking Method Overview
Adjusts this channel's blocking mode.
See Code Examples for other Java 8 AbstractSelectableChannel Methods: