jetty-6.1.26

16:37:27.401 INFO  jd.cli.Main - Decompiling jetty-6.1.26.jar
package org.mortbay.jetty.nio;

public abstract interface NIOConnector
{
  public abstract boolean getUseDirectBuffers();
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.NIOConnector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import org.mortbay.io.Buffer;
import org.mortbay.io.nio.DirectNIOBuffer;
import org.mortbay.io.nio.IndirectNIOBuffer;
import org.mortbay.jetty.AbstractConnector;

public abstract class AbstractNIOConnector
  extends AbstractConnector
  implements NIOConnector
{
  private boolean _useDirectBuffers = true;
  
  public boolean getUseDirectBuffers()
  {
    return _useDirectBuffers;
  }
  
  public void setUseDirectBuffers(boolean direct)
  {
    _useDirectBuffers = direct;
  }
  
  protected Buffer newBuffer(int size)
  {
    Buffer buf = null;
    if (size == getHeaderBufferSize()) {
      buf = new IndirectNIOBuffer(size);
    } else {
      buf = _useDirectBuffers ? new DirectNIOBuffer(size) : new IndirectNIOBuffer(size);
    }
    return buf;
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.AbstractNIOConnector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.ByteChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.mortbay.io.EndPoint;
import org.mortbay.io.nio.ChannelEndPoint;
import org.mortbay.jetty.EofException;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.HttpException;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.log.Log;
import org.mortbay.thread.ThreadPool;

public class BlockingChannelConnector
  extends AbstractNIOConnector
{
  private transient ServerSocketChannel _acceptChannel;
  
  public Object getConnection()
  {
    return _acceptChannel;
  }
  
  public void open()
    throws IOException
  {
    _acceptChannel = ServerSocketChannel.open();
    _acceptChannel.configureBlocking(true);
    
    InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
    _acceptChannel.socket().bind(addr, getAcceptQueueSize());
  }
  
  public void close()
    throws IOException
  {
    if (_acceptChannel != null) {
      _acceptChannel.close();
    }
    _acceptChannel = null;
  }
  
  public void accept(int acceptorID)
    throws IOException, InterruptedException
  {
    SocketChannel channel = _acceptChannel.accept();
    channel.configureBlocking(true);
    Socket socket = channel.socket();
    configure(socket);
    
    Connection connection = new Connection(channel);
    connection.dispatch();
  }
  
  public void customize(EndPoint endpoint, Request request)
    throws IOException
  {
    Connection connection = (Connection)endpoint;
    if (_sotimeout != _maxIdleTime)
    {
      _sotimeout = _maxIdleTime;
      ((SocketChannel)endpoint.getTransport()).socket().setSoTimeout(_maxIdleTime);
    }
    super.customize(endpoint, request);
    configure(((SocketChannel)endpoint.getTransport()).socket());
  }
  
  public int getLocalPort()
  {
    if ((_acceptChannel == null) || (!_acceptChannel.isOpen())) {
      return -1;
    }
    return _acceptChannel.socket().getLocalPort();
  }
  
  private class Connection
    extends ChannelEndPoint
    implements Runnable
  {
    boolean _dispatched = false;
    HttpConnection _connection;
    int _sotimeout;
    
    Connection(ByteChannel channel)
    {
      super();
      _connection = new HttpConnection(BlockingChannelConnector.this, this, getServer());
    }
    
    void dispatch()
      throws IOException
    {
      if (!getThreadPool().dispatch(this))
      {
        Log.warn("dispatch failed for  {}", _connection);
        close();
      }
    }
    
    public void run()
    {
      try
      {
        connectionOpened(_connection);
        while (isOpen())
        {
          if (_connection.isIdle()) {
            if (getServer().getThreadPool().isLowOnThreads())
            {
              int lrmit = getLowResourceMaxIdleTime();
              if ((lrmit >= 0) && (_sotimeout != lrmit))
              {
                _sotimeout = lrmit;
                ((SocketChannel)getTransport()).socket().setSoTimeout(_sotimeout);
              }
            }
          }
          _connection.handle();
        }
      }
      catch (EofException e)
      {
        Log.debug("EOF", e);
        try
        {
          close();
        }
        catch (IOException e2)
        {
          Log.ignore(e2);
        }
      }
      catch (HttpException e)
      {
        Log.debug("BAD", e);
        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
      {
        connectionClosed(_connection);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.BlockingChannelConnector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import org.mortbay.io.nio.SelectChannelEndPoint;
import org.mortbay.io.nio.SelectorManager.SelectSet;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.RetryRequest;
import org.mortbay.thread.Timeout.Task;
import org.mortbay.util.ajax.Continuation;

public class SelectChannelConnector$RetryContinuation
  extends Timeout.Task
  implements Continuation, Runnable
{
  SelectChannelEndPoint _endPoint = (SelectChannelEndPoint)HttpConnection.getCurrentConnection().getEndPoint();
  boolean _new = true;
  Object _object;
  boolean _pending = false;
  boolean _resumed = false;
  boolean _parked = false;
  RetryRequest _retry;
  long _timeout;
  
  public Object getObject()
  {
    return _object;
  }
  
  public long getTimeout()
  {
    return _timeout;
  }
  
  public boolean isNew()
  {
    return _new;
  }
  
  public boolean isPending()
  {
    return _pending;
  }
  
  public boolean isResumed()
  {
    return _resumed;
  }
  
  public void reset()
  {
    synchronized (this)
    {
      _resumed = false;
      _pending = false;
      _parked = false;
    }
    synchronized (_endPoint.getSelectSet())
    {
      cancel();
    }
  }
  
  public boolean suspend(long timeout)
  {
    boolean resumed = false;
    synchronized (this)
    {
      resumed = _resumed;
      _resumed = false;
      _new = false;
      if ((!_pending) && (!resumed) && (timeout >= 0L))
      {
        _pending = true;
        _parked = false;
        _timeout = timeout;
        if (_retry == null) {
          _retry = new RetryRequest();
        }
        throw _retry;
      }
      _resumed = false;
      _pending = false;
      _parked = false;
    }
    synchronized (_endPoint.getSelectSet())
    {
      cancel();
    }
    return resumed;
  }
  
  public void resume()
  {
    boolean redispatch = false;
    synchronized (this)
    {
      if ((_pending) && (!isExpired()))
      {
        _resumed = true;
        redispatch = _parked;
        _parked = false;
      }
    }
    if (redispatch)
    {
      SelectorManager.SelectSet selectSet = _endPoint.getSelectSet();
      synchronized (selectSet)
      {
        cancel();
      }
      _endPoint.scheduleIdle();
      selectSet.addChange(this);
      selectSet.wakeup();
    }
  }
  
  public void expire()
  {
    boolean redispatch = false;
    synchronized (this)
    {
      redispatch = (_parked) && (_pending) && (!_resumed);
      _parked = false;
    }
    if (redispatch)
    {
      _endPoint.scheduleIdle();
      _endPoint.getSelectSet().addChange(this);
      _endPoint.getSelectSet().wakeup();
    }
  }
  
  public void run()
  {
    _endPoint.run();
  }
  
  public boolean undispatch()
  {
    boolean redispatch = false;
    synchronized (this)
    {
      if (!_pending) {
        return true;
      }
      redispatch = (isExpired()) || (_resumed);
      _parked = (!redispatch);
    }
    if (redispatch)
    {
      _endPoint.scheduleIdle();
      _endPoint.getSelectSet().addChange(this);
    }
    else if (_timeout > 0L)
    {
      _endPoint.getSelectSet().scheduleTimeout(this, _timeout);
    }
    _endPoint.getSelectSet().wakeup();
    return false;
  }
  
  public void setObject(Object object)
  {
    _object = object;
  }
  
  public String toString()
  {
    synchronized (this)
    {
      return "RetryContinuation@" + hashCode() + (_new ? ",new" : "") + (_pending ? ",pending" : "") + (_resumed ? ",resumed" : "") + (isExpired() ? ",expired" : "") + (_parked ? ",parked" : "");
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.SelectChannelConnector.RetryContinuation
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.mortbay.io.Connection;
import org.mortbay.io.EndPoint;
import org.mortbay.io.nio.SelectChannelEndPoint;
import org.mortbay.io.nio.SelectorManager;
import org.mortbay.io.nio.SelectorManager.SelectSet;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.RetryRequest;
import org.mortbay.log.Log;
import org.mortbay.thread.ThreadPool;
import org.mortbay.thread.Timeout.Task;
import org.mortbay.util.ajax.Continuation;

public class SelectChannelConnector
  extends AbstractNIOConnector
{
  protected transient ServerSocketChannel _acceptChannel;
  private long _lowResourcesConnections;
  private long _lowResourcesMaxIdleTime;
  private SelectorManager _manager = new SelectorManager()
  {
    protected SocketChannel acceptChannel(SelectionKey key)
      throws IOException
    {
      SocketChannel channel = ((ServerSocketChannel)key.channel()).accept();
      if (channel == null) {
        return null;
      }
      channel.configureBlocking(false);
      Socket socket = channel.socket();
      configure(socket);
      return channel;
    }
    
    public boolean dispatch(Runnable task)
      throws IOException
    {
      return getThreadPool().dispatch(task);
    }
    
    protected void endPointClosed(SelectChannelEndPoint endpoint)
    {
      connectionClosed((HttpConnection)endpoint.getConnection());
    }
    
    protected void endPointOpened(SelectChannelEndPoint endpoint)
    {
      connectionOpened((HttpConnection)endpoint.getConnection());
    }
    
    protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
    {
      return SelectChannelConnector.this.newConnection(channel, endpoint);
    }
    
    protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey sKey)
      throws IOException
    {
      return SelectChannelConnector.this.newEndPoint(channel, selectSet, sKey);
    }
  };
  
  public void accept(int acceptorID)
    throws IOException
  {
    _manager.doSelect(acceptorID);
  }
  
  public void close()
    throws IOException
  {
    synchronized (this)
    {
      if (_manager.isRunning()) {
        try
        {
          _manager.stop();
        }
        catch (Exception e)
        {
          Log.warn(e);
        }
      }
      if (_acceptChannel != null) {
        _acceptChannel.close();
      }
      _acceptChannel = null;
    }
  }
  
  public void customize(EndPoint endpoint, Request request)
    throws IOException
  {
    ConnectorEndPoint cep = (ConnectorEndPoint)endpoint;
    cep.cancelIdle();
    request.setTimeStamp(cep.getSelectSet().getNow());
    super.customize(endpoint, request);
  }
  
  public void persist(EndPoint endpoint)
    throws IOException
  {
    ((ConnectorEndPoint)endpoint).scheduleIdle();
    super.persist(endpoint);
  }
  
  public Object getConnection()
  {
    return _acceptChannel;
  }
  
  public boolean getDelaySelectKeyUpdate()
  {
    return _manager.isDelaySelectKeyUpdate();
  }
  
  public int getLocalPort()
  {
    synchronized (this)
    {
      if ((_acceptChannel == null) || (!_acceptChannel.isOpen())) {
        return -1;
      }
      return _acceptChannel.socket().getLocalPort();
    }
  }
  
  public Continuation newContinuation()
  {
    return new RetryContinuation();
  }
  
  public void open()
    throws IOException
  {
    synchronized (this)
    {
      if (_acceptChannel == null)
      {
        _acceptChannel = ServerSocketChannel.open();
        
        _acceptChannel.socket().setReuseAddress(getReuseAddress());
        InetSocketAddress addr = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort());
        _acceptChannel.socket().bind(addr, getAcceptQueueSize());
        
        _acceptChannel.configureBlocking(false);
      }
    }
  }
  
  public void setDelaySelectKeyUpdate(boolean delay)
  {
    _manager.setDelaySelectKeyUpdate(delay);
  }
  
  public void setMaxIdleTime(int maxIdleTime)
  {
    _manager.setMaxIdleTime(maxIdleTime);
    super.setMaxIdleTime(maxIdleTime);
  }
  
  public long getLowResourcesConnections()
  {
    return _lowResourcesConnections;
  }
  
  public void setLowResourcesConnections(long lowResourcesConnections)
  {
    _lowResourcesConnections = lowResourcesConnections;
  }
  
  public long getLowResourcesMaxIdleTime()
  {
    return _lowResourcesMaxIdleTime;
  }
  
  /**
   * @deprecated
   */
  public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)
  {
    _lowResourcesMaxIdleTime = lowResourcesMaxIdleTime;
    super.setLowResourceMaxIdleTime((int)lowResourcesMaxIdleTime);
  }
  
  public void setLowResourceMaxIdleTime(int lowResourcesMaxIdleTime)
  {
    _lowResourcesMaxIdleTime = lowResourcesMaxIdleTime;
    super.setLowResourceMaxIdleTime(lowResourcesMaxIdleTime);
  }
  
  protected void doStart()
    throws Exception
  {
    _manager.setSelectSets(getAcceptors());
    _manager.setMaxIdleTime(getMaxIdleTime());
    _manager.setLowResourcesConnections(getLowResourcesConnections());
    _manager.setLowResourcesMaxIdleTime(getLowResourcesMaxIdleTime());
    _manager.start();
    open();
    _manager.register(_acceptChannel);
    super.doStart();
  }
  
  protected void doStop()
    throws Exception
  {
    super.doStop();
  }
  
  protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key)
    throws IOException
  {
    return new ConnectorEndPoint(channel, selectSet, key);
  }
  
  protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
  {
    return new HttpConnection(this, endpoint, getServer());
  }
  
  public static class ConnectorEndPoint
    extends SelectChannelEndPoint
  {
    public ConnectorEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key)
    {
      super(selectSet, key);
      scheduleIdle();
    }
    
    public void close()
      throws IOException
    {
      Connection con = getConnection();
      if ((con instanceof HttpConnection))
      {
        SelectChannelConnector.RetryContinuation continuation = (SelectChannelConnector.RetryContinuation)((HttpConnection)getConnection()).getRequest().getContinuation();
        if ((continuation != null) && (continuation.isPending())) {
          continuation.reset();
        }
      }
      super.close();
    }
    
    public void undispatch()
    {
      Connection con = getConnection();
      if ((con instanceof HttpConnection))
      {
        SelectChannelConnector.RetryContinuation continuation = (SelectChannelConnector.RetryContinuation)((HttpConnection)getConnection()).getRequest().getContinuation();
        if (continuation != null)
        {
          Log.debug("continuation {}", continuation);
          if (continuation.undispatch()) {
            super.undispatch();
          }
        }
        else
        {
          super.undispatch();
        }
      }
      else
      {
        super.undispatch();
      }
    }
  }
  
  public static class RetryContinuation
    extends Timeout.Task
    implements Continuation, Runnable
  {
    SelectChannelEndPoint _endPoint = (SelectChannelEndPoint)HttpConnection.getCurrentConnection().getEndPoint();
    boolean _new = true;
    Object _object;
    boolean _pending = false;
    boolean _resumed = false;
    boolean _parked = false;
    RetryRequest _retry;
    long _timeout;
    
    public Object getObject()
    {
      return _object;
    }
    
    public long getTimeout()
    {
      return _timeout;
    }
    
    public boolean isNew()
    {
      return _new;
    }
    
    public boolean isPending()
    {
      return _pending;
    }
    
    public boolean isResumed()
    {
      return _resumed;
    }
    
    public void reset()
    {
      synchronized (this)
      {
        _resumed = false;
        _pending = false;
        _parked = false;
      }
      synchronized (_endPoint.getSelectSet())
      {
        cancel();
      }
    }
    
    public boolean suspend(long timeout)
    {
      boolean resumed = false;
      synchronized (this)
      {
        resumed = _resumed;
        _resumed = false;
        _new = false;
        if ((!_pending) && (!resumed) && (timeout >= 0L))
        {
          _pending = true;
          _parked = false;
          _timeout = timeout;
          if (_retry == null) {
            _retry = new RetryRequest();
          }
          throw _retry;
        }
        _resumed = false;
        _pending = false;
        _parked = false;
      }
      synchronized (_endPoint.getSelectSet())
      {
        cancel();
      }
      return resumed;
    }
    
    public void resume()
    {
      boolean redispatch = false;
      synchronized (this)
      {
        if ((_pending) && (!isExpired()))
        {
          _resumed = true;
          redispatch = _parked;
          _parked = false;
        }
      }
      if (redispatch)
      {
        SelectorManager.SelectSet selectSet = _endPoint.getSelectSet();
        synchronized (selectSet)
        {
          cancel();
        }
        _endPoint.scheduleIdle();
        selectSet.addChange(this);
        selectSet.wakeup();
      }
    }
    
    public void expire()
    {
      boolean redispatch = false;
      synchronized (this)
      {
        redispatch = (_parked) && (_pending) && (!_resumed);
        _parked = false;
      }
      if (redispatch)
      {
        _endPoint.scheduleIdle();
        _endPoint.getSelectSet().addChange(this);
        _endPoint.getSelectSet().wakeup();
      }
    }
    
    public void run()
    {
      _endPoint.run();
    }
    
    public boolean undispatch()
    {
      boolean redispatch = false;
      synchronized (this)
      {
        if (!_pending) {
          return true;
        }
        redispatch = (isExpired()) || (_resumed);
        _parked = (!redispatch);
      }
      if (redispatch)
      {
        _endPoint.scheduleIdle();
        _endPoint.getSelectSet().addChange(this);
      }
      else if (_timeout > 0L)
      {
        _endPoint.getSelectSet().scheduleTimeout(this, _timeout);
      }
      _endPoint.getSelectSet().wakeup();
      return false;
    }
    
    public void setObject(Object object)
    {
      _object = object;
    }
    
    public String toString()
    {
      synchronized (this)
      {
        return "RetryContinuation@" + hashCode() + (_new ? ",new" : "") + (_pending ? ",pending" : "") + (_resumed ? ",resumed" : "") + (isExpired() ? ",expired" : "") + (_parked ? ",parked" : "");
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.SelectChannelConnector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.net.Socket;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import org.mortbay.io.Connection;
import org.mortbay.io.nio.SelectChannelEndPoint;
import org.mortbay.io.nio.SelectorManager;
import org.mortbay.io.nio.SelectorManager.SelectSet;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.thread.ThreadPool;

class SelectChannelConnector$1
  extends SelectorManager
{
  private final SelectChannelConnector this$0;
  
  SelectChannelConnector$1(SelectChannelConnector paramSelectChannelConnector) {}
  
  protected SocketChannel acceptChannel(SelectionKey key)
    throws IOException
  {
    SocketChannel channel = ((ServerSocketChannel)key.channel()).accept();
    if (channel == null) {
      return null;
    }
    channel.configureBlocking(false);
    Socket socket = channel.socket();
    SelectChannelConnector.access$000(this$0, socket);
    return channel;
  }
  
  public boolean dispatch(Runnable task)
    throws IOException
  {
    return this$0.getThreadPool().dispatch(task);
  }
  
  protected void endPointClosed(SelectChannelEndPoint endpoint)
  {
    SelectChannelConnector.access$100(this$0, (HttpConnection)endpoint.getConnection());
  }
  
  protected void endPointOpened(SelectChannelEndPoint endpoint)
  {
    SelectChannelConnector.access$200(this$0, (HttpConnection)endpoint.getConnection());
  }
  
  protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
  {
    return this$0.newConnection(channel, endpoint);
  }
  
  protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey sKey)
    throws IOException
  {
    return this$0.newEndPoint(channel, selectSet, sKey);
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.SelectChannelConnector.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.channels.Channel;
import java.nio.channels.ServerSocketChannel;
import org.mortbay.log.Log;

public class InheritedChannelConnector
  extends SelectChannelConnector
{
  public void open()
    throws IOException
  {
    synchronized (this)
    {
      try
      {
        Method m = System.class.getMethod("inheritedChannel", null);
        if (m != null)
        {
          Channel channel = (Channel)m.invoke(null, null);
          if ((channel instanceof ServerSocketChannel)) {
            _acceptChannel = ((ServerSocketChannel)channel);
          }
        }
        if (_acceptChannel != null) {
          _acceptChannel.configureBlocking(false);
        }
      }
      catch (Exception e)
      {
        Log.warn(e);
      }
      if (_acceptChannel == null) {
        super.open();
      } else {
        throw new IOException("No System.inheritedChannel()");
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.InheritedChannelConnector
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import org.mortbay.io.Connection;
import org.mortbay.io.nio.SelectChannelEndPoint;
import org.mortbay.io.nio.SelectorManager.SelectSet;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.Request;
import org.mortbay.log.Log;

public class SelectChannelConnector$ConnectorEndPoint
  extends SelectChannelEndPoint
{
  public SelectChannelConnector$ConnectorEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey key)
  {
    super(channel, selectSet, key);
    scheduleIdle();
  }
  
  public void close()
    throws IOException
  {
    Connection con = getConnection();
    if ((con instanceof HttpConnection))
    {
      SelectChannelConnector.RetryContinuation continuation = (SelectChannelConnector.RetryContinuation)((HttpConnection)getConnection()).getRequest().getContinuation();
      if ((continuation != null) && (continuation.isPending())) {
        continuation.reset();
      }
    }
    super.close();
  }
  
  public void undispatch()
  {
    Connection con = getConnection();
    if ((con instanceof HttpConnection))
    {
      SelectChannelConnector.RetryContinuation continuation = (SelectChannelConnector.RetryContinuation)((HttpConnection)getConnection()).getRequest().getContinuation();
      if (continuation != null)
      {
        Log.debug("continuation {}", continuation);
        if (continuation.undispatch()) {
          super.undispatch();
        }
      }
      else
      {
        super.undispatch();
      }
    }
    else
    {
      super.undispatch();
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.SelectChannelConnector.ConnectorEndPoint
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty.nio;

import java.io.IOException;
import java.net.Socket;
import java.nio.channels.ByteChannel;
import java.nio.channels.SocketChannel;
import org.mortbay.io.nio.ChannelEndPoint;
import org.mortbay.jetty.EofException;
import org.mortbay.jetty.HttpConnection;
import org.mortbay.jetty.HttpException;
import org.mortbay.jetty.Server;
import org.mortbay.log.Log;
import org.mortbay.thread.ThreadPool;

class BlockingChannelConnector$Connection
  extends ChannelEndPoint
  implements Runnable
{
  boolean _dispatched = false;
  HttpConnection _connection;
  int _sotimeout;
  private final BlockingChannelConnector this$0;
  
  BlockingChannelConnector$Connection(BlockingChannelConnector paramBlockingChannelConnector, ByteChannel channel)
  {
    super(channel);
    _connection = new HttpConnection(paramBlockingChannelConnector, this, paramBlockingChannelConnector.getServer());
  }
  
  void dispatch()
    throws IOException
  {
    if (!this$0.getThreadPool().dispatch(this))
    {
      Log.warn("dispatch failed for  {}", _connection);
      close();
    }
  }
  
  public void run()
  {
    try
    {
      BlockingChannelConnector.access$000(this$0, _connection);
      while (isOpen())
      {
        if (_connection.isIdle()) {
          if (this$0.getServer().getThreadPool().isLowOnThreads())
          {
            int lrmit = this$0.getLowResourceMaxIdleTime();
            if ((lrmit >= 0) && (_sotimeout != lrmit))
            {
              _sotimeout = lrmit;
              ((SocketChannel)getTransport()).socket().setSoTimeout(_sotimeout);
            }
          }
        }
        _connection.handle();
      }
    }
    catch (EofException e)
    {
      Log.debug("EOF", e);
      try
      {
        close();
      }
      catch (IOException e2)
      {
        Log.ignore(e2);
      }
    }
    catch (HttpException e)
    {
      Log.debug("BAD", e);
      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
    {
      BlockingChannelConnector.access$100(this$0, _connection);
    }
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.nio.BlockingChannelConnector.Connection
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import org.mortbay.io.Buffer;
import org.mortbay.io.BufferCache;
import org.mortbay.io.BufferCache.CachedBuffer;
import org.mortbay.log.Log;
import org.mortbay.util.StringUtil;

public class MimeTypes
{
  public static final String FORM_ENCODED = "application/x-www-form-urlencoded";
  public static final String MESSAGE_HTTP = "message/http";
  public static final String MULTIPART_BYTERANGES = "multipart/byteranges";
  public static final String TEXT_HTML = "text/html";
  public static final String TEXT_PLAIN = "text/plain";
  public static final String TEXT_XML = "text/xml";
  public static final String TEXT_HTML_8859_1 = "text/html; charset=iso-8859-1";
  public static final String TEXT_PLAIN_8859_1 = "text/plain; charset=iso-8859-1";
  public static final String TEXT_XML_8859_1 = "text/xml; charset=iso-8859-1";
  public static final String TEXT_HTML_UTF_8 = "text/html; charset=utf-8";
  public static final String TEXT_PLAIN_UTF_8 = "text/plain; charset=utf-8";
  public static final String TEXT_XML_UTF_8 = "text/xml; charset=utf-8";
  public static final String TEXT_JSON = "text/json";
  public static final String TEXT_JSON_UTF_8 = "text/json;charset=UTF-8";
  private static final int FORM_ENCODED_ORDINAL = 1;
  private static final int MESSAGE_HTTP_ORDINAL = 2;
  private static final int MULTIPART_BYTERANGES_ORDINAL = 3;
  private static final int TEXT_HTML_ORDINAL = 4;
  private static final int TEXT_PLAIN_ORDINAL = 5;
  private static final int TEXT_XML_ORDINAL = 6;
  private static final int TEXT_HTML_8859_1_ORDINAL = 7;
  private static final int TEXT_PLAIN_8859_1_ORDINAL = 8;
  private static final int TEXT_XML_8859_1_ORDINAL = 9;
  private static final int TEXT_HTML_UTF_8_ORDINAL = 10;
  private static final int TEXT_PLAIN_UTF_8_ORDINAL = 11;
  private static final int TEXT_XML_UTF_8_ORDINAL = 12;
  private static final int TEXT_JSON_ORDINAL = 13;
  private static final int TEXT_JSON_UTF_8_ORDINAL = 14;
  private static int __index = 15;
  public static final BufferCache CACHE = new BufferCache();
  public static final BufferCache.CachedBuffer FORM_ENCODED_BUFFER = CACHE.add("application/x-www-form-urlencoded", 1);
  public static final BufferCache.CachedBuffer MESSAGE_HTTP_BUFFER = CACHE.add("message/http", 2);
  public static final BufferCache.CachedBuffer MULTIPART_BYTERANGES_BUFFER = CACHE.add("multipart/byteranges", 3);
  public static final BufferCache.CachedBuffer TEXT_HTML_BUFFER = CACHE.add("text/html", 4);
  public static final BufferCache.CachedBuffer TEXT_PLAIN_BUFFER = CACHE.add("text/plain", 5);
  public static final BufferCache.CachedBuffer TEXT_XML_BUFFER = CACHE.add("text/xml", 6);
  public static final BufferCache.CachedBuffer TEXT_HTML_8859_1_BUFFER = new BufferCache.CachedBuffer("text/html; charset=iso-8859-1", 7);
  public static final BufferCache.CachedBuffer TEXT_PLAIN_8859_1_BUFFER = new BufferCache.CachedBuffer("text/plain; charset=iso-8859-1", 8);
  public static final BufferCache.CachedBuffer TEXT_XML_8859_1_BUFFER = new BufferCache.CachedBuffer("text/xml; charset=iso-8859-1", 9);
  public static final BufferCache.CachedBuffer TEXT_HTML_UTF_8_BUFFER = new BufferCache.CachedBuffer("text/html; charset=utf-8", 10);
  public static final BufferCache.CachedBuffer TEXT_PLAIN_UTF_8_BUFFER = new BufferCache.CachedBuffer("text/plain; charset=utf-8", 11);
  public static final BufferCache.CachedBuffer TEXT_XML_UTF_8_BUFFER = new BufferCache.CachedBuffer("text/xml; charset=utf-8", 12);
  public static final BufferCache.CachedBuffer TEXT_JSON_BUFFER = CACHE.add("text/json", 13);
  public static final BufferCache.CachedBuffer TEXT_JSON_UTF_8_BUFFER = CACHE.add("text/json;charset=UTF-8", 14);
  private static final Map __dftMimeMap = new HashMap();
  private static final Map __encodings = new HashMap();
  private Map _mimeMap;
  
  static
  {
    try
    {
      ResourceBundle mime = ResourceBundle.getBundle("org/mortbay/jetty/mime");
      Enumeration i = mime.getKeys();
      while (i.hasMoreElements())
      {
        String ext = (String)i.nextElement();
        String m = mime.getString(ext);
        __dftMimeMap.put(StringUtil.asciiToLowerCase(ext), normalizeMimeType(m));
      }
    }
    catch (MissingResourceException e)
    {
      Log.warn(e.toString());
      Log.debug(e);
    }
    try
    {
      ResourceBundle encoding = ResourceBundle.getBundle("org/mortbay/jetty/encoding");
      Enumeration i = encoding.getKeys();
      while (i.hasMoreElements())
      {
        Buffer type = normalizeMimeType((String)i.nextElement());
        __encodings.put(type, encoding.getString(type.toString()));
      }
    }
    catch (MissingResourceException e)
    {
      Log.warn(e.toString());
      Log.debug(e);
    }
    TEXT_HTML_BUFFER.setAssociate("ISO-8859-1", TEXT_HTML_8859_1_BUFFER);
    TEXT_HTML_BUFFER.setAssociate("ISO_8859_1", TEXT_HTML_8859_1_BUFFER);
    TEXT_HTML_BUFFER.setAssociate("iso-8859-1", TEXT_HTML_8859_1_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("ISO-8859-1", TEXT_PLAIN_8859_1_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("ISO_8859_1", TEXT_PLAIN_8859_1_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("iso-8859-1", TEXT_PLAIN_8859_1_BUFFER);
    TEXT_XML_BUFFER.setAssociate("ISO-8859-1", TEXT_XML_8859_1_BUFFER);
    TEXT_XML_BUFFER.setAssociate("ISO_8859_1", TEXT_XML_8859_1_BUFFER);
    TEXT_XML_BUFFER.setAssociate("iso-8859-1", TEXT_XML_8859_1_BUFFER);
    
    TEXT_HTML_BUFFER.setAssociate("UTF-8", TEXT_HTML_UTF_8_BUFFER);
    TEXT_HTML_BUFFER.setAssociate("UTF8", TEXT_HTML_UTF_8_BUFFER);
    TEXT_HTML_BUFFER.setAssociate("utf8", TEXT_HTML_UTF_8_BUFFER);
    TEXT_HTML_BUFFER.setAssociate("utf-8", TEXT_HTML_UTF_8_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("UTF-8", TEXT_PLAIN_UTF_8_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("UTF8", TEXT_PLAIN_UTF_8_BUFFER);
    TEXT_PLAIN_BUFFER.setAssociate("utf-8", TEXT_PLAIN_UTF_8_BUFFER);
    TEXT_XML_BUFFER.setAssociate("UTF-8", TEXT_XML_UTF_8_BUFFER);
    TEXT_XML_BUFFER.setAssociate("utf8", TEXT_XML_UTF_8_BUFFER);
    TEXT_XML_BUFFER.setAssociate("UTF8", TEXT_XML_UTF_8_BUFFER);
    TEXT_XML_BUFFER.setAssociate("utf-8", TEXT_XML_UTF_8_BUFFER);
    
    TEXT_JSON_BUFFER.setAssociate("UTF-8", TEXT_JSON_UTF_8_BUFFER);
    TEXT_JSON_BUFFER.setAssociate("utf8", TEXT_JSON_UTF_8_BUFFER);
    TEXT_JSON_BUFFER.setAssociate("UTF8", TEXT_JSON_UTF_8_BUFFER);
    TEXT_JSON_BUFFER.setAssociate("utf-8", TEXT_JSON_UTF_8_BUFFER);
  }
  
  public synchronized Map getMimeMap()
  {
    return _mimeMap;
  }
  
  public void setMimeMap(Map mimeMap)
  {
    if (mimeMap == null)
    {
      _mimeMap = null;
      return;
    }
    Map m = new HashMap();
    Iterator i = mimeMap.entrySet().iterator();
    while (i.hasNext())
    {
      Map.Entry entry = (Map.Entry)i.next();
      m.put(entry.getKey(), normalizeMimeType(entry.getValue().toString()));
    }
    _mimeMap = m;
  }
  
  public Buffer getMimeByExtension(String filename)
  {
    Buffer type = null;
    if (filename != null)
    {
      int i = -1;
      while (type == null)
      {
        i = filename.indexOf(".", i + 1);
        if ((i < 0) || (i >= filename.length())) {
          break;
        }
        String ext = StringUtil.asciiToLowerCase(filename.substring(i + 1));
        if (_mimeMap != null) {
          type = (Buffer)_mimeMap.get(ext);
        }
        if (type == null) {
          type = (Buffer)__dftMimeMap.get(ext);
        }
      }
    }
    if (type == null)
    {
      if (_mimeMap != null) {
        type = (Buffer)_mimeMap.get("*");
      }
      if (type == null) {
        type = (Buffer)__dftMimeMap.get("*");
      }
    }
    return type;
  }
  
  public void addMimeMapping(String extension, String type)
  {
    if (_mimeMap == null) {
      _mimeMap = new HashMap();
    }
    _mimeMap.put(StringUtil.asciiToLowerCase(extension), normalizeMimeType(type));
  }
  
  private static synchronized Buffer normalizeMimeType(String type)
  {
    Buffer b = CACHE.get(type);
    if (b == null) {
      b = CACHE.add(type, __index++);
    }
    return b;
  }
  
  public static String getCharsetFromContentType(Buffer value)
  {
    if ((value instanceof BufferCache.CachedBuffer)) {
      switch (((BufferCache.CachedBuffer)value).getOrdinal())
      {
      case 7: 
      case 8: 
      case 9: 
        return StringUtil.__ISO_8859_1;
      case 10: 
      case 11: 
      case 12: 
      case 13: 
      case 14: 
        return "UTF-8";
      }
    }
    int i = value.getIndex();
    int end = value.putIndex();
    int state = 0;
    int start = 0;
    boolean quote = false;
    for (; i < end; i++)
    {
      byte b = value.peek(i);
      if ((quote) && (state != 10))
      {
        if (34 == b) {
          quote = false;
        }
      }
      else {
        switch (state)
        {
        case 0: 
          if (34 == b) {
            quote = true;
          } else if (59 == b) {
            state = 1;
          }
          break;
        case 1: 
          if (99 == b) {
            state = 2;
          } else if (32 != b) {
            state = 0;
          }
          break;
        case 2: 
          if (104 == b) {
            state = 3;
          } else {
            state = 0;
          }
          break;
        case 3: 
          if (97 == b) {
            state = 4;
          } else {
            state = 0;
          }
          break;
        case 4: 
          if (114 == b) {
            state = 5;
          } else {
            state = 0;
          }
          break;
        case 5: 
          if (115 == b) {
            state = 6;
          } else {
            state = 0;
          }
          break;
        case 6: 
          if (101 == b) {
            state = 7;
          } else {
            state = 0;
          }
          break;
        case 7: 
          if (116 == b) {
            state = 8;
          } else {
            state = 0;
          }
          break;
        case 8: 
          if (61 == b) {
            state = 9;
          } else if (32 != b) {
            state = 0;
          }
          break;
        case 9: 
          if (32 != b) {
            if (34 == b)
            {
              quote = true;
              start = i + 1;
              state = 10;
            }
            else
            {
              start = i;
              state = 10;
            }
          }
          break;
        case 10: 
          if (((!quote) && ((59 == b) || (32 == b))) || ((quote) && (34 == b))) {
            return CACHE.lookup(value.peek(start, i - start)).toString();
          }
          break;
        }
      }
    }
    if (state == 10) {
      return CACHE.lookup(value.peek(start, i - start)).toString();
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.mortbay.jetty.MimeTypes
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.mortbay.jetty;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import org.mortbay.io.Buffer;
import org.mortbay.io.ByteArrayBuffer;
import org.mortbay.io.View;
import org.mortbay.resource.Resource;

public class ResourceCache$Content
  implements HttpContent
{
  String _key;
  Resource _resource;
  long _lastModified;
  Content _prev;
  Content _next;
  Buffer _lastModifiedBytes;
  Buffer _contentType;
  Buffer _buffer;
  private final ResourceCache this$0;
  
  ResourceCache$Content(ResourceCache paramResourceCache, Resource resource)
  {
    _resource = resource;
    
    _next = this;
    _prev = this;
    _contentType = ResourceCache.access$000(paramResourceCache).getMimeByExtension(_resource.toString());
    
    _lastModified = resource.lastModified();
  }
  
  void cache(String pathInContext)
  {
    _key = pathInContext;
    _next = this$0._mostRecentlyUsed;
    this$0._mostRecentlyUsed = this;
    if (_next != null) {
      _next._prev = this;
    }
    _prev = null;
    if (this$0._leastRecentlyUsed == null) {
      this$0._leastRecentlyUsed = this;
    }
    this$0._cache.put(_key, this);
    this$0._cachedSize += _buffer.length();
    this$0._cachedFiles += 1;
    if
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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