jetty-io-8.1.0.v20120127

16:37:31.687 INFO  jd.cli.Main - Decompiling jetty-io-8.1.0.v20120127.jar
package org.eclipse.jetty.io;

import java.io.IOException;

public class ByteArrayEndPoint
  implements ConnectedEndPoint
{
  protected byte[] _inBytes;
  protected ByteArrayBuffer _in;
  protected ByteArrayBuffer _out;
  protected boolean _closed;
  protected boolean _nonBlocking;
  protected boolean _growOutput;
  protected Connection _connection;
  protected int _maxIdleTime;
  
  public ByteArrayEndPoint() {}
  
  public Connection getConnection()
  {
    return _connection;
  }
  
  public void setConnection(Connection connection)
  {
    _connection = connection;
  }
  
  public boolean isNonBlocking()
  {
    return _nonBlocking;
  }
  
  public void setNonBlocking(boolean nonBlocking)
  {
    _nonBlocking = nonBlocking;
  }
  
  public ByteArrayEndPoint(byte[] input, int outputSize)
  {
    _inBytes = input;
    _in = new ByteArrayBuffer(input);
    _out = new ByteArrayBuffer(outputSize);
  }
  
  public ByteArrayBuffer getIn()
  {
    return _in;
  }
  
  public void setIn(ByteArrayBuffer in)
  {
    _in = in;
  }
  
  public ByteArrayBuffer getOut()
  {
    return _out;
  }
  
  public void setOut(ByteArrayBuffer out)
  {
    _out = out;
  }
  
  public boolean isOpen()
  {
    return !_closed;
  }
  
  public boolean isInputShutdown()
  {
    return _closed;
  }
  
  public boolean isOutputShutdown()
  {
    return _closed;
  }
  
  public boolean isBlocking()
  {
    return !_nonBlocking;
  }
  
  public boolean blockReadable(long millisecs)
  {
    return true;
  }
  
  public boolean blockWritable(long millisecs)
  {
    return true;
  }
  
  public void shutdownOutput()
    throws IOException
  {
    close();
  }
  
  public void shutdownInput()
    throws IOException
  {
    close();
  }
  
  public void close()
    throws IOException
  {
    _closed = true;
  }
  
  public int fill(Buffer buffer)
    throws IOException
  {
    if (_closed) {
      throw new IOException("CLOSED");
    }
    if ((_in != null) && (_in.length() > 0))
    {
      int len = buffer.put(_in);
      _in.skip(len);
      return len;
    }
    if ((_in != null) && (_in.length() == 0) && (_nonBlocking)) {
      return 0;
    }
    close();
    return -1;
  }
  
  public int flush(Buffer buffer)
    throws IOException
  {
    if (_closed) {
      throw new IOException("CLOSED");
    }
    if ((_growOutput) && (buffer.length() > _out.space()))
    {
      _out.compact();
      if (buffer.length() > _out.space())
      {
        ByteArrayBuffer n = new ByteArrayBuffer(_out.putIndex() + buffer.length());
        
        n.put(_out.peek(0, _out.putIndex()));
        if (_out.getIndex() > 0)
        {
          n.mark();
          n.setGetIndex(_out.getIndex());
        }
        _out = n;
      }
    }
    int len = _out.put(buffer);
    buffer.skip(len);
    return len;
  }
  
  public int flush(Buffer header, Buffer buffer, Buffer trailer)
    throws IOException
  {
    if (_closed) {
      throw new IOException("CLOSED");
    }
    int flushed = 0;
    if ((header != null) && (header.length() > 0)) {
      flushed = flush(header);
    }
    if ((header == null) || (header.length() == 0))
    {
      if ((buffer != null) && (buffer.length() > 0)) {
        flushed += flush(buffer);
      }
      if ((buffer == null) || (buffer.length() == 0)) {
        if ((trailer != null) && (trailer.length() > 0)) {
          flushed += flush(trailer);
        }
      }
    }
    return flushed;
  }
  
  public void reset()
  {
    _closed = false;
    _in.clear();
    _out.clear();
    if (_inBytes != null) {
      _in.setPutIndex(_inBytes.length);
    }
  }
  
  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 _inBytes;
  }
  
  public void flush()
    throws IOException
  {}
  
  public boolean isGrowOutput()
  {
    return _growOutput;
  }
  
  public void setGrowOutput(boolean growOutput)
  {
    _growOutput = growOutput;
  }
  
  public int getMaxIdleTime()
  {
    return _maxIdleTime;
  }
  
  public void setMaxIdleTime(int timeMs)
    throws IOException
  {
    _maxIdleTime = timeMs;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.ByteArrayEndPoint
 * 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.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import org.eclipse.jetty.io.AbstractBuffer;
import org.eclipse.jetty.io.Buffer;

public class RandomAccessFileBuffer
  extends AbstractBuffer
  implements Buffer
{
  final RandomAccessFile _file;
  final FileChannel _channel;
  final int _capacity;
  
  public RandomAccessFileBuffer(File file)
    throws FileNotFoundException
  {
    super(2, true);
    assert (file.length() <= 2147483647L);
    _file = new RandomAccessFile(file, "rw");
    _channel = _file.getChannel();
    _capacity = Integer.MAX_VALUE;
    setGetIndex(0);
    setPutIndex((int)file.length());
  }
  
  public RandomAccessFileBuffer(File file, int capacity)
    throws FileNotFoundException
  {
    super(2, true);
    assert (capacity >= file.length());
    assert (file.length() <= 2147483647L);
    _capacity = capacity;
    _file = new RandomAccessFile(file, "rw");
    _channel = _file.getChannel();
    setGetIndex(0);
    setPutIndex((int)file.length());
  }
  
  public RandomAccessFileBuffer(File file, int capacity, int access)
    throws FileNotFoundException
  {
    super(access, true);
    assert (capacity >= file.length());
    assert (file.length() <= 2147483647L);
    _capacity = capacity;
    _file = new RandomAccessFile(file, access == 2 ? "rw" : "r");
    _channel = _file.getChannel();
    setGetIndex(0);
    setPutIndex((int)file.length());
  }
  
  public byte[] array()
  {
    return null;
  }
  
  public int capacity()
  {
    return _capacity;
  }
  
  public void clear()
  {
    try
    {
      synchronized (_file)
      {
        super.clear();
        _file.setLength(0L);
      }
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
  
  public byte peek()
  {
    synchronized (_file)
    {
      try
      {
        if (_get != _file.getFilePointer()) {
          _file.seek(_get);
        }
        return _file.readByte();
      }
      catch (Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  }
  
  public byte peek(int index)
  {
    synchronized (_file)
    {
      try
      {
        _file.seek(index);
        return _file.readByte();
      }
      catch (Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  }
  
  public int peek(int index, byte[] b, int offset, int length)
  {
    synchronized (_file)
    {
      try
      {
        _file.seek(index);
        return _file.read(b, offset, length);
      }
      catch (Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  }
  
  public void poke(int index, byte b)
  {
    synchronized (_file)
    {
      try
      {
        _file.seek(index);
        _file.writeByte(b);
      }
      catch (Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  }
  
  public int poke(int index, byte[] b, int offset, int length)
  {
    synchronized (_file)
    {
      try
      {
        _file.seek(index);
        _file.write(b, offset, length);
        return length;
      }
      catch (Exception e)
      {
        throw new RuntimeException(e);
      }
    }
  }
  
  /* Error */
  public int writeTo(java.nio.channels.WritableByteChannel channel, int index, int length)
    throws java.io.IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 11	org/eclipse/jetty/io/nio/RandomAccessFileBuffer:_file	Ljava/io/RandomAccessFile;
    //   4: dup
    //   5: astore 4
    //   7: monitorenter
    //   8: aload_0
    //   9: getfield 13	org/eclipse/jetty/io/nio/RandomAccessFileBuffer:_channel	Ljava/nio/channels/FileChannel;
    //   12: iload_2
    //   13: i2l
    //   14: iload_3
    //   15: i2l
    //   16: aload_1
    //   17: invokevirtual 31	java/nio/channels/FileChannel:transferTo	(JJLjava/nio/channels/WritableByteChannel;)J
    //   20: l2i
    //   21: aload 4
    //   23: monitorexit
    //   24: ireturn
    //   25: astore 5
    //   27: aload 4
    //   29: monitorexit
    //   30: aload 5
    //   32: athrow
    // Line number table:
    //   Java source line #184	-> byte code offset #0
    //   Java source line #186	-> byte code offset #8
    //   Java source line #187	-> byte code offset #25
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	33	0	this	RandomAccessFileBuffer
    //   0	33	1	channel	java.nio.channels.WritableByteChannel
    //   0	33	2	index	int
    //   0	33	3	length	int
    //   5	23	4	Ljava/lang/Object;	Object
    //   25	6	5	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   8	24	25	finally
    //   25	30	25	finally
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jetty.io.nio.RandomAccessFileBuffer
 * 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.AsyncEndPoint;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.AggregateLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Timeout;
import org.eclipse.jetty.util.thread.Timeout.Task;

public abstract class SelectorManager
  extends AbstractLifeCycle
  implements Dumpable
{
  public static final Logger LOG = Log.getLogger("org.eclipse.jetty.io.nio");
  private static final int __MONITOR_PERIOD = Integer.getInteger("org.eclipse.jetty.io.nio.MONITOR_PERIOD", 1000).intValue();
  private static final int __MAX_SELECTS = Integer.getInteger("org.eclipse.jetty.io.nio.MAX_SELECTS", 100000).intValue();
  private static final int __BUSY_PAUSE = Integer.getInteger("org.eclipse.jetty.io.nio.BUSY_PAUSE", 50).intValue();
  private static final int __IDLE_TICK = Integer.getInteger("org.eclipse.jetty.io.nio.IDLE_TICK", 400).intValue();
  private int _maxIdleTime;
  private int _lowResourcesMaxIdleTime;
  private long _lowResourcesConnections;
  private SelectSet[] _selectSet;
  private int _selectSets;
  private volatile int _set;
  private boolean _deferringInterestedOps0;
  private int _selectorPriorityDelta;
  
  public SelectorManager()
  {
    _selectSets = 1;
    _set = 0;
    _deferringInterestedOps0 = true;
    _selectorPriorityDelta = 0;
  }
  
  public void setMaxIdleTime(long maxIdleTime)
  {
    _maxIdleTime = ((int)maxIdleTime);
  }
  
  public void setSelectSets(int selectSets)
  {
    long lrc = _lowResourcesConnections * _selectSets;
    _selectSets = selectSets;
    _lowResourcesConnections = (lrc / _selectSets);
  }
  
  public long getMaxIdleTime()
  {
    return _maxIdleTime;
  }
  
  public int getSelectSets()
  {
    return _selectSets;
  }
  
  public SelectSet getSelectSet(int i)
  {
    return _selectSet[i];
  }
  
  public void register(SocketChannel channel, Object att)
  {
    int s = _set++;
    if (s < 0) {
      s = -s;
    }
    s %= _selectSets;
    SelectSet[] sets = _selectSet;
    if (sets != null)
    {
      SelectSet set = sets[s];
      set.addChange(channel, att);
      set.wakeup();
    }
  }
  
  public void register(SocketChannel channel)
  {
    int s = _set++;
    if (s < 0) {
      s = -s;
    }
    s %= _selectSets;
    SelectSet[] sets = _selectSet;
    if (sets != null)
    {
      SelectSet set = sets[s];
      set.addChange(channel);
      set.wakeup();
    }
  }
  
  public void register(ServerSocketChannel acceptChannel)
  {
    int s = _set++;
    if (s < 0) {
      s = -s;
    }
    s %= _selectSets;
    SelectSet set = _selectSet[s];
    set.addChange(acceptChannel);
    set.wakeup();
  }
  
  public int getSelectorPriorityDelta()
  {
    return _selectorPriorityDelta;
  }
  
  public void setSelectorPriorityDelta(int delta)
  {
    _selectorPriorityDelta = delta;
  }
  
  public long getLowResourcesConnections()
  {
    return _lowResourcesConnections * _selectSets;
  }
  
  public void setLowResourcesConnections(long lowResourcesConnections)
  {
    _lowResourcesConnections = ((lowResourcesConnections + _selectSets - 1L) / _selectSets);
  }
  
  public long getLowResourcesMaxIdleTime()
  {
    return _lowResourcesMaxIdleTime;
  }
  
  public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)
  {
    _lowResourcesMaxIdleTime = ((int)lowResourcesMaxIdleTime);
  }
  
  public abstract boolean dispatch(Runnable paramRunnable);
  
  protected void doStart()
    throws Exception
  {
    _selectSet = new SelectSet[_selectSets];
    for (int i = 0; i < _selectSet.length; i++) {
      _selectSet[i] = new SelectSet(i);
    }
    super.doStart();
    for (int i = 0; i < getSelectSets(); i++)
    {
      final int id = i;
      boolean selecting = dispatch(new Runnable()
      {
        /* Error */
        public void run()
        {
          // Byte code:
          //   0: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   3: invokevirtual 5	java/lang/Thread:getName	()Ljava/lang/String;
          //   6: astore_1
          //   7: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   10: invokevirtual 6	java/lang/Thread:getPriority	()I
          //   13: istore_2
          //   14: aload_0
          //   15: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   18: invokestatic 7	org/eclipse/jetty/io/nio/SelectorManager:access$000	(Lorg/eclipse/jetty/io/nio/SelectorManager;)[Lorg/eclipse/jetty/io/nio/SelectorManager$SelectSet;
          //   21: astore_3
          //   22: aload_3
          //   23: ifnonnull +52 -> 75
          //   26: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   29: ldc 9
          //   31: iconst_2
          //   32: anewarray 10	java/lang/Object
          //   35: dup
          //   36: iconst_0
          //   37: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   40: aastore
          //   41: dup
          //   42: iconst_1
          //   43: aload_0
          //   44: aastore
          //   45: invokeinterface 11 3 0
          //   50: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   53: aload_1
          //   54: invokevirtual 12	java/lang/Thread:setName	(Ljava/lang/String;)V
          //   57: aload_0
          //   58: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   61: invokevirtual 13	org/eclipse/jetty/io/nio/SelectorManager:getSelectorPriorityDelta	()I
          //   64: ifeq +10 -> 74
          //   67: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   70: iload_2
          //   71: invokevirtual 14	java/lang/Thread:setPriority	(I)V
          //   74: return
          //   75: aload_3
          //   76: aload_0
          //   77: getfield 2	org/eclipse/jetty/io/nio/SelectorManager$1:val$id	I
          //   80: aaload
          //   81: astore 4
          //   83: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   86: new 15	java/lang/StringBuilder
          //   89: dup
          //   90: invokespecial 16	java/lang/StringBuilder:<init>	()V
          //   93: aload_1
          //   94: invokevirtual 17	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
          //   97: ldc 18
          //   99: invokevirtual 17	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
          //   102: aload_0
          //   103: getfield 2	org/eclipse/jetty/io/nio/SelectorManager$1:val$id	I
          //   106: invokevirtual 19	java/lang/StringBuilder:append	(I)Ljava/lang/StringBuilder;
          //   109: invokevirtual 20	java/lang/StringBuilder:toString	()Ljava/lang/String;
          //   112: invokevirtual 12	java/lang/Thread:setName	(Ljava/lang/String;)V
          //   115: aload_0
          //   116: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   119: invokevirtual 13	org/eclipse/jetty/io/nio/SelectorManager:getSelectorPriorityDelta	()I
          //   122: ifeq +23 -> 145
          //   125: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   128: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   131: invokevirtual 6	java/lang/Thread:getPriority	()I
          //   134: aload_0
          //   135: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   138: invokevirtual 13	org/eclipse/jetty/io/nio/SelectorManager:getSelectorPriorityDelta	()I
          //   141: iadd
          //   142: invokevirtual 14	java/lang/Thread:setPriority	(I)V
          //   145: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   148: ldc 21
          //   150: iconst_2
          //   151: anewarray 10	java/lang/Object
          //   154: dup
          //   155: iconst_0
          //   156: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   159: aastore
          //   160: dup
          //   161: iconst_1
          //   162: aload_0
          //   163: aastore
          //   164: invokeinterface 11 3 0
          //   169: aload_0
          //   170: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   173: invokevirtual 22	org/eclipse/jetty/io/nio/SelectorManager:isRunning	()Z
          //   176: ifeq +41 -> 217
          //   179: aload 4
          //   181: invokevirtual 23	org/eclipse/jetty/io/nio/SelectorManager$SelectSet:doSelect	()V
          //   184: goto -15 -> 169
          //   187: astore 5
          //   189: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   192: aload 5
          //   194: invokeinterface 25 2 0
          //   199: goto -30 -> 169
          //   202: astore 5
          //   204: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   207: aload 5
          //   209: invokeinterface 27 2 0
          //   214: goto -45 -> 169
          //   217: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   220: ldc 9
          //   222: iconst_2
          //   223: anewarray 10	java/lang/Object
          //   226: dup
          //   227: iconst_0
          //   228: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   231: aastore
          //   232: dup
          //   233: iconst_1
          //   234: aload_0
          //   235: aastore
          //   236: invokeinterface 11 3 0
          //   241: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   244: aload_1
          //   245: invokevirtual 12	java/lang/Thread:setName	(Ljava/lang/String;)V
          //   248: aload_0
          //   249: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   252: invokevirtual 13	org/eclipse/jetty/io/nio/SelectorManager:getSelectorPriorityDelta	()I
          //   255: ifeq +66 -> 321
          //   258: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   261: iload_2
          //   262: invokevirtual 14	java/lang/Thread:setPriority	(I)V
          //   265: goto +56 -> 321
          //   268: astore 6
          //   270: getstatic 8	org/eclipse/jetty/io/nio/SelectorManager:LOG	Lorg/eclipse/jetty/util/log/Logger;
          //   273: ldc 9
          //   275: iconst_2
          //   276: anewarray 10	java/lang/Object
          //   279: dup
          //   280: iconst_0
          //   281: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   284: aastore
          //   285: dup
          //   286: iconst_1
          //   287: aload_0
          //   288: aastore
          //   289: invokeinterface 11 3 0
          //   294: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   297: aload_1
          //   298: invokevirtual 12	java/lang/Thread:setName	(Ljava/lang/String;)V
          //   301: aload_0
          //   302: getfield 1	org/eclipse/jetty/io/nio/SelectorManager$1:this$0	Lorg/eclipse/jetty/io/nio/SelectorManager;
          //   305: invokevirtual 13	org/eclipse/jetty/io/nio/SelectorManager:getSelectorPriorityDelta	()I
          //   308: ifeq +10 -> 318
          //   311: invokestatic 4	java/lang/Thread:currentThread	()Ljava/lang/Thread;
          //   314: iload_2
          //   315: invokevirtual 14	java/lang/Thread:setPriority	(I)V
          //   318: aload 6
          //   320: athrow
          //   321: return
          // Line number table:
          //   Java source line #268	-> byte code offset #0
          //   Java source line #269	-> byte code offset #7
          //   Java source line #272	-> byte code offset #14
          //   Java source line #273	-> byte code offset #22
          //   Java source line #299	-> byte code offset #26
          //   Java source line #300	-> byte code offset #50
          //   Java source line #301	-> byte code offset #57
          //   Java source line #302	-> byte code offset #67
          //   Java source line #275	-> byte code offset #75
          //   Java source line #277	-> byte code offset #83
          //   Java source line #278	-> byte code offset #115
          //   Java source line #279	-> byte code offset #125
          //   Java source line #280	-> byte code offset #145
          //   Java source line #281	-> byte code offset #169
          //   Java source line #285	-> byte code offset #179
          //   Java source line #294	-> byte code offset #184
          //   Java source line #287	-> byte code offset #187
          //   Java source line #289	-> byte code offset #189
          //   Java source line #294	-> byte code offset #199
          //   Java source line #291	-> byte code offset #202
          //   Java source line #293	-> byte code offset #204
          //   Java source line #294	-> byte code offset #214
          //   Java source line #299	-> byte code offset #217
          //   Java source line #300	-> byte code offset #241
          //   Java source line #301	-> byte code offset #248
          //   Java source line #302	-> byte code offset #258
          //   Java source line #299	-> byte code offset #268
          //   Java source line #300	-> byte code offset #294
          //   Java source line #301	-> byte code offset #301
          //   Java source line #302	-> byte code offset #311
          //   Java source line #304	-> byte code offset #321
          // Local variable table:
          //   start	length	slot	name	signature
          //   0	322	0	this	1
          //   6	292	1	name	String
          //   13	302	2	priority	int
          //   21	55	3	sets	SelectorManager.SelectSet[]
          //   81	99	4	set	SelectorManager.SelectSet
          //   187	6	5	e	IOException
          //   202	6	5	e	Exception
          //   268	51	6	localObject	Object
          // Exception table:
          //   from	to	target	type
          //   179	184	187	java/io/IOException
          //   179	184	202	java/lang/Exception
          //   14	26	268	finally
          //   75	217	268	finally
          //   268	270	268	finally
        }
      });
      if (!selecting) {
        throw new IllegalStateException("!Selecting");
      }
    }
  }
  
  protected void doStop()
    throws Exception
  {
    SelectSet[] sets = _selectSet;
    _selectSet = null;
    if (sets != null) {
      for (SelectSet set : sets) {
        if (set != null) {
          set.stop();
        }
      }
    }
    super.doStop();
  }
  
  protected abstract void endPointClosed(SelectChannelEndPoint paramSelectChannelEndPoint);
  
  protected abstract void endPointOpened(SelectChannelEndPoint paramSelectChannelEndPoint);
  
  protected abstract void endPointUpgraded(ConnectedEndPoint paramConnectedEndPoint, Connection paramConnection);
  
  public abstract AsyncConnection newConnection(SocketChannel paramSocketChannel, AsyncEndPoint paramAsyncEndPoint, Object paramObject);
  
  protected abstract SelectChannelEndPoint newEndPoint(SocketChannel paramSocketChannel, SelectSet paramSelectSet, SelectionKey paramSelectionKey)
    throws IOException;
  
  protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
  {
    LOG.warn(ex + "," + channel + "," + attachment, new Object[0]);
    LOG.debug(ex);
  }
  
  public String dump()
  {
    return AggregateLifeCycle.dump(this);
  }
  
  public void dump(Appendable out, String indent)
    throws IOException
  {
    AggregateLifeCycle.dumpObject(out, this);
    AggregateLifeCycle.dump(out, indent, new Collection[] { TypeUtil.asList(_selectSet) });
  }
  
  public class 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();
    
    SelectSet(int acceptorID)
      throws Exception
    {
      _setID = acceptorID;
      
      _idleTick = System.currentTimeMillis();
      _timeout = new Timeout(this);
      _timeout.setDuration(0L);
      
      _selector = Selector.open();
      _monitorNext = (System.currentTimeMillis() + SelectorManager.__MONITOR_PERIOD);
    }
    
    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))
            {
              dispatch((Runnable)change);
            }
            else
            {
              throw new IllegalArgumentException(change.toString());
            }
          }
          catch (CancelledKeyException e)
          {
            SelectorManager.LOG.ignore(e);
          }
          catch (Throwable e)
          {
            if (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.__BUSY_PAUSE);
            }
            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.__IDLE_TICK : 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.__MONITOR_PERIOD > 0) && (now - before <= 1L)) {
              if (++_busySelects > SelectorManager.__MAX_SELECTS)
              {
                _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;
                  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 (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)) {
            dispatch((Runnable)task);
          }
          task = _timeout.expired();
        }
        if (now - _idleTick > SelectorManager.__IDLE_TICK)
        {
          _idleTick = now;
          
          final long idle_now = (_lowResourcesConnections > 0L) && (selector.keys().size() > _lowResourcesConnections) ? now + _maxIdleTime - _lowResourcesMaxIdleTime : now;
          
          dispatch(new Runnable()
          {
            public void run()
            {
              for (SelectChannelEndPoint endp : _endPoints.keySet()) {
                endp.checkIdleTimestamp(idle_now);
              }
            }
            
            public String toString()
            {
              return "Idle-" + super.toString();
            }
          });
        }
        if ((SelectorManager.__MONITOR_PERIOD > 0) && (now > _monitorNext))
        {
          _busySelects = 0;
          _pausing = false;
          _monitorNext = (now + SelectorManager.__MONITOR_PERIOD);
        }
      }
      catch (ClosedSelectorException e)
      {
        if (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 SelectorManager.this;
    }
    
    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()
          {
            SelectorManager.SelectSet.this.renewSelector();
          }
        });
        renewSelector();
      }
    }
    
    private SelectChannelEndPoint createEndPoint(SocketChannel channel, SelectionKey sKey)
      throws IOException
    {
      SelectChannelEndPoint endp = newEndPoint(channel, this, sKey);
      SelectorManager.LOG.debug("created {}", new Object[] { endp });
      endPointOpened(endp);
      _endPoints.put(endp, this);
      return endp;
    }
    
    public void destroyEndPoint(SelectChannelEndPoint endp)
    {
      SelectorManager.LOG.debug("destroyEndPoint {}", new Object[] { endp });
      _endPoints.remove(endp);
      endPointClosed(endp);
    }
    
    Selector getSelector()
    {
      return _selector;
    }
    
    void stop()
      throws Exception
    {
      try
      {
        for (int i = 0; (i < 100) && (_selecting != null); i++)
        {
          wakeup();
          Thread.sleep(10L);
        }
      }
      catch (Exception e)
      {
        SelectorManager.LOG.ignore(e);
      }
      synchronized (this)
      {
        Selector selector = _selector;
        for (SelectionKey key : selector.keys()) {
          if (key != null)
          {
            Object att = key.attachment();
            if ((att instanceof EndPoint))
            {
              EndPoint endpoint = (EndPoint)att;
              try
              {
                endpoint.close();
              }
              catch (IOException e)
              {
                SelectorManager.LOG.ignore(e);
              }
            }
          }
   
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