Example #1
0
  /**
   * Listen for one object and place it on the request queue
   *
   * @throws IOException
   * @throws InterruptedException
   * @throws RadiusException
   */
  public void listen() throws Exception {
    RadiusLog.debug("Listening on socket...");
    Socket socket = serverSocket.accept();

    socket.setTcpNoDelay(false);

    if (keepAlive) {
      KeepAliveListener keepAliveListener = new KeepAliveListener(socket, this, queue);
      keepAliveListener.start();

      synchronized (keepAliveListeners) {
        keepAliveListeners.add(keepAliveListener);
      }
    } else {
      TCPListenerRequest lr = (TCPListenerRequest) requestObjectPool.borrowObject();
      lr.setBorrowedFromPool(requestObjectPool);
      lr.accept(socket, this, false, false);

      while (true) {
        try {
          this.queue.put(lr);
          break;
        } catch (InterruptedException e) {
        }
      }
    }
  }
Example #2
0
  public void setActive(boolean active) {
    this.active = active;
    if (!active) {
      for (KeepAliveListener listener : keepAliveListeners) {
        try {
          listener.shutdown(true);
        } catch (Throwable e) {
        }
      }

      this.keepAliveListeners.clear();

      try {
        this.serverSocket.close();
      } catch (Throwable e) {
      }

      try {
        this.interrupt();
      } catch (Exception e) {
      }
    }
  }