Example usage for java.nio.channels SelectableChannel configureBlocking

List of usage examples for java.nio.channels SelectableChannel configureBlocking

Introduction

In this page you can find the example usage for java.nio.channels SelectableChannel configureBlocking.

Prototype

public abstract SelectableChannel configureBlocking(boolean block) throws IOException;

Source Link

Document

Adjusts this channel's blocking mode.

Usage

From source file:com.buaa.cfs.net.SocketIOWithTimeout.java

SocketIOWithTimeout(SelectableChannel channel, long timeout) throws IOException {
    checkChannelValidity(channel);// ww  w . j  a v  a  2s.c  o  m

    this.channel = channel;
    this.timeout = timeout;
    // Set non-blocking
    channel.configureBlocking(false);
}

From source file:net.sf.cindy.impl.ChannelSession.java

protected void startSession(SelectableChannel readChannel, SelectableChannel writeChannel, boolean block) {
    synchronized (startLock) {
        if (isStarted())
            return;
        try {//from w w w .j  a  v a 2 s. co m
            if (readChannel != null)
                readChannel.configureBlocking(false);
            if (writeChannel != null)
                writeChannel.configureBlocking(false);
        } catch (IOException e) {
            dispatchException(e);
            if (readChannel != null)
                try {
                    readChannel.close();
                } catch (IOException ioe) {
                }
            if (writeChannel != null) {
                try {
                    writeChannel.close();
                } catch (IOException ioe) {
                }
            }
            dispatchSessionClosed();
            return;
        }

        this.readChannel = readChannel;
        this.writeChannel = writeChannel;
        started = true; //Set started
        EventGeneratorSpi generator = (EventGeneratorSpi) getEventGenerator();
        if (!generator.isStarted())
            generator.start();
        generator.register(this, Constants.EV_REGISTER); //If can't started, will close the session, then the started status become false
        if (block && !generator.isEventGeneratorThread())
            try {
                startLock.wait();
            } catch (InterruptedException e) {
            }
    }
}

From source file:org.apache.catalina.cluster.tcp.ReplicationListener.java

/**
 * Register the given channel with the given selector for
 * the given operations of interest//from w  w w .j  a v a2 s .  c  o  m
 */
protected void registerChannel(Selector selector, SelectableChannel channel, int ops, Object attach)
        throws Exception {
    if (channel == null)
        return; // could happen
    // set the new channel non-blocking
    channel.configureBlocking(false);
    // register it with the selector
    channel.register(selector, ops, attach);
}