Example usage for org.apache.commons.collections BufferUtils synchronizedBuffer

List of usage examples for org.apache.commons.collections BufferUtils synchronizedBuffer

Introduction

In this page you can find the example usage for org.apache.commons.collections BufferUtils synchronizedBuffer.

Prototype

public static Buffer synchronizedBuffer(Buffer buffer) 

Source Link

Document

Returns a synchronized buffer backed by the given buffer.

Usage

From source file:messageit.dispatcher.MessageQueue.java

/** Creates an empty MessageQueue */
public MessageQueue() {
    qNorm = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer(32));

    qHigh = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer(16));
}

From source file:org.graylog2.log4j.MemoryAppender.java

protected MemoryAppender(String name, Filter filter, Layout<? extends Serializable> layout,
        boolean ignoreExceptions, int bufferSize) {
    super(name, filter, layout, ignoreExceptions);
    this.bufferSize = bufferSize;
    this.buffer = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(bufferSize));
}

From source file:org.opencms.main.CmsSessionInfo.java

/**
 * Returns the broadcast queue of the user to which this session info belongs.<p>
 * //from  w w w .  j a v  a  2 s  .c o m
 * @return the broadcast queue of the user to which this session info belongs
 */
public Buffer getBroadcastQueue() {

    if (m_broadcastQueue == null) {
        m_broadcastQueue = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer(QUEUE_SIZE));
    }
    return m_broadcastQueue;
}

From source file:org.opencms.main.CmsSessionManager.java

/**
 * Returns the broadcast queue for the given OpenCms session id.<p>
 * /*from   www. j  a v  a 2  s  . co m*/
 * @param sessionId the OpenCms session id to get the broadcast queue for
 * 
 * @return the broadcast queue for the given OpenCms session id
 */
public Buffer getBroadcastQueue(String sessionId) {

    CmsSessionInfo sessionInfo = getSessionInfo(getSessionUUID(sessionId));
    if (sessionInfo == null) {
        // return empty message buffer if the session is gone or not available
        return BufferUtils.synchronizedBuffer(new CircularFifoBuffer(CmsSessionInfo.QUEUE_SIZE));
    }
    return sessionInfo.getBroadcastQueue();
}

From source file:org.opencms.publish.CmsPublishHistory.java

/**
 * Returns (and initializes) the queue.<p>
 * //from   w  w w  . ja  v a2s . com
 * @param size the history size
 * 
 * @return the queue buffer
 */
public static Buffer getQueue(int size) {

    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(
                Messages.get().getBundle().key(Messages.INIT_PUBLISH_HISTORY_SIZE_SET_1, new Integer(size)));
    }

    return BufferUtils.synchronizedBuffer(TypedBuffer.decorate(new CircularFifoBuffer(size) {

        /** The serialization version id constant. */
        private static final long serialVersionUID = -6257542123241183114L;

        /**
         * Called when the queue is full to remove the oldest element.<p>
         * 
         * @see org.apache.commons.collections.buffer.BoundedFifoBuffer#remove()
         */
        @Override
        public Object remove() {

            CmsPublishJobInfoBean publishJob = (CmsPublishJobInfoBean) super.remove();
            try {
                OpenCms.getPublishManager().getEngine().getPublishHistory().remove(publishJob);
            } catch (CmsException exc) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(exc.getLocalizedMessage(), exc);
                }
            }
            return publishJob;
        }
    }, CmsPublishJobInfoBean.class));
}

From source file:org.opencms.publish.CmsPublishQueue.java

/**
 * Creates the buffer used as publish queue.<p>
 * //from   w ww . j a  va  2  s  . c o  m
 * @return the queue buffer
 */
public static Buffer getQueue() {

    return BufferUtils.synchronizedBuffer(TypedBuffer.decorate(new UnboundedFifoBuffer() {

        /** The serialization version id constant. */
        private static final long serialVersionUID = 606444342980861724L;

        /**
         * Called when the queue is full to remove the oldest element.<p>
         * 
         * @see org.apache.commons.collections.buffer.BoundedFifoBuffer#remove()
         */
        @Override
        public Object remove() {

            CmsPublishJobInfoBean publishJob = (CmsPublishJobInfoBean) super.remove();
            return publishJob;
        }
    }, CmsPublishJobInfoBean.class));
}

From source file:org.paxle.tools.logging.impl.ALogReader.java

@OverrideMustInvoke
@Activate/* www .j a va2  s  . com*/
protected void activate(Map<String, Object> props) {
    // configuring the buffer
    Integer bufferSize = Integer.valueOf(200);
    if (props.containsKey(BUFFER_SIZE)) {
        bufferSize = (Integer) props.get(BUFFER_SIZE);
    }
    this.fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(bufferSize));
}

From source file:org.perfcake.reporting.reporters.accumulators.AbstractSlidingWindowAccumulator.java

/**
 * Creates a new accumulator with the sliding window of a given size.
 *
 * @param windowSize/*w  ww .j  a va 2  s.  c  o m*/
 *       Size of the sliding window.
 */
public AbstractSlidingWindowAccumulator(final int windowSize) {
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(windowSize));
}

From source file:sintef.android.controller.sensor.SensorEventBuffer.java

private SensorEventBuffer() {
    /*//from ww  w. j a  va 2  s .  c  o m
    The buffer needs to hold at least two seconds worth of sensor events.
    The frequency is set to around 25Hz as we were not able to set it any higher.
    Therefor the size of the buffer is set to 3 * 25
     */
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(3 * 25));
}

From source file:sintef.android.controller.sensor.SensorEventBuffer.java

private SensorEventBuffer(int frequency) {
    /*/*from  w ww.  ja  v  a2  s  . c  o m*/
    Planned for the future: Get the actual maximum frequency of sensor events and
    use this value to instantiated the buffer.
     */
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(3 * frequency));
}