Merged branch 'jetty-9.4.x' into 'master'.
This commit is contained in:
commit
8f5985e0e1
|
@ -22,7 +22,9 @@ import java.io.Closeable;
|
|||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
@ -35,7 +37,6 @@ import org.eclipse.jetty.client.Synchronizable;
|
|||
import org.eclipse.jetty.client.api.ContentProvider;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
||||
|
@ -90,7 +91,7 @@ public class DeferredContentProvider implements AsyncContentProvider, Callback,
|
|||
private static final Chunk CLOSE = new Chunk(BufferUtil.EMPTY_BUFFER, Callback.NOOP);
|
||||
|
||||
private final Object lock = this;
|
||||
private final ArrayQueue<Chunk> chunks = new ArrayQueue<>(4, 64, lock);
|
||||
private final Deque<Chunk> chunks = new ArrayDeque<>();
|
||||
private final AtomicReference<Listener> listener = new AtomicReference<>();
|
||||
private final DeferredContentProviderIterator iterator = new DeferredContentProviderIterator();
|
||||
private final AtomicBoolean closed = new AtomicBoolean();
|
||||
|
@ -259,7 +260,7 @@ public class DeferredContentProvider implements AsyncContentProvider, Callback,
|
|||
{
|
||||
// Slow path: reinsert the CLOSE chunk
|
||||
// so that hasNext() works correctly.
|
||||
chunks.add(0, CLOSE);
|
||||
chunks.offerFirst(CLOSE);
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return chunk == null ? null : chunk.buffer;
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.net.InetSocketAddress;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -52,7 +53,6 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
|
|||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.Promise;
|
||||
|
@ -156,7 +156,7 @@ public class PrefaceTest extends AbstractTest
|
|||
List<ByteBuffer> buffers = lease.getByteBuffers();
|
||||
socket.write(buffers.toArray(new ByteBuffer[buffers.size()]));
|
||||
|
||||
Queue<SettingsFrame> settings = new ArrayQueue<>();
|
||||
Queue<SettingsFrame> settings = new ArrayDeque<>();
|
||||
Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter()
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
|
@ -29,7 +30,6 @@ import org.eclipse.jetty.http2.frames.Frame;
|
|||
import org.eclipse.jetty.http2.frames.WindowUpdateFrame;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.IteratingCallback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -40,7 +40,7 @@ public class HTTP2Flusher extends IteratingCallback
|
|||
private static final Logger LOG = Log.getLogger(HTTP2Flusher.class);
|
||||
|
||||
private final Queue<WindowEntry> windows = new ArrayDeque<>();
|
||||
private final ArrayQueue<Entry> frames = new ArrayQueue<>(ArrayQueue.DEFAULT_CAPACITY, ArrayQueue.DEFAULT_GROWTH, this);
|
||||
private final Deque<Entry> frames = new ArrayDeque<>();
|
||||
private final Queue<Entry> entries = new ArrayDeque<>();
|
||||
private final List<Entry> actives = new ArrayList<>();
|
||||
private final HTTP2Session session;
|
||||
|
@ -76,7 +76,7 @@ public class HTTP2Flusher extends IteratingCallback
|
|||
closed = terminated;
|
||||
if (!closed)
|
||||
{
|
||||
frames.add(0, entry);
|
||||
frames.offerFirst(entry);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Prepended {}, frames={}", entry, frames.size());
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -81,7 +81,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
|||
|
||||
private final Locker _locker = new Locker();
|
||||
private final Condition _hasOutput = _locker.newCondition();
|
||||
private final Queue<ByteBuffer> _inQ = new ArrayQueue<>();
|
||||
private final Queue<ByteBuffer> _inQ = new ArrayDeque<>();
|
||||
private ByteBuffer _out;
|
||||
private boolean _growOutput;
|
||||
|
||||
|
@ -325,7 +325,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
|||
getWriteFlusher().completeWrite();
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Wait for some output
|
||||
* @param time Time to wait
|
||||
|
@ -541,7 +541,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
|
|||
String o;
|
||||
try(Locker.Lock lock = _locker.lock())
|
||||
{
|
||||
q=_inQ.size();
|
||||
q=_inQ.size();
|
||||
b=_inQ.peek();
|
||||
o=BufferUtil.toDetailString(_out);
|
||||
}
|
||||
|
|
|
@ -1,432 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Queue backed by circular array.
|
||||
* <p>
|
||||
* This partial Queue implementation (also with {@link #remove()} for stack operation)
|
||||
* is backed by a growable circular array.
|
||||
* </p>
|
||||
*
|
||||
* @param <E> the type of object the queue holds
|
||||
*/
|
||||
public class ArrayQueue<E> extends AbstractList<E> implements Queue<E>
|
||||
{
|
||||
public static final int DEFAULT_CAPACITY = 64;
|
||||
public static final int DEFAULT_GROWTH = 32;
|
||||
|
||||
protected final Object _lock;
|
||||
protected final int _growCapacity;
|
||||
protected Object[] _elements;
|
||||
protected int _nextE;
|
||||
protected int _nextSlot;
|
||||
protected int _size;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ArrayQueue()
|
||||
{
|
||||
this(DEFAULT_CAPACITY, -1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ArrayQueue(Object lock)
|
||||
{
|
||||
this(DEFAULT_CAPACITY, -1,lock);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ArrayQueue(int capacity)
|
||||
{
|
||||
this(capacity, -1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ArrayQueue(int initCapacity, int growBy)
|
||||
{
|
||||
this(initCapacity, growBy, null);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ArrayQueue(int initCapacity, int growBy, Object lock)
|
||||
{
|
||||
_lock = lock == null ? this : lock;
|
||||
_growCapacity = growBy;
|
||||
_elements = new Object[initCapacity];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object lock()
|
||||
{
|
||||
return _lock;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int getCapacity()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
return _elements.length;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the next slot to be used
|
||||
*/
|
||||
public int getNextSlotUnsafe()
|
||||
{
|
||||
return _nextSlot;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean add(E e)
|
||||
{
|
||||
if (!offer(e))
|
||||
throw new IllegalStateException("Full");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean offer(E e)
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
return enqueue(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected boolean enqueue(E e)
|
||||
{
|
||||
if (_size == _elements.length && !growUnsafe())
|
||||
return false;
|
||||
|
||||
_size++;
|
||||
_elements[_nextSlot++] = e;
|
||||
if (_nextSlot == _elements.length)
|
||||
_nextSlot = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Add without synchronization or bounds checking
|
||||
*
|
||||
* @param e the element to add
|
||||
* @see #add(Object)
|
||||
*/
|
||||
public void addUnsafe(E e)
|
||||
{
|
||||
if (!enqueue(e))
|
||||
throw new IllegalStateException("Full");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E element()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (isEmpty())
|
||||
throw new NoSuchElementException();
|
||||
return at(_nextE);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@SuppressWarnings("unchecked")
|
||||
private E at(int index)
|
||||
{
|
||||
return (E)_elements[index];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E peek()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (_size == 0)
|
||||
return null;
|
||||
return at(_nextE);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E peekUnsafe()
|
||||
{
|
||||
if (_size == 0)
|
||||
return null;
|
||||
return at(_nextE);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E poll()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (_size == 0)
|
||||
return null;
|
||||
return dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E pollUnsafe()
|
||||
{
|
||||
if (_size == 0)
|
||||
return null;
|
||||
return dequeue();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected E dequeue()
|
||||
{
|
||||
E e = at(_nextE);
|
||||
_elements[_nextE] = null;
|
||||
_size--;
|
||||
if (++_nextE == _elements.length)
|
||||
_nextE = 0;
|
||||
return e;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public E remove()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (_size == 0)
|
||||
throw new NoSuchElementException();
|
||||
return dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
_size = 0;
|
||||
_nextE = 0;
|
||||
_nextSlot = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int sizeUnsafe()
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public E get(int index)
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (index < 0 || index >= _size)
|
||||
throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
|
||||
return getUnsafe(index);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Get without synchronization or bounds checking.
|
||||
*
|
||||
* @param index index of the element to return
|
||||
* @return the element at the specified index
|
||||
* @see #get(int)
|
||||
*/
|
||||
public E getUnsafe(int index)
|
||||
{
|
||||
int i = (_nextE + index) % _elements.length;
|
||||
return at(i);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public E remove(int index)
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (index < 0 || index >= _size)
|
||||
throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
|
||||
|
||||
int i = (_nextE + index) % _elements.length;
|
||||
E old = at(i);
|
||||
|
||||
if (i < _nextSlot)
|
||||
{
|
||||
// 0 _elements.length
|
||||
// _nextE........._nextSlot
|
||||
System.arraycopy(_elements, i + 1, _elements, i, _nextSlot - i);
|
||||
_nextSlot--;
|
||||
_size--;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 0 _elements.length
|
||||
// ......_nextSlot _nextE..........
|
||||
System.arraycopy(_elements, i + 1, _elements, i, _elements.length - i - 1);
|
||||
if (_nextSlot > 0)
|
||||
{
|
||||
_elements[_elements.length - 1] = _elements[0];
|
||||
System.arraycopy(_elements, 1, _elements, 0, _nextSlot - 1);
|
||||
_nextSlot--;
|
||||
}
|
||||
else
|
||||
_nextSlot = _elements.length - 1;
|
||||
|
||||
_size--;
|
||||
}
|
||||
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public E set(int index, E element)
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (index < 0 || index >= _size)
|
||||
throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
|
||||
|
||||
int i = _nextE + index;
|
||||
if (i >= _elements.length)
|
||||
i -= _elements.length;
|
||||
E old = at(i);
|
||||
_elements[i] = element;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void add(int index, E element)
|
||||
{
|
||||
synchronized (_lock)
|
||||
{
|
||||
if (index < 0 || index > _size)
|
||||
throw new IndexOutOfBoundsException("!(" + 0 + "<" + index + "<=" + _size + ")");
|
||||
|
||||
if (_size == _elements.length && !growUnsafe())
|
||||
throw new IllegalStateException("Full");
|
||||
|
||||
if (index == _size)
|
||||
{
|
||||
add(element);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = _nextE + index;
|
||||
if (i >= _elements.length)
|
||||
i -= _elements.length;
|
||||
|
||||
_size++;
|
||||
_nextSlot++;
|
||||
if (_nextSlot == _elements.length)
|
||||
_nextSlot = 0;
|
||||
|
||||
if (i < _nextSlot)
|
||||
{
|
||||
// 0 _elements.length
|
||||
// _nextE.....i..._nextSlot
|
||||
// 0 _elements.length
|
||||
// ..i..._nextSlot _nextE..........
|
||||
System.arraycopy(_elements, i, _elements, i + 1, _nextSlot - i);
|
||||
_elements[i] = element;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 0 _elements.length
|
||||
// ......_nextSlot _nextE.....i....
|
||||
if (_nextSlot > 0)
|
||||
{
|
||||
System.arraycopy(_elements, 0, _elements, 1, _nextSlot);
|
||||
_elements[0] = _elements[_elements.length - 1];
|
||||
}
|
||||
|
||||
System.arraycopy(_elements, i, _elements, i + 1, _elements.length - i - 1);
|
||||
_elements[i] = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void resizeUnsafe(int newCapacity)
|
||||
{
|
||||
newCapacity = Math.max(newCapacity,_size);
|
||||
Object[] elements = new Object[newCapacity];
|
||||
|
||||
if (_size>0)
|
||||
{
|
||||
if (_nextSlot>_nextE)
|
||||
System.arraycopy(_elements, _nextE, elements, 0, _size);
|
||||
else
|
||||
{
|
||||
int split = _elements.length - _nextE;
|
||||
System.arraycopy(_elements, _nextE, elements, 0, split);
|
||||
System.arraycopy(_elements, 0, elements, split, _nextSlot);
|
||||
}
|
||||
}
|
||||
_elements = elements;
|
||||
_nextE = 0;
|
||||
_nextSlot = _size;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected boolean growUnsafe()
|
||||
{
|
||||
if (_growCapacity <= 0)
|
||||
return false;
|
||||
resizeUnsafe(_elements.length+_growCapacity);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ArrayQueueTest
|
||||
{
|
||||
@Test
|
||||
public void testWrap() throws Exception
|
||||
{
|
||||
ArrayQueue<String> queue = new ArrayQueue<String>(3,3);
|
||||
|
||||
assertEquals(0,queue.size());
|
||||
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
queue.offer("one");
|
||||
assertEquals(1,queue.size());
|
||||
|
||||
queue.offer("two");
|
||||
assertEquals(2,queue.size());
|
||||
|
||||
queue.offer("three");
|
||||
assertEquals(3,queue.size());
|
||||
|
||||
assertEquals("one",queue.get(0));
|
||||
assertEquals("two",queue.get(1));
|
||||
assertEquals("three",queue.get(2));
|
||||
|
||||
assertEquals("[one, two, three]",queue.toString());
|
||||
|
||||
assertEquals("two",queue.remove(1));
|
||||
assertEquals(2,queue.size());
|
||||
|
||||
assertEquals("one",queue.remove());
|
||||
assertEquals(1,queue.size());
|
||||
|
||||
assertEquals("three",queue.poll());
|
||||
assertEquals(0,queue.size());
|
||||
|
||||
assertEquals(null,queue.poll());
|
||||
|
||||
queue.offer("xxx");
|
||||
queue.offer("xxx");
|
||||
assertEquals(2,queue.size());
|
||||
assertEquals("xxx",queue.poll());
|
||||
assertEquals("xxx",queue.poll());
|
||||
assertEquals(0,queue.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() throws Exception
|
||||
{
|
||||
ArrayQueue<String> queue = new ArrayQueue<String>(3,3);
|
||||
|
||||
queue.add("0");
|
||||
queue.add("x");
|
||||
|
||||
for (int i=1;i<100;i++)
|
||||
{
|
||||
queue.add(""+i);
|
||||
queue.add("x");
|
||||
queue.remove(queue.size()-3);
|
||||
queue.set(queue.size()-3,queue.get(queue.size()-3)+"!");
|
||||
}
|
||||
|
||||
for (int i=0;i<99;i++)
|
||||
assertEquals(i+"!",queue.get(i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrow() throws Exception
|
||||
{
|
||||
ArrayQueue<String> queue = new ArrayQueue<String>(3,5);
|
||||
assertEquals(3,queue.getCapacity());
|
||||
|
||||
queue.add("0");
|
||||
queue.add("a");
|
||||
queue.add("b");
|
||||
assertEquals(3,queue.getCapacity());
|
||||
queue.add("c");
|
||||
assertEquals(8,queue.getCapacity());
|
||||
|
||||
for (int i=0;i<4;i++)
|
||||
queue.add(""+('d'+i));
|
||||
assertEquals(8,queue.getCapacity());
|
||||
for (int i=0;i<4;i++)
|
||||
queue.poll();
|
||||
assertEquals(8,queue.getCapacity());
|
||||
for (int i=0;i<4;i++)
|
||||
queue.add(""+('d'+i));
|
||||
assertEquals(8,queue.getCapacity());
|
||||
for (int i=0;i<4;i++)
|
||||
queue.poll();
|
||||
assertEquals(8,queue.getCapacity());
|
||||
for (int i=0;i<4;i++)
|
||||
queue.add(""+('d'+i));
|
||||
assertEquals(8,queue.getCapacity());
|
||||
|
||||
queue.add("z");
|
||||
assertEquals(13,queue.getCapacity());
|
||||
|
||||
queue.clear();
|
||||
assertEquals(13,queue.getCapacity());
|
||||
for (int i=0;i<12;i++)
|
||||
queue.add(""+('a'+i));
|
||||
assertEquals(13,queue.getCapacity());
|
||||
queue.clear();
|
||||
assertEquals(13,queue.getCapacity());
|
||||
for (int i=0;i<12;i++)
|
||||
queue.add(""+('a'+i));
|
||||
assertEquals(13,queue.getCapacity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullEmpty() throws Exception
|
||||
{
|
||||
ArrayQueue<String> queue = new ArrayQueue<String>(2);
|
||||
assertTrue(queue.offer("one"));
|
||||
assertTrue(queue.offer("two"));
|
||||
assertFalse(queue.offer("three"));
|
||||
|
||||
try
|
||||
{
|
||||
queue.add("four");
|
||||
assertTrue(false);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
assertEquals("one",queue.peek());
|
||||
assertEquals("one",queue.remove());
|
||||
assertEquals("two",queue.remove());
|
||||
try
|
||||
{
|
||||
assertEquals("three",queue.remove());
|
||||
assertTrue(false);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
assertEquals(null,queue.poll());
|
||||
}
|
||||
|
||||
}
|
|
@ -20,14 +20,15 @@ package org.eclipse.jetty.websocket.common.io;
|
|||
|
||||
import java.io.EOFException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IteratingCallback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -163,7 +164,7 @@ public class FrameFlusher
|
|||
{
|
||||
while ((entries.size() <= maxGather) && !queue.isEmpty())
|
||||
{
|
||||
FrameEntry entry = queue.remove(0);
|
||||
FrameEntry entry = queue.poll();
|
||||
currentBatchMode = BatchMode.max(currentBatchMode,entry.batchMode);
|
||||
|
||||
// Force flush if we need to.
|
||||
|
@ -293,7 +294,7 @@ public class FrameFlusher
|
|||
private final Generator generator;
|
||||
private final int maxGather;
|
||||
private final Object lock = new Object();
|
||||
private final ArrayQueue<FrameEntry> queue = new ArrayQueue<>(16,16,lock);
|
||||
private final Deque<FrameEntry> queue = new ArrayDeque<>();
|
||||
private final Flusher flusher;
|
||||
private final AtomicBoolean closed = new AtomicBoolean();
|
||||
private volatile Throwable failure;
|
||||
|
@ -353,7 +354,7 @@ public class FrameFlusher
|
|||
case OpCode.PING:
|
||||
{
|
||||
// Prepend PINGs so they are processed first.
|
||||
queue.add(0,entry);
|
||||
queue.offerFirst(entry);
|
||||
break;
|
||||
}
|
||||
case OpCode.CLOSE:
|
||||
|
@ -362,12 +363,12 @@ public class FrameFlusher
|
|||
// added after this close frame, but we will
|
||||
// fail them later to keep it simple here.
|
||||
closed.set(true);
|
||||
queue.add(entry);
|
||||
queue.offer(entry);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
queue.add(entry);
|
||||
queue.offer(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ import java.util.ServiceLoader;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.eclipse.jetty.util.ArrayQueue;
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
import org.eclipse.jetty.util.Loader;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
@ -84,7 +83,7 @@ public class XmlConfiguration
|
|||
private static final Class<?>[] __boxedPrimitives =
|
||||
{Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Void.class};
|
||||
private static final Class<?>[] __supportedCollections =
|
||||
{ArrayList.class, ArrayQueue.class, HashSet.class, Queue.class, List.class, Set.class, Collection.class};
|
||||
{ArrayList.class, HashSet.class, Queue.class, List.class, Set.class, Collection.class};
|
||||
private static final Iterable<ConfigurationProcessorFactory> __factoryLoader = ServiceLoader.load(ConfigurationProcessorFactory.class);
|
||||
private static final XmlParser __parser = initParser();
|
||||
private static XmlParser initParser()
|
||||
|
@ -605,12 +604,6 @@ public class XmlConfiguration
|
|||
collection = convertArrayToArrayList(array);
|
||||
else if (collectionType.isAssignableFrom(HashSet.class))
|
||||
collection = new HashSet<>(convertArrayToArrayList(array));
|
||||
else if (collectionType.isAssignableFrom(ArrayQueue.class))
|
||||
{
|
||||
ArrayQueue<Object> q= new ArrayQueue<>();
|
||||
q.addAll(convertArrayToArrayList(array));
|
||||
collection=q;
|
||||
}
|
||||
}
|
||||
if (collection==null)
|
||||
throw new IllegalArgumentException("Can't convert \"" + array.getClass() + "\" to " + collectionType);
|
||||
|
|
Loading…
Reference in New Issue