Tabnine Logo
NioReceiver
Code IndexAdd Tabnine to your IDE (free)

How to use
NioReceiver
in
org.apache.catalina.tribes.transport.nio

Best Java code snippets using org.apache.catalina.tribes.transport.nio.NioReceiver (Showing top 20 results out of 315)

origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

/**
 * start cluster receiver
 * @throws Exception
 * @see org.apache.catalina.tribes.ClusterReceiver#start()
 */
public void start() throws IOException {
  super.start();
  try {
    setPool(new RxTaskPool(getMaxThreads(),getMinThreads(),this));
  } catch (Exception x) {
    log.fatal("ThreadPool can initilzed. Listener not started", x);
    if ( x instanceof IOException ) throw (IOException)x;
    else throw new IOException(x.getMessage());
  }
  try {
    getBind();
    bind();
    Thread t = new Thread(this, "NioReceiver");
    t.setDaemon(true);
    t.start();
  } catch (Exception x) {
    log.fatal("Unable to start cluster receiver", x);
    if ( x instanceof IOException ) throw (IOException)x;
    else throw new IOException(x.getMessage());
  }
}

origin: org.apache.geronimo.ext.tomcat/tribes

protected void socketTimeouts() {
  long now = System.currentTimeMillis();
  if ( (now-lastCheck) < getSelectorTimeout() ) return;
  Set<SelectionKey> keys =  (isListening()&&tmpsel!=null)?tmpsel.keys():null;
  if ( keys == null ) return;
  for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
        if ( ka != null ) {
          long delta = now - ka.getLastAccess();
          if (delta > getTimeout() && (!ka.isAccessed())) {
            if (log.isWarnEnabled())
              log.warn("Channel key is registered, but has had no interest ops for the last "+getTimeout()+" ms. (cancelled:"+ka.isCancelled()+"):"+key+" last access:"+new java.sql.Timestamp(ka.getLastAccess())+" Possible cause: all threads used, perform thread dump");
            ka.setLastAccess(now);
          cancelledKey(key);
      cancelledKey(key);
origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

if (doListen()) {
  log.warn("ServerSocketChannel already started");
  return;
setListen(true);
while (doListen() && selector != null) {
    events();
    socketTimeouts();
    int n = selector.select(getTcpSelectorTimeout());
    if (n == 0) {
        ServerSocketChannel server = (ServerSocketChannel) key.channel();
        SocketChannel channel = server.accept();
        channel.socket().setReceiveBufferSize(getRxBufSize());
        channel.socket().setSendBufferSize(getTxBufSize());
        channel.socket().setTcpNoDelay(getTcpNoDelay());
        channel.socket().setKeepAlive(getSoKeepAlive());
        channel.socket().setOOBInline(getOoBInline());
        channel.socket().setReuseAddress(getSoReuseAddress());
        channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
        channel.socket().setTrafficClass(getSoTrafficClass());
        channel.socket().setSoTimeout(getTimeout());
        Object attach = new ObjectReader(channel);
        registerChannel(selector,
                channel,
                SelectionKey.OP_READ,
origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

protected void bind() throws IOException {
  // allocate an unbound server socket channel
  serverChannel = ServerSocketChannel.open();
  // Get the associated ServerSocket to bind it with
  ServerSocket serverSocket = serverChannel.socket();
  // create a new Selector for use below
  selector = Selector.open();
  // set the port the server channel will listen to
  //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
  bind(serverSocket,getTcpListenPort(),getAutoBind());
  // set non-blocking mode for the listening socket
  serverChannel.configureBlocking(false);
  // register the ServerSocketChannel with the Selector
  serverChannel.register(selector, SelectionKey.OP_ACCEPT);
  
}

origin: org.apache.tomcat/tomcat-tribes

protected void bind() throws IOException {
  // allocate an unbound server socket channel
  serverChannel = ServerSocketChannel.open();
  // Get the associated ServerSocket to bind it with
  ServerSocket serverSocket = serverChannel.socket();
  // create a new Selector for use below
  this.selector.set(Selector.open());
  // set the port the server channel will listen to
  //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
  bind(serverSocket,getPort(),getAutoBind());
  // set non-blocking mode for the listening socket
  serverChannel.configureBlocking(false);
  // register the ServerSocketChannel with the Selector
  serverChannel.register(this.selector.get(), SelectionKey.OP_ACCEPT);
  //set up the datagram channel
  if (this.getUdpPort()>0) {
    datagramChannel = DatagramChannel.open();
    configureDatagraChannel();
    //bind to the address to avoid security checks
    bindUdp(datagramChannel.socket(),getUdpPort(),getAutoBind());
  }
}
origin: org.apache.geronimo.ext.tomcat/tribes

if (doListen()) {
  log.warn("ServerSocketChannel already started");
  return;
setListen(true);
  registerChannel(selector,datagramChannel,SelectionKey.OP_READ,oreader);
while (doListen() && selector != null) {
    events();
    socketTimeouts();
    int n = selector.select(getSelectorTimeout());
    if (n == 0) {
        ServerSocketChannel server = (ServerSocketChannel) key.channel();
        SocketChannel channel = server.accept();
        channel.socket().setReceiveBufferSize(getTxBufSize());
        channel.socket().setSendBufferSize(getTxBufSize());
        channel.socket().setTcpNoDelay(getTcpNoDelay());
        channel.socket().setKeepAlive(getSoKeepAlive());
        channel.socket().setOOBInline(getOoBInline());
        channel.socket().setReuseAddress(getSoReuseAddress());
        channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
        channel.socket().setSoTimeout(getTimeout());
        Object attach = new ObjectReader(channel);
        registerChannel(selector,
                channel,
                SelectionKey.OP_READ,
origin: codefollower/Tomcat-Research

/**
 * Sample data handler method for a channel with data ready to read.
 * @param key A SelectionKey object associated with a channel
 *  determined by the selector to be ready for reading.  If the
 *  channel returns an EOF condition, it is closed here, which
 *  automatically invalidates the associated key.  The selector
 *  will then de-register the channel on the next select call.
 */
protected void readDataFromSocket(SelectionKey key) throws Exception {
  NioReplicationTask task = (NioReplicationTask) getTaskPool().getRxTask();
  if (task == null) {
    // No threads/tasks available, do nothing, the selection
    // loop will keep calling this method until a
    // thread becomes available, the thread pool itself has a waiting mechanism
    // so we will not wait here.
    if (log.isDebugEnabled()) log.debug("No TcpReplicationThread available");
  } else {
    // invoking this wakes up the worker thread then returns
    //add task to thread pool
    task.serviceChannel(key);
    getExecutor().execute(task);
  }
}
origin: org.apache.tomcat/tomcat-tribes

  @Override
  public void run() {
    if ( log.isTraceEnabled() )
      log.trace("Cancelling key:"+key);
    NioReceiver.cancelledKey(key);
  }
};
origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

private void cancelKey(final SelectionKey key) {
  if ( log.isTraceEnabled() ) 
    log.trace("Adding key for cancel event:"+key);
  ObjectReader reader = (ObjectReader)key.attachment();
  if ( reader != null ) {
    reader.setCancelled(true);
    reader.finish();
  }
  Runnable cx = new Runnable() {
    public void run() {
      if ( log.isTraceEnabled() ) 
        log.trace("Cancelling key:"+key);
      NioReceiver.cancelledKey(key);
    }
  };
  receiver.addEvent(cx);
}

origin: codefollower/Tomcat-Research

if (doListen()) {
  log.warn(sm.getString("NioReceiver.alreadyStarted"));
  return;
setListen(true);
  registerChannel(selector,datagramChannel,SelectionKey.OP_READ,oreader);
while (doListen() && selector != null) {
    events();
    socketTimeouts();
    int n = selector.select(getSelectorTimeout());
    if (n == 0) {
        ServerSocketChannel server = (ServerSocketChannel) key.channel();
        SocketChannel channel = server.accept();
        channel.socket().setReceiveBufferSize(getTxBufSize());
        channel.socket().setSendBufferSize(getTxBufSize());
        channel.socket().setTcpNoDelay(getTcpNoDelay());
        channel.socket().setKeepAlive(getSoKeepAlive());
        channel.socket().setOOBInline(getOoBInline());
        channel.socket().setReuseAddress(getSoReuseAddress());
        channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
        channel.socket().setSoTimeout(getTimeout());
        Object attach = new ObjectReader(channel);
        registerChannel(selector,
                channel,
                SelectionKey.OP_READ,
origin: codefollower/Tomcat-Research

protected void bind() throws IOException {
  // allocate an unbound server socket channel
  serverChannel = ServerSocketChannel.open();
  // Get the associated ServerSocket to bind it with
  ServerSocket serverSocket = serverChannel.socket();
  // create a new Selector for use below
  synchronized (Selector.class) {
    // Selector.open() isn't thread safe
    // http://bugs.sun.com/view_bug.do?bug_id=6427854
    // Affects 1.6.0_29, fixed in 1.7.0_01
    this.selector.set(Selector.open());
  }
  // set the port the server channel will listen to
  //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
  bind(serverSocket,getPort(),getAutoBind());
  // set non-blocking mode for the listening socket
  serverChannel.configureBlocking(false);
  // register the ServerSocketChannel with the Selector
  serverChannel.register(this.selector.get(), SelectionKey.OP_ACCEPT);
  //set up the datagram channel
  if (this.getUdpPort()>0) {
    datagramChannel = DatagramChannel.open();
    configureDatagraChannel();
    //bind to the address to avoid security checks
    bindUdp(datagramChannel.socket(),getUdpPort(),getAutoBind());
  }
}
origin: org.apache.geronimo.ext.tomcat/tribes

/**
 * Sample data handler method for a channel with data ready to read.
 * @param key A SelectionKey object associated with a channel
 *  determined by the selector to be ready for reading.  If the
 *  channel returns an EOF condition, it is closed here, which
 *  automatically invalidates the associated key.  The selector
 *  will then de-register the channel on the next select call.
 */
protected void readDataFromSocket(SelectionKey key) throws Exception {
  NioReplicationTask task = (NioReplicationTask) getTaskPool().getRxTask();
  if (task == null) {
    // No threads/tasks available, do nothing, the selection
    // loop will keep calling this method until a
    // thread becomes available, the thread pool itself has a waiting mechanism
    // so we will not wait here.
    if (log.isDebugEnabled()) log.debug("No TcpReplicationThread available");
  } else {
    // invoking this wakes up the worker thread then returns
    //add task to thread pool
    task.serviceChannel(key);
    getExecutor().execute(task);
  }
}
origin: codefollower/Tomcat-Research

  @Override
  public void run() {
    if ( log.isTraceEnabled() )
      log.trace("Cancelling key:"+key);
    NioReceiver.cancelledKey(key);
  }
};
origin: org.apache.tomcat/tomcat-tribes

private void cancelKey(final SelectionKey key) {
  if ( log.isTraceEnabled() )
    log.trace("Adding key for cancel event:"+key);
  ObjectReader reader = (ObjectReader)key.attachment();
  if ( reader != null ) {
    reader.setCancelled(true);
    reader.finish();
  }
  Runnable cx = new Runnable() {
    @Override
    public void run() {
      if ( log.isTraceEnabled() )
        log.trace("Cancelling key:"+key);
      NioReceiver.cancelledKey(key);
    }
  };
  receiver.addEvent(cx);
}
origin: org.apache.tomcat/tomcat-tribes

if (doListen()) {
  log.warn(sm.getString("nioReceiver.alreadyStarted"));
  return;
setListen(true);
  registerChannel(selector,datagramChannel,SelectionKey.OP_READ,oreader);
while (doListen() && selector != null) {
    events();
    socketTimeouts();
    int n = selector.select(getSelectorTimeout());
    if (n == 0) {
        ServerSocketChannel server = (ServerSocketChannel) key.channel();
        SocketChannel channel = server.accept();
        channel.socket().setReceiveBufferSize(getRxBufSize());
        channel.socket().setSendBufferSize(getTxBufSize());
        channel.socket().setTcpNoDelay(getTcpNoDelay());
        channel.socket().setKeepAlive(getSoKeepAlive());
        channel.socket().setOOBInline(getOoBInline());
        channel.socket().setReuseAddress(getSoReuseAddress());
        channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
        channel.socket().setSoTimeout(getTimeout());
        Object attach = new ObjectReader(channel);
        registerChannel(selector,
                channel,
                SelectionKey.OP_READ,
origin: org.apache.geronimo.ext.tomcat/tribes

/**
 * start cluster receiver
 * @throws IOException
 * @see org.apache.catalina.tribes.ChannelReceiver#start()
 */
@Override
public void start() throws IOException {
  super.start();
  try {
    setPool(new RxTaskPool(getMaxThreads(),getMinThreads(),this));
  } catch (Exception x) {
    log.fatal("ThreadPool can initilzed. Listener not started", x);
    if ( x instanceof IOException ) throw (IOException)x;
    else throw new IOException(x.getMessage());
  }
  try {
    getBind();
    bind();
    Thread t = new Thread(this, "NioReceiver");
    t.setDaemon(true);
    t.start();
  } catch (Exception x) {
    log.fatal("Unable to start cluster receiver", x);
    if ( x instanceof IOException ) throw (IOException)x;
    else throw new IOException(x.getMessage());
  }
}
origin: org.apache.geronimo.ext.tomcat/tribes

protected void bind() throws IOException {
  // allocate an unbound server socket channel
  serverChannel = ServerSocketChannel.open();
  // Get the associated ServerSocket to bind it with
  ServerSocket serverSocket = serverChannel.socket();
  // create a new Selector for use below
  synchronized (Selector.class) {
    // Selector.open() isn't thread safe
    // http://bugs.sun.com/view_bug.do?bug_id=6427854
    // Affects 1.6.0_29, fixed in 1.7.0_01
    this.selector.set(Selector.open());
  }
  // set the port the server channel will listen to
  //serverSocket.bind(new InetSocketAddress(getBind(), getTcpListenPort()));
  bind(serverSocket,getPort(),getAutoBind());
  // set non-blocking mode for the listening socket
  serverChannel.configureBlocking(false);
  // register the ServerSocketChannel with the Selector
  serverChannel.register(this.selector.get(), SelectionKey.OP_ACCEPT);
  //set up the datagram channel
  if (this.getUdpPort()>0) {
    datagramChannel = DatagramChannel.open();
    configureDatagraChannel();
    //bind to the address to avoid security checks
    bindUdp(datagramChannel.socket(),getUdpPort(),getAutoBind());
  }
}
origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

protected void socketTimeouts() {
  long now = System.currentTimeMillis();
  if ( (now-lastCheck) < getSelectorTimeout() ) return;
  Set keys =  (isListening()&&tmpsel!=null)?tmpsel.keys():null;
  if ( keys == null ) return;
  for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
        if ( ka != null ) {
          long delta = now - ka.getLastAccess();
          if (delta > (long) getTimeout() && (!ka.isAccessed())) {
            log.warn("Channel key is registered, but has had no interest ops for the last "+getTimeout()+" ms. (cancelled:"+ka.isCancelled()+"):"+key+" last access:"+new java.sql.Timestamp(ka.getLastAccess()));
          cancelledKey(key);
      cancelledKey(key);
origin: org.apache.catalina.springsource/com.springsource.org.apache.catalina.tribes.springsource

/**
 * Sample data handler method for a channel with data ready to read.
 * @param key A SelectionKey object associated with a channel
 *  determined by the selector to be ready for reading.  If the
 *  channel returns an EOF condition, it is closed here, which
 *  automatically invalidates the associated key.  The selector
 *  will then de-register the channel on the next select call.
 */
protected void readDataFromSocket(SelectionKey key) throws Exception {
  NioReplicationTask task = (NioReplicationTask) getTaskPool().getRxTask();
  if (task == null) {
    // No threads/tasks available, do nothing, the selection
    // loop will keep calling this method until a
    // thread becomes available, the thread pool itself has a waiting mechanism
    // so we will not wait here.
    if (log.isDebugEnabled()) log.debug("No TcpReplicationThread available");
  } else {
    // invoking this wakes up the worker thread then returns
    //add task to thread pool
    task.serviceChannel(key);
    getExecutor().execute(task);
  }
}
origin: org.apache.geronimo.ext.tomcat/tribes

  @Override
  public void run() {
    if ( log.isTraceEnabled() )
      log.trace("Cancelling key:"+key);
    NioReceiver.cancelledKey(key);
  }
};
org.apache.catalina.tribes.transport.nioNioReceiver

Most used methods

  • addEvent
  • bind
  • cancelledKey
  • doListen
  • events
  • getAutoBind
  • getBind
  • getExecutor
  • getMaxThreads
  • getMinThreads
  • getOoBInline
  • getRxBufSize
  • getOoBInline,
  • getRxBufSize,
  • getSelectorTimeout,
  • getSoKeepAlive,
  • getSoLingerOn,
  • getSoLingerTime,
  • getSoReuseAddress,
  • getSoTrafficClass,
  • getTaskPool,
  • getTcpNoDelay

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getResourceAsStream (ClassLoader)
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now