org.eclipse.jetty.io_8.1.3.v20120522

16:45:23.570 INFO  jd.cli.Main - Decompiling org.eclipse.jetty.io_8.1.3.v20120522.jar
package org.eclipse.jetty.io.bio;

class StringEndPoint$1
  extends IllegalStateException
{
  StringEndPoint$1(StringEndPoint paramStringEndPoint, String x0, Exception paramException)
  {
    super(x0);
    initCause(val$e);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.bio.StringEndPoint.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EndPoint;

public class StreamEndPoint
  implements EndPoint
{
  InputStream _in;
  OutputStream _out;
  int _maxIdleTime;
  boolean _ishut;
  boolean _oshut;
  
  public StreamEndPoint(InputStream in, OutputStream out)
  {
    _in = in;
    _out = out;
  }
  
  public boolean isBlocking()
  {
    return true;
  }
  
  public boolean blockReadable(long millisecs)
    throws IOException
  {
    return true;
  }
  
  public boolean blockWritable(long millisecs)
    throws IOException
  {
    return true;
  }
  
  public boolean isOpen()
  {
    return _in != null;
  }
  
  public final boolean isClosed()
  {
    return !isOpen();
  }
  
  public void shutdownOutput()
    throws IOException
  {
    _oshut = true;
    if ((_ishut) && (_out != null)) {
      _out.close();
    }
  }
  
  public boolean isInputShutdown()
  {
    return _ishut;
  }
  
  public void shutdownInput()
    throws IOException
  {
    _ishut = true;
    if ((_oshut) && (_in != null)) {
      _in.close();
    }
  }
  
  public boolean isOutputShutdown()
  {
    return _oshut;
  }
  
  public void close()
    throws IOException
  {
    if (_in != null) {
      _in.close();
    }
    _in = null;
    if (_out != null) {
      _out.close();
    }
    _out = null;
  }
  
  protected void idleExpired()
    throws IOException
  {
    if (_in != null) {
      _in.close();
    }
  }
  
  public int fill(Buffer buffer)
    throws IOException
  {
    if (_ishut) {
      return -1;
    }
    if (_in == null) {
      return 0;
    }
    int space = buffer.space();
    if (space <= 0)
    {
      if (buffer.hasContent()) {
        return 0;
      }
      throw new IOException("FULL");
    }
    try
    {
      int filled = buffer.readFrom(_in, space);
      if (filled < 0) {
        shutdownInput();
      }
      return filled;
    }
    catch (SocketTimeoutException e)
    {
      idleExpired();
    }
    return -1;
  }
  
  public int flush(Buffer buffer)
    throws IOException
  {
    if (_oshut) {
      return -1;
    }
    if (_out == null) {
      return 0;
    }
    int length = buffer.length();
    if (length > 0) {
      buffer.writeTo(_out);
    }
    if (!buffer.isImmutable()) {
      buffer.clear();
    }
    return length;
  }
  
  public int flush(Buffer header, Buffer buffer, Buffer trailer)
    throws IOException
  {
    int len = 0;
    if (header != null)
    {
      int tw = header.length();
      if (tw > 0)
      {
        int f = flush(header);
        len = f;
        if (f < tw) {
          return len;
        }
      }
    }
    if (buffer != null)
    {
      int tw = buffer.length();
      if (tw > 0)
      {
        int f = flush(buffer);
        if (f < 0) {
          return len > 0 ? len : f;
        }
        len += f;
        if (f < tw) {
          return len;
        }
      }
    }
    if (trailer != null)
    {
      int tw = trailer.length();
      if (tw > 0)
      {
        int f = flush(trailer);
        if (f < 0) {
          return len > 0 ? len : f;
        }
        len += f;
      }
    }
    return len;
  }
  
  public String getLocalAddr()
  {
    return null;
  }
  
  public String getLocalHost()
  {
    return null;
  }
  
  public int getLocalPort()
  {
    return 0;
  }
  
  public String getRemoteAddr()
  {
    return null;
  }
  
  public String getRemoteHost()
  {
    return null;
  }
  
  public int getRemotePort()
  {
    return 0;
  }
  
  public Object getTransport()
  {
    return null;
  }
  
  public InputStream getInputStream()
  {
    return _in;
  }
  
  public void setInputStream(InputStream in)
  {
    _in = in;
  }
  
  public OutputStream getOutputStream()
  {
    return _out;
  }
  
  public void setOutputStream(OutputStream out)
  {
    _out = out;
  }
  
  public void flush()
    throws IOException
  {
    if (_out != null) {
      _out.flush();
    }
  }
  
  public int getMaxIdleTime()
  {
    return _maxIdleTime;
  }
  
  public void setMaxIdleTime(int timeMs)
    throws IOException
  {
    _maxIdleTime = timeMs;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.bio.StreamEndPoint
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.bio;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import javax.net.ssl.SSLSocket;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;

public class SocketEndPoint
  extends StreamEndPoint
{
  private static final Logger LOG = Log.getLogger(SocketEndPoint.class);
  final Socket _socket;
  final InetSocketAddress _local;
  final InetSocketAddress _remote;
  
  public SocketEndPoint(Socket socket)
    throws IOException
  {
    super(socket.getInputStream(), socket.getOutputStream());
    _socket = socket;
    _local = ((InetSocketAddress)_socket.getLocalSocketAddress());
    _remote = ((InetSocketAddress)_socket.getRemoteSocketAddress());
    super.setMaxIdleTime(_socket.getSoTimeout());
  }
  
  protected SocketEndPoint(Socket socket, int maxIdleTime)
    throws IOException
  {
    super(socket.getInputStream(), socket.getOutputStream());
    _socket = socket;
    _local = ((InetSocketAddress)_socket.getLocalSocketAddress());
    _remote = ((InetSocketAddress)_socket.getRemoteSocketAddress());
    _socket.setSoTimeout(maxIdleTime > 0 ? maxIdleTime : 0);
    super.setMaxIdleTime(maxIdleTime);
  }
  
  public boolean isOpen()
  {
    return (super.isOpen()) && (_socket != null) && (!_socket.isClosed());
  }
  
  public boolean isInputShutdown()
  {
    if ((_socket instanceof SSLSocket)) {
      return super.isInputShutdown();
    }
    return (_socket.isClosed()) || (_socket.isInputShutdown());
  }
  
  public boolean isOutputShutdown()
  {
    if ((_socket instanceof SSLSocket)) {
      return super.isOutputShutdown();
    }
    return (_socket.isClosed()) || (_socket.isOutputShutdown());
  }
  
  protected final void shutdownSocketOutput()
    throws IOException
  {
    if (!_socket.isClosed())
    {
      if (!_socket.isOutputShutdown()) {
        _socket.shutdownOutput();
      }
      if (_socket.isInputShutdown()) {
        _socket.close();
      }
    }
  }
  
  public void shutdownOutput()
    throws IOException
  {
    if ((_socket instanceof SSLSocket)) {
      super.shutdownOutput();
    } else {
      shutdownSocketOutput();
    }
  }
  
  public void shutdownSocketInput()
    throws IOException
  {
    if (!_socket.isClosed())
    {
      if (!_socket.isInputShutdown()) {
        _socket.shutdownInput();
      }
      if (_socket.isOutputShutdown()) {
        _socket.close();
      }
    }
  }
  
  public void shutdownInput()
    throws IOException
  {
    if ((_socket instanceof SSLSocket)) {
      super.shutdownInput();
    } else {
      shutdownSocketInput();
    }
  }
  
  public void close()
    throws IOException
  {
    _socket.close();
    _in = null;
    _out = null;
  }
  
  public String getLocalAddr()
  {
    if ((_local == null) || (_local.getAddress() == null) || (_local.getAddress().isAnyLocalAddress())) {
      return "0.0.0.0";
    }
    return _local.getAddress().getHostAddress();
  }
  
  public String getLocalHost()
  {
    if ((_local == null) || (_local.getAddress() == null) || (_local.getAddress().isAnyLocalAddress())) {
      return "0.0.0.0";
    }
    return _local.getAddress().getCanonicalHostName();
  }
  
  public int getLocalPort()
  {
    if (_local == null) {
      return -1;
    }
    return _local.getPort();
  }
  
  public String getRemoteAddr()
  {
    if (_remote == null) {
      return null;
    }
    InetAddress addr = _remote.getAddress();
    return addr == null ? null : addr.getHostAddress();
  }
  
  public String getRemoteHost()
  {
    if (_remote == null) {
      return null;
    }
    return _remote.getAddress().getCanonicalHostName();
  }
  
  public int getRemotePort()
  {
    if (_remote == null) {
      return -1;
    }
    return _remote.getPort();
  }
  
  public Object getTransport()
  {
    return _socket;
  }
  
  public void setMaxIdleTime(int timeMs)
    throws IOException
  {
    if (timeMs != getMaxIdleTime()) {
      _socket.setSoTimeout(timeMs > 0 ? timeMs : 0);
    }
    super.setMaxIdleTime(timeMs);
  }
  
  protected void idleExpired()
    throws IOException
  {
    try
    {
      if (!isInputShutdown()) {
        shutdownInput();
      }
    }
    catch (IOException e)
    {
      LOG.ignore(e);
      _socket.close();
    }
  }
  
  public String toString()
  {
    return _local + " <--> " + _remote;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.bio.SocketEndPoint
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.bio;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class StringEndPoint
  extends StreamEndPoint
{
  String _encoding = "UTF-8";
  ByteArrayInputStream _bin = new ByteArrayInputStream(new byte[0]);
  ByteArrayOutputStream _bout = new ByteArrayOutputStream();
  
  public StringEndPoint()
  {
    super(null, null);
    _in = _bin;
    _out = _bout;
  }
  
  public StringEndPoint(String encoding)
  {
    this();
    if (encoding != null) {
      _encoding = encoding;
    }
  }
  
  public void setInput(String s)
  {
    try
    {
      byte[] bytes = s.getBytes(_encoding);
      _bin = new ByteArrayInputStream(bytes);
      _in = _bin;
      _bout = new ByteArrayOutputStream();
      _out = _bout;
      _ishut = false;
      _oshut = false;
    }
    catch (Exception e)
    {
      throw new IllegalStateException(e.toString());
    }
  }
  
  public String getOutput()
  {
    try
    {
      String s = new String(_bout.toByteArray(), _encoding);
      _bout.reset();
      return s;
    }
    catch (Exception e)
    {
      throw new IllegalStateException(_encoding) {};
    }
  }
  
  public boolean hasMore()
  {
    return _bin.available() > 0;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.bio.StringEndPoint
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.nio;

import java.io.IOException;
import java.net.Socket;
import java.nio.channels.ByteChannel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Timeout.Task;

public class SelectChannelEndPoint
  extends ChannelEndPoint
  implements AsyncEndPoint, ConnectedEndPoint
{
  public static final Logger LOG = Log.getLogger("org.eclipse.jetty.io.nio");
  private final boolean WORK_AROUND_JVM_BUG_6346658 = System.getProperty("os.name").toLowerCase().contains("win");
  private final SelectorManager.SelectSet _selectSet;
  private final SelectorManager _manager;
  private SelectionKey _key;
  private final Runnable _handler = new Runnable()
  {
    public void run()
    {
      handle();
    }
  };
  private int _interestOps;
  private volatile AsyncConnection _connection;
  private boolean _dispatched = false;
  private boolean _asyncDispatch = false;
  private volatile boolean _writable = true;
  private boolean _readBlocked;
  private boolean _writeBlocked;
  private boolean _open;
  private volatile long _idleTimestamp;
  private boolean _ishut;
  
  public SelectChannelEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key, int maxIdleTime)
    throws IOException
  {
    super(channel, maxIdleTime);
    
    _manager = selectSet.getManager();
    _selectSet = selectSet;
    _dispatched = false;
    _asyncDispatch = false;
    _open = true;
    _key = key;
    
    setCheckForIdle(true);
  }
  
  /* Error */
  public SelectionKey getSelectionKey()
  {
    // Byte code:
    //   0: aload_0
    //   1: dup
    //   2: astore_1
    //   3: monitorenter
    //   4: aload_0
    //   5: getfield 374	org/eclipse/jetty/io/nio/SelectChannelEndPoint:_key	Ljava/nio/channels/SelectionKey;
    //   8: aload_1
    //   9: monitorexit
    //   10: areturn
    //   11: astore_2
    //   12: aload_1
    //   13: monitorexit
    //   14: aload_2
    //   15: athrow
    // Line number table:
    //   Java source line #102	-> byte code offset #0
    //   Java source line #104	-> byte code offset #4
    //   Java source line #105	-> byte code offset #11
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	16	0	this	SelectChannelEndPoint
    //   2	11	1	Ljava/lang/Object;	Object
    //   11	4	2	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   4	10	11	finally
    //   11	14	11	finally
  }
  
  public SelectorManager getSelectManager()
  {
    return _manager;
  }
  
  public Connection getConnection()
  {
    return _connection;
  }
  
  public void setConnection(Connection connection)
  {
    Connection old = _connection;
    _connection = ((AsyncConnection)connection);
    if ((old != null) && (old != _connection)) {
      _manager.endPointUpgraded(this, old);
    }
  }
  
  public long getIdleTimestamp()
  {
    return _idleTimestamp;
  }
  
  public void schedule()
  {
    synchronized (this)
    {
      if ((_key == null) || (!_key.isValid()))
      {
        _readBlocked = false;
        _writeBlocked = false;
        notifyAll();
        return;
      }
      if ((_readBlocked) || (_writeBlocked))
      {
        if ((_readBlocked) && (_key.isReadable())) {
          _readBlocked = false;
        }
        if ((_writeBlocked) && (_key.isWritable())) {
          _writeBlocked = false;
        }
        notifyAll();
        
        _key.interestOps(0);
        if (!_dispatched) {
          updateKey();
        }
        return;
      }
      if (((_key.readyOps() & 0x4) == 4) && ((_key.interestOps() & 0x4) == 4))
      {
        _interestOps = (_key.interestOps() & 0xFFFFFFFB);
        _key.interestOps(_interestOps);
        _writable = true;
      }
      if (_dispatched)
      {
        _key.interestOps(0);
      }
      else
      {
        dispatch();
        if ((_dispatched) && (!_selectSet.getManager().isDeferringInterestedOps0())) {
          _key.interestOps(0);
        }
      }
    }
  }
  
  public void asyncDispatch()
  {
    synchronized (this)
    {
      if (_dispatched) {
        _asyncDispatch = true;
      } else {
        dispatch();
      }
    }
  }
  
  public void dispatch()
  {
    synchronized (this)
    {
      if (!_dispatched)
      {
        _dispatched = true;
        boolean dispatched = _manager.dispatch(_handler);
        if (!dispatched)
        {
          _dispatched = false;
          LOG.warn("Dispatched Failed! " + this + " to " + _manager, new Object[0]);
          updateKey();
        }
      }
    }
  }
  
  protected boolean undispatch()
  {
    synchronized (this)
    {
      if (_asyncDispatch)
      {
        _asyncDispatch = false;
        return false;
      }
      _dispatched = false;
      updateKey();
    }
    return true;
  }
  
  public void cancelTimeout(Timeout.Task task)
  {
    getSelectSet().cancelTimeout(task);
  }
  
  public void scheduleTimeout(Timeout.Task task, long timeoutMs)
  {
    getSelectSet().scheduleTimeout(task, timeoutMs);
  }
  
  public void setCheckForIdle(boolean check)
  {
    _idleTimestamp = (check ? System.currentTimeMillis() : 0L);
  }
  
  public boolean isCheckForIdle()
  {
    return _idleTimestamp != 0L;
  }
  
  protected void notIdle()
  {
    if (_idleTimestamp != 0L) {
      _idleTimestamp = System.currentTimeMillis();
    }
  }
  
  public void checkIdleTimestamp(long now)
  {
    long idleTimestamp = _idleTimestamp;
    if ((idleTimestamp != 0L) && (_maxIdleTime > 0))
    {
      long idleForMs = now - idleTimestamp;
      if (idleForMs > _maxIdleTime)
      {
        onIdleExpired(idleForMs);
        _idleTimestamp = now;
      }
    }
  }
  
  public void onIdleExpired(long idleForMs)
  {
    _connection.onIdleExpired(idleForMs);
  }
  
  public int fill(Buffer buffer)
    throws IOException
  {
    int fill = super.fill(buffer);
    if (fill > 0) {
      notIdle();
    }
    return fill;
  }
  
  public int flush(Buffer header, Buffer buffer, Buffer trailer)
    throws IOException
  {
    int l = super.flush(header, buffer, trailer);
    if ((l == 0) && (((header != null) && (header.hasContent())) || ((buffer != null) && (buffer.hasContent())) || ((trailer != null) && (trailer.hasContent()))))
    {
      synchronized (this)
      {
        if (_dispatched) {
          _writable = false;
        }
      }
    }
    else if (l > 0)
    {
      _writable = true;
      notIdle();
    }
    return l;
  }
  
  public int flush(Buffer buffer)
    throws IOException
  {
    int l = super.flush(buffer);
    if ((l == 0) && (buffer != null) && (buffer.hasContent()))
    {
      synchronized (this)
      {
        if (_dispatched) {
          _writable = false;
        }
      }
    }
    else if (l > 0)
    {
      _writable = true;
      notIdle();
    }
    return l;
  }
  
  public boolean blockReadable(long timeoutMs)
    throws IOException
  {
    synchronized (this)
    {
      if (isInputShutdown()) {
        throw new EofException();
      }
      long now = _selectSet.getNow();
      long end = now + timeoutMs;
      boolean check = isCheckForIdle();
      setCheckForIdle(true);
      try
      {
        _readBlocked = true;
        for (; (!isInputShutdown()) && (_readBlocked); return e)
        {
          try
          {
            label50:
            updateKey();
            wait(timeoutMs > 0L ? end - now : 10000L);
          }
          catch (InterruptedException e)
          {
            LOG.warn(e);
          }
          finally
          {
            now = _selectSet.getNow();
          }
          if ((!_readBlocked) || (timeoutMs <= 0L) || (now < end)) {
            break label50;
          }
          e = 0;
          
          _readBlocked = false;
          setCheckForIdle(check);
        }
      }
      finally
      {
        _readBlocked = false;
        setCheckForIdle(check);
      }
    }
    return true;
  }
  
  public boolean blockWritable(long timeoutMs)
    throws IOException
  {
    synchronized (this)
    {
      if (isOutputShutdown()) {
        throw new EofException();
      }
      long now = _selectSet.getNow();
      long end = now + timeoutMs;
      boolean check = isCheckForIdle();
      setCheckForIdle(true);
      try
      {
        _writeBlocked = true;
        for (; (_writeBlocked) && (!isOutputShutdown()); return e)
        {
          try
          {
            label50:
            updateKey();
            wait(timeoutMs > 0L ? end - now : 10000L);
          }
          catch (InterruptedException e)
          {
            LOG.warn(e);
          }
          finally
          {
            now = _selectSet.getNow();
          }
          if ((!_writeBlocked) || (timeoutMs <= 0L) || (now < end)) {
            break label50;
          }
          e = 0;
          
          _writeBlocked = false;
          setCheckForIdle(check);
        }
      }
      finally
      {
        _writeBlocked = false;
        setCheckForIdle(check);
      }
    }
    return true;
  }
  
  public void scheduleWrite()
  {
    if (_writable) {
      LOG.debug("Required scheduleWrite {}", new Object[] { this });
    }
    _writable = false;
    updateKey();
  }
  
  public boolean isWritable()
  {
    return _writable;
  }
  
  public boolean hasProgressed()
  {
    return false;
  }
  
  private void updateKey()
  {
    boolean changed;
    synchronized (this)
    {
      int current_ops = -1;
      if (getChannel().isOpen())
      {
        boolean read_interest = (_readBlocked) || ((!_dispatched) && (!_connection.isSuspended()));
        boolean write_interest = (_writeBlocked) || ((!_dispatched) && (!_writable));
        
        _interestOps = (((!_socket.isInputShutdown()) && (read_interest) ? 1 : 0) | ((!_socket.isOutputShutdown()) && (write_interest) ? 4 : 0));
        try
        {
          current_ops = (_key != null) && (_key.isValid()) ? _key.interestOps() : -1;
        }
        catch (Exception e)
        {
          _key = null;
          LOG.ignore(e);
        }
      }
      changed = _interestOps != current_ops;
    }
    if (changed)
    {
      _selectSet.addChange(this);
      _selectSet.wakeup();
    }
  }
  
  void doUpdateKey()
  {
    synchronized (this)
    {
      if (getChannel().isOpen())
      {
        if (_interestOps > 0)
        {
          if ((_key == null) || (!_key.isValid()))
          {
            SelectableChannel sc = (SelectableChannel)getChannel();
            if (sc.isRegistered()) {
              updateKey();
            } else {
              try
              {
                _key = ((SelectableChannel)getChannel()).register(_selectSet.getSelector(), _interestOps, this);
              }
              catch (Exception e)
              {
                LOG.ignore(e);
                if ((_key != null) && (_key.isValid())) {
                  _key.cancel();
                }
                if (_open) {
                  _selectSet.destroyEndPoint(this);
                }
                _open = false;
                _key = null;
              }
            }
          }
          else
          {
            _key.interestOps(_interestOps);
          }
        }
        else if ((_key != null) && (_key.isValid())) {
          _key.interestOps(0);
        } else {
          _key = null;
        }
      }
      else
      {
        if ((_key != null) && (_key.isValid())) {
          _key.cancel();
        }
        if (_open)
        {
          _open = false;
          _selectSet.destroyEndPoint(this);
        }
        _key = null;
      }
    }
  }
  
  protected void handle()
  {
    boolean dispatched = true;
    try
    {
      while (dispatched) {
        try
        {
          for (;;)
          {
            AsyncConnection next = (AsyncConnection)_connection.handle();
            if (next == _connection) {
              break;
            }
            LOG.debug("{} replaced {}", new Object[] { next, _connection });
            Connection old = _connection;
            _connection = next;
            _manager.endPointUpgraded(this, old);
          }
        }
        catch (ClosedChannelException e)
        {
          LOG.ignore(e);
        }
        catch (EofException e)
        {
          LOG.debug("EOF", e);
          try
          {
            close();
          }
          catch (IOException e2)
          {
            LOG.ignore(e2);
          }
        }
        catch (IOException e)
        {
          LOG.warn(e.toString(), new Object[0]);
          try
          {
            close();
          }
          catch (IOException e2)
          {
            LOG.ignore(e2);
          }
        }
        catch (Throwable e)
        {
          LOG.warn("handle failed", e);
          try
          {
            close();
          }
          catch (IOException e2)
          {
            LOG.ignore(e2);
          }
        }
        finally
        {
          if ((!_ishut) && (isInputShutdown()) && (isOpen()))
          {
            _ishut = true;
            try
            {
              _connection.onInputShutdown();
            }
            catch (Throwable x)
            {
              LOG.warn("onInputShutdown failed", x);
              try
              {
                close();
              }
              catch (IOException e2)
              {
                LOG.ignore(e2);
              }
            }
            finally
            {
              updateKey();
            }
          }
          dispatched = !undispatch();
        }
      }
      return;
    }
    finally
    {
      if (dispatched)
      {
        dispatched = !undispatch();
        while (dispatched)
        {
          LOG.warn("SCEP.run() finally DISPATCHED", new Object[0]);
          dispatched = !undispatch();
        }
      }
    }
  }
  
  public void close()
    throws IOException
  {
    if (WORK_AROUND_JVM_BUG_6346658) {
      try
      {
        SelectionKey key = _key;
        if (key != null) {
          key.cancel();
        }
      }
      catch (Throwable e)
      {
        LOG.ignore(e);
      }
    }
    try
    {
      super.close();
    }
    catch (IOException e)
    {
      LOG.ignore(e);
    }
    finally
    {
      updateKey();
    }
  }
  
  public String toString()
  {
    SelectionKey key = _key;
    String keyString = "";
    if (key != null)
    {
      if (key.isValid())
      {
        if (key.isReadable()) {
          keyString = keyString + "r";
        }
        if (key.isWritable()) {
          keyString = keyString + "w";
        }
      }
      else
      {
        keyString = keyString + "!";
      }
    }
    else {
      keyString = keyString + "-";
    }
    return String.format("SCEP@%x{l(%s)<->r(%s),d=%b,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", new Object[] { Integer.valueOf(hashCode()), _socket.getRemoteSocketAddress(), _socket.getLocalSocketAddress(), Boolean.valueOf(_dispatched), Boolean.valueOf(isOpen()), Boolean.valueOf(isInputShutdown()), Boolean.valueOf(isOutputShutdown()), Boolean.valueOf(_readBlocked), Boolean.valueOf(_writeBlocked), Boolean.valueOf(_writable), Integer.valueOf(_interestOps), keyString, _connection });
  }
  
  public SelectorManager.SelectSet getSelectSet()
  {
    return _selectSet;
  }
  
  public void setMaxIdleTime(int timeMs)
    throws IOException
  {
    _maxIdleTime = timeMs;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.nio.SelectChannelEndPoint
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.nio;

import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteArrayBuffer;

public class IndirectNIOBuffer
  extends ByteArrayBuffer
  implements NIOBuffer
{
  protected final ByteBuffer _buf;
  
  public IndirectNIOBuffer(int size)
  {
    super(size, 2, false);
    _buf = ByteBuffer.wrap(_bytes);
    _buf.position(0);
    _buf.limit(_buf.capacity());
  }
  
  public IndirectNIOBuffer(ByteBuffer buffer, boolean immutable)
  {
    super(buffer.array(), 0, 0, immutable ? 0 : 2, false);
    if (buffer.isDirect()) {
      throw new IllegalArgumentException();
    }
    _buf = buffer;
    _get = buffer.position();
    _put = buffer.limit();
    buffer.position(0);
    buffer.limit(buffer.capacity());
  }
  
  public ByteBuffer getByteBuffer()
  {
    return _buf;
  }
  
  public boolean isDirect()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.nio.IndirectNIOBuffer
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.nio;

abstract interface SelectorManager$ChangeTask
  extends Runnable
{}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.nio.SelectorManager.ChangeTask
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jetty.io.nio;

import java.io.IOException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Timeout;
import org.eclipse.jetty.util.thread.Timeout.Task;

public class SelectorManager$SelectSet
  implements Dumpable
{
  private final int _setID;
  private final Timeout _timeout;
  private final ConcurrentLinkedQueue<Object> _changes = new ConcurrentLinkedQueue();
  private volatile Selector _selector;
  private volatile Thread _selecting;
  private int _busySelects;
  private long _monitorNext;
  private boolean _pausing;
  private boolean _paused;
  private volatile long _idleTick;
  private ConcurrentMap<SelectChannelEndPoint, Object> _endPoints = new ConcurrentHashMap();
  
  SelectorManager$SelectSet(SelectorManager paramSelectorManager, int acceptorID)
    throws Exception
  {
    _setID = acceptorID;
    
    _idleTick = System.currentTimeMillis();
    _timeout = new Timeout(this);
    _timeout.setDuration(0L);
    
    _selector = Selector.open();
    _monitorNext = (System.currentTimeMillis() + SelectorManager.access$100());
  }
  
  public void addChange(Object change)
  {
    _changes.add(change);
  }
  
  public void addChange(SelectableChannel channel, Object att)
  {
    if (att == null) {
      addChange(channel);
    } else if ((att instanceof EndPoint)) {
      addChange(att);
    } else {
      addChange(new SelectorManager.ChannelAndAttachment(channel, att));
    }
  }
  
  public void doSelect()
    throws IOException
  {
    try
    {
      _selecting = Thread.currentThread();
      Selector selector = _selector;
      if (selector == null) {
        return;
      }
      int changes = _changes.size();
      Object change;
      while ((changes-- > 0) && ((change = _changes.poll()) != null))
      {
        Channel ch = null;
        SelectionKey key = null;
        try
        {
          if ((change instanceof EndPoint))
          {
            SelectChannelEndPoint endpoint = (SelectChannelEndPoint)change;
            ch = endpoint.getChannel();
            endpoint.doUpdateKey();
          }
          else if ((change instanceof SelectorManager.ChannelAndAttachment))
          {
            SelectorManager.ChannelAndAttachment asc = (SelectorManager.ChannelAndAttachment)change;
            SelectableChannel channel = _channel;
            ch = channel;
            Object att = _attachment;
            if (((channel instanceof SocketChannel)) && (((SocketChannel)channel).isConnected()))
            {
              key = channel.register(selector, 1, att);
              SelectChannelEndPoint endpoint = createEndPoint((SocketChannel)channel, key);
              key.attach(endpoint);
              endpoint.schedule();
            }
            else if (channel.isOpen())
            {
              key = channel.register(selector, 8, att);
            }
          }
          else if ((change instanceof SocketChannel))
          {
            SocketChannel channel = (SocketChannel)change;
            ch = channel;
            key = channel.register(selector, 1, null);
            SelectChannelEndPoint endpoint = createEndPoint(channel, key);
            key.attach(endpoint);
            endpoint.schedule();
          }
          else if ((change instanceof SelectorManager.ChangeTask))
          {
            ((Runnable)change).run();
          }
          else if ((change instanceof Runnable))
          {
            this$0.dispatch((Runnable)change);
          }
          else
          {
            throw new IllegalArgumentException(change.toString());
          }
        }
        catch (CancelledKeyException e)
        {
          SelectorManager.LOG.ignore(e);
        }
        catch (Throwable e)
        {
          if (this$0.isRunning()) {
            SelectorManager.LOG.warn(e);
          } else {
            SelectorManager.LOG.debug(e);
          }
          try
          {
            if (ch != null) {
              ch.close();
            }
          }
          catch (IOException e2)
          {
            SelectorManager.LOG.debug(e2);
          }
        }
      }
      int selected = selector.selectNow();
      
      long now = System.currentTimeMillis();
      if ((selected == 0) && (selector.selectedKeys().isEmpty()))
      {
        if (_pausing)
        {
          try
          {
            Thread.sleep(SelectorManager.access$200());
          }
          catch (InterruptedException e)
          {
            SelectorManager.LOG.ignore(e);
          }
          now = System.currentTimeMillis();
        }
        _timeout.setNow(now);
        long to_next_timeout = _timeout.getTimeToNext();
        
        long wait = _changes.size() == 0 ? SelectorManager.access$300() : 0L;
        if ((wait > 0L) && (to_next_timeout >= 0L) && (wait > to_next_timeout)) {
          wait = to_next_timeout;
        }
        if (wait > 0L)
        {
          long before = now;
          selected = selector.select(wait);
          now = System.currentTimeMillis();
          _timeout.setNow(now);
          if ((SelectorManager.access$100() > 0) && (now - before <= 1L)) {
            if (++_busySelects > SelectorManager.access$400())
            {
              _pausing = true;
              if (!_paused)
              {
                _paused = true;
                SelectorManager.LOG.warn("Selector {} is too busy, pausing!", new Object[] { this });
              }
            }
          }
        }
      }
      if ((_selector == null) || (!selector.isOpen())) {
        return;
      }
      for (SelectionKey key : selector.selectedKeys())
      {
        SocketChannel channel = null;
        try
        {
          if (!key.isValid())
          {
            key.cancel();
            SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment();
            if (endpoint != null) {
              endpoint.doUpdateKey();
            }
          }
          else
          {
            Object att = key.attachment();
            if ((att instanceof SelectChannelEndPoint))
            {
              if ((key.isReadable()) || (key.isWritable())) {
                ((SelectChannelEndPoint)att).schedule();
              }
            }
            else if (key.isConnectable())
            {
              channel = (SocketChannel)key.channel();
              boolean connected = false;
              try
              {
                connected = channel.finishConnect();
              }
              catch (Exception e)
              {
                SelectChannelEndPoint endpoint;
                this$0.connectionFailed(channel, e, att);
              }
              finally
              {
                SelectChannelEndPoint endpoint;
                if (connected)
                {
                  key.interestOps(1);
                  SelectChannelEndPoint endpoint = createEndPoint(channel, key);
                  key.attach(endpoint);
                  endpoint.schedule();
                }
                else
                {
                  key.cancel();
                }
              }
            }
            else
            {
              channel = (SocketChannel)key.channel();
              SelectChannelEndPoint endpoint = createEndPoint(channel, key);
              key.attach(endpoint);
              if (key.isReadable()) {
                endpoint.schedule();
              }
            }
            key = null;
          }
        }
        catch (CancelledKeyException e)
        {
          SelectorManager.LOG.ignore(e);
        }
        catch (Exception e)
        {
          if (this$0.isRunning()) {
            SelectorManager.LOG.warn(e);
          } else {
            SelectorManager.LOG.ignore(e);
          }
          try
          {
            if (channel != null) {
              channel.close();
            }
          }
          catch (IOException e2)
          {
            SelectorManager.LOG.debug(e2);
          }
          if ((key != null) && (!(key.channel() instanceof ServerSocketChannel)) && (key.isValid())) {
            key.cancel();
          }
        }
      }
      selector.selectedKeys().clear();
      
      now = System.currentTimeMillis();
      _timeout.setNow(now);
      Timeout.Task task = _timeout.expired();
      while (task != null)
      {
        if ((task instanceof Runnable)) {
          this$0.dispatch((Runnable)task);
        }
        task = _timeout.expired();
      }
      if (now - _idleTick > SelectorManager.access$300())
      {
        _idleTick = now;
        
        final long idle_now = (SelectorManager.access$500(this$0) > 0L) && (selector.keys().size() > SelectorManager.access$500(this$0)) ? now + SelectorManager.access$600(this$0) - SelectorManager.access$700(this$0) : now;
        
        this$0.dispatch(new Runnable()
        {
          public void run()
          {
            for (SelectChannelEndPoint endp : _endPoints.keySet()) {
              endp.checkIdleTimestamp(idle_now);
            }
          }
          
          public String toString()
          {
            return "Idle-" + super.toString();
          }
        });
      }
      if ((SelectorManager.access$100() > 0) && (now > _monitorNext))
      {
        _busySelects = 0;
        _pausing = false;
        _monitorNext = (now + SelectorManager.access$100());
      }
    }
    catch (ClosedSelectorException e)
    {
      if (this$0.isRunning()) {
        SelectorManager.LOG.warn(e);
      } else {
        SelectorManager.LOG.ignore(e);
      }
    }
    catch (CancelledKeyException e)
    {
      SelectorManager.LOG.ignore(e);
    }
    finally
    {
      _selecting = null;
    }
  }
  
  private void renewSelector()
  {
    try
    {
      synchronized (this)
      {
        Selector selector = _selector;
        if (selector == null) {
          return;
        }
        Selector new_selector = Selector.open();
        for (SelectionKey k : selector.keys()) {
          if ((k.isValid()) && (k.interestOps() != 0))
          {
            SelectableChannel channel = k.channel();
            Object attachment = k.attachment();
            if (attachment == null) {
              addChange(channel);
            } else {
              addChange(channel, attachment);
            }
          }
        }
        _selector.close();
        _selector = new_selector;
      }
    }
    catch (IOException e)
    {
      throw new RuntimeException("recreating selector", e);
    }
  }
  
  public SelectorManager getManager()
  {
    return this$0;
  }
  
  public long getNow()
  {
    return _timeout.getNow();
  }
  
  public void scheduleTimeout(Timeout.Task task, long timeoutMs)
  {
    if (!(task instanceof Runnable)) {
      throw new IllegalArgumentException("!Runnable");
    }
    _timeout.schedule(task, timeoutMs);
  }
  
  public void cancelTimeout(Timeout.Task task)
  {
    task.cancel();
  }
  
  public void wakeup()
  {
    try
    {
      Selector selector = _selector;
      if (selector != null) {
        selector.wakeup();
      }
    }
    catch (Exception e)
    {
      addChange(new SelectorManager.ChangeTask()
      {
        public void run()
        {
          Sel
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd