Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplified HttpInput lock design
  • Loading branch information
gregw committed Jul 15, 2013
1 parent 9f5f7e9 commit 5d3760b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
20 changes: 16 additions & 4 deletions jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java
Expand Up @@ -63,13 +63,22 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl

protected State _state = BLOCKING;
private State _eof=null;

private final Object _lock;

protected HttpInput()
{
this(null);
}

protected HttpInput(Object lock)
{
_lock=lock==null?this:lock;
}

public abstract Object lock();
public final Object lock()
{
return _lock;
}

public void recycle()
{
Expand Down Expand Up @@ -431,7 +440,10 @@ public String toString()

public void init(HttpChannelState state)
{
_channelState=state;
synchronized (lock())
{
_channelState=state;
}
}

}
Expand Up @@ -53,7 +53,6 @@ public void recycle()
}
}


@Override
protected void blockForContent() throws IOException
{
Expand All @@ -74,12 +73,6 @@ public String toString()
{
return String.format("%s@%x",getClass().getSimpleName(),hashCode());
}

@Override
public Object lock()
{
return this;
}

@Override
protected ByteBuffer nextContent() throws IOException
Expand Down Expand Up @@ -120,7 +113,6 @@ protected ByteBuffer nextContent() throws IOException
}
return null;
}

}

return null;
Expand Down
Expand Up @@ -42,16 +42,10 @@ public abstract class QueuedHttpInput<T> extends HttpInput<T>
{
private final static Logger LOG = Log.getLogger(QueuedHttpInput.class);

private final ArrayQueue<T> _inputQ = new ArrayQueue<>();
private final ArrayQueue<T> _inputQ = new ArrayQueue<>(lock());

public QueuedHttpInput()
{
}

public Object lock()
{
return _inputQ.lock();
}
{}

public void recycle()
{
Expand Down
Expand Up @@ -48,6 +48,12 @@ public ArrayQueue()
{
this(DEFAULT_CAPACITY, -1);
}

/* ------------------------------------------------------------ */
public ArrayQueue(Object lock)
{
this(DEFAULT_CAPACITY, -1,lock);
}

/* ------------------------------------------------------------ */
public ArrayQueue(int capacity)
Expand Down

0 comments on commit 5d3760b

Please sign in to comment.