Example usage for java.util.concurrent ConcurrentLinkedQueue add

List of usage examples for java.util.concurrent ConcurrentLinkedQueue add

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentLinkedQueue add.

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element at the tail of this queue.

Usage

From source file:com.ibm.crail.tools.CrailBenchmark.java

void readMultiStream(String filename, int size, int loop, int batch) throws Exception {
    System.out.println(// w  w  w. ja  v  a2 s. co  m
            "readMultiStream, filename " + filename + ", size " + size + ", loop " + loop + ", batch " + batch);

    //warmup
    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    for (int i = 0; i < warmup; i++) {
        CrailBuffer buf = fs.allocateBuffer().limit(size).slice();
        bufferQueue.add(buf);
    }
    warmUp(filename, warmup, bufferQueue);
    while (!bufferQueue.isEmpty()) {
        CrailBuffer buf = bufferQueue.poll();
        fs.freeBuffer(buf);
    }

    //benchmark
    System.out.println("starting benchmark...");
    fs.getStatistics().reset();
    CrailBuffer _buf = null;
    if (size == CrailConstants.BUFFER_SIZE) {
        _buf = fs.allocateBuffer();
    } else if (size < CrailConstants.BUFFER_SIZE) {
        CrailBuffer __buf = fs.allocateBuffer();
        __buf.clear().limit(size);
        _buf = __buf.slice();
    } else {
        _buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
    }
    ByteBuffer buf = _buf.getByteBuffer();
    for (int i = 0; i < loop; i++) {
        CrailBufferedInputStream multiStream = fs.lookup(filename).get().asMultiFile().getMultiStream(batch);
        double sumbytes = 0;
        long _sumbytes = 0;
        double ops = 0;
        buf.clear();
        long start = System.currentTimeMillis();
        int ret = multiStream.read(buf);
        while (ret >= 0) {
            sumbytes = sumbytes + ret;
            long _ret = (long) ret;
            _sumbytes += _ret;
            ops = ops + 1.0;
            buf.clear();
            ret = multiStream.read(buf);
        }
        long end = System.currentTimeMillis();
        multiStream.close();

        double executionTime = ((double) (end - start)) / 1000.0;
        double throughput = 0.0;
        double latency = 0.0;
        double sumbits = sumbytes * 8.0;
        if (executionTime > 0) {
            throughput = sumbits / executionTime / 1000.0 / 1000.0;
            latency = 1000000.0 * executionTime / ops;
        }

        System.out.println("round " + i + ":");
        System.out.println("bytes read " + _sumbytes);
        System.out.println("execution time " + executionTime);
        System.out.println("ops " + ops);
        System.out.println("throughput " + throughput);
        System.out.println("latency " + latency);
    }

    fs.getStatistics().print("close");
}

From source file:com.google.cloud.dns.testing.LocalDnsHelper.java

/**
 * Creates a new change, stores it, and if delayChange > 0, invokes processing in a new thread.
 *///from   ww  w . ja  v a2s . com
Response createChange(String projectId, String zoneName, Change change, String... fields) {
    ZoneContainer zoneContainer = findZone(projectId, zoneName);
    if (zoneContainer == null) {
        return Error.NOT_FOUND.response(
                String.format("The 'parameters.managedZone' resource named %s does not exist.", zoneName));
    }
    Response response = checkChange(change, zoneContainer);
    if (response != null) {
        return response;
    }
    Change completeChange = new Change();
    if (change.getAdditions() != null) {
        completeChange.setAdditions(ImmutableList.copyOf(change.getAdditions()));
    }
    if (change.getDeletions() != null) {
        completeChange.setDeletions(ImmutableList.copyOf(change.getDeletions()));
    }
    /* We need to set ID for the change. We are working in concurrent environment. We know that the
    element fell on an index between 1 and maxId (index 0 is the default change which creates SOA
    and NS), so we will reset all IDs between 0 and maxId (all of them are valid for the respective
    objects). */
    ConcurrentLinkedQueue<Change> changeSequence = zoneContainer.changes();
    changeSequence.add(completeChange);
    int maxId = changeSequence.size();
    int index = 0;
    for (Change c : changeSequence) {
        if (index == maxId) {
            break;
        }
        c.setId(String.valueOf(index++));
    }
    completeChange.setStatus("pending");
    completeChange.setStartTime(ISODateTimeFormat.dateTime().withZoneUTC().print(System.currentTimeMillis()));
    invokeChange(projectId, zoneName, completeChange.getId());
    Change result = OptionParsers.extractFields(completeChange, fields);
    try {
        return new Response(HTTP_OK, jsonFactory.toString(result));
    } catch (IOException e) {
        return Error.INTERNAL_ERROR
                .response(String.format("Error when serializing change %s in managed zone %s in project %s.",
                        result.getId(), zoneName, projectId));
    }
}

From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java

@Override
public void outgoAMessage(String outgoingIndex, IMessage msg) {
    // Evaluate the length of the msg, 16 means 1 long and 2 int.
    int length = sizer.sizeOf(msg) + this.sizeOfRef;
    // Accumulate the total size of messages.
    this.totalSizeOfMessages = this.totalSizeOfMessages + length;
    this.totalCount = this.totalCount + 1;
    this.sizeOfMessagesDataInMem = this.sizeOfMessagesDataInMem + length;
    // Message number in memory
    this.countOfMessagesDataInMem = this.countOfMessagesDataInMem + 1;
    ConcurrentLinkedQueue<IMessage> queue = this.outgoingQueues.get(outgoingIndex);
    if (queue == null) {
        queue = new ConcurrentLinkedQueue<IMessage>();
        this.sizeOfHashMapsInMem = this.sizeOfHashMapsInMem
                + (sizeOfRef * 2 + (outgoingIndex.length() * sizeOfChar) + sizeOfEmptyMessageQueue);
    }// w w  w  . j a  va2s . com
    queue.add(msg);
    this.outgoingQueues.put(outgoingIndex, queue);
    // On a new message outgoed.
    onMessageOutgoed();
}

From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java

@Override
public void incomeAMessage(String dstVertexID, IMessage msg) {
    // Evaluate the length of the msg, 16 means 1 long and 2 int.
    int length = sizer.sizeOf(msg) + this.sizeOfRef;
    // Accumulate the total size of messages.
    this.totalSizeOfMessages = this.totalSizeOfMessages + length;
    this.totalCount = this.totalCount + 1;
    this.sizeOfMessagesDataInMem = this.sizeOfMessagesDataInMem + length;
    // Message number in memory
    this.countOfMessagesDataInMem = this.countOfMessagesDataInMem + 1;
    // Get the hash bucket index.
    int hashCode = dstVertexID.hashCode();
    int hashIndex = hashCode % this.hashBucketNumber; // bucket index
    hashIndex = (hashIndex < 0 ? hashIndex + this.hashBucketNumber : hashIndex);
    // Update the bucket meta data.
    BucketMeta meta = this.incomingQueues.get(hashIndex);
    meta.count = meta.count + 1;/*from   ww  w . ja v a  2 s .c  o m*/
    meta.countInMemory = meta.countInMemory + 1;
    meta.length = meta.length + length;
    meta.lengthInMemory = meta.lengthInMemory + length;
    // Add the msg into the incoming queue for the dstVertexID.
    ConcurrentLinkedQueue<IMessage> incomingQueue = meta.queueMap.get(dstVertexID);
    if (incomingQueue == null) {
        incomingQueue = new ConcurrentLinkedQueue<IMessage>();
        this.sizeOfHashMapsInMem = this.sizeOfHashMapsInMem
                + (sizeOfRef * 2 + (dstVertexID.length() * sizeOfChar) + sizeOfEmptyMessageQueue);
    }
    incomingQueue.add(msg);
    meta.queueMap.put(dstVertexID, incomingQueue);
    // On a new message added.
    onMessageIncomed();
}

From source file:org.restcomm.app.qoslib.Services.Events.EventUploader.java

public void report(boolean local, Location location) {
    try {//from w  w w  .j a  v a  2  s.  c  om
        //now create a list of eventData variables
        List<EventData> eventDataList = new ArrayList<EventData>();
        String strPhone = "";
        long duration = 0;

        EventDataEnvelope eventDataEnvelope = null;
        if (event != null) {
            // Dont send an unconfirmed Travel event
            if (event.getEventType() == EventType.TRAVEL_CHECK
                    && owner.getTravelDetector().isConfirmed() == false) {
                LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "report", "skip unconfirmed travel event");
                return;
            }

            EventData eventData = generateEventDataFromEvent(event, local);
            if (eventData == null)
                return;
            //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "run", "reporting event type=" + event.getEventType() + ",lat:" + eventData.getFltEventLat() + ",local=" + local);
            if (eventData.getFltEventLat() == 0 && location != null) {
                eventData.setFltEventLat((float) location.getLatitude());
                eventData.setFltEventLng((float) location.getLongitude());
                eventData.setiUncertainty((int) location.getAccuracy());
            }
            eventData.setCallID(event.getLocalID());
            EventData eventData2 = null;
            eventDataList.add(eventData);

            if (event.getEventType() == EventType.APP_MONITORING && event.getDownloadSpeed() > 0
                    && event.getUploadSpeed() > 0) {
                //App throughput was getting stored twice
                boolean stored = PreferenceManager.getDefaultSharedPreferences(owner)
                        .getBoolean(PreferenceKeys.Miscellaneous.THROUGHPUT_STORED, false);
                if (!stored) {
                    owner.getReportManager().storeEvent(eventData);
                    PreferenceManager.getDefaultSharedPreferences(owner).edit()
                            .putBoolean(PreferenceKeys.Miscellaneous.THROUGHPUT_STORED, true).commit();
                } else
                    PreferenceManager.getDefaultSharedPreferences(owner).edit()
                            .putBoolean(PreferenceKeys.Miscellaneous.THROUGHPUT_STORED, false).commit();
                ;
            }
            if (event.getEventType() == EventType.MAN_PLOTTING) {
                eventData.setLookupid1(event.getBuildingID());
                eventData.setRunningApps(event.getAppData()); // contains user's polyline
            }

            // Event is 'reported' locally before GPS sampling is complete
            // to make it show up on the map as soon as it gets a first fix
            //if (local == true && ((event.getEventType() != EventType.MAN_SPEEDTEST && event.getEventType() != EventType.LATENCY_TEST && event.getEventType() != EventType.APP_MONITORING) || event.latency != 0))
            //if (local == true && (event.getEventType().waitsForSpeed() == false || event.getLatency() != 0))
            //   (local == false && event.getEventType() == EventType.MAN_SPEEDTEST))  // but for speedtest, wait until complete
            if ((event.getEventType().waitsForSpeed() == false || event.getLatency() != 0)) {
                if (event.getLocalID() > 0 && eventData.getFltEventLng() != 0) {
                    owner.getReportManager().updateEventField(event.getLocalID(), Events.KEY_LATITUDE,
                            String.valueOf(eventData.getFltEventLat()));
                    owner.getReportManager().updateEventField(event.getLocalID(), Events.KEY_LONGITUDE,
                            String.valueOf(eventData.getFltEventLng()));
                } else if (event.getLocalID() == 0) {
                    int evtID = owner.getReportManager().storeEvent(eventData); // .reportEvent (eventData, event, local, location);
                    event.setLocalID(evtID);
                    eventData.setCallID(evtID);
                }
                if (complimentaryEvent != null) {
                    if (complimentaryEvent.getLocalID() > 0 && location != null) {
                        owner.getReportManager().updateEventField(complimentaryEvent.getLocalID(),
                                Events.KEY_LATITUDE, String.valueOf(location.getLatitude()));
                        owner.getReportManager().updateEventField(complimentaryEvent.getLocalID(),
                                Events.KEY_LONGITUDE, String.valueOf(location.getLongitude()));
                    } else if (complimentaryEvent.getLocalID() == 0) {
                        int evtID = owner.getReportManager().storeEvent(eventData); //(eventData2, complimentaryEvent, local, location);
                        complimentaryEvent.setLocalID(evtID);
                    }
                }
            }
            if (local)
                return;

            //if the complimentary event is not null, then this event must be
            //the "starting end" of an event couple. If so, then this event should
            //be uploaded alongside the main event
            if (complimentaryEvent != null && local == false) {
                eventData2 = generateEventDataFromEvent(complimentaryEvent, local);
                if (eventData2 != null) {
                    //complimentaryEvent.setFlag (EventObj.SERVER_SENDING, true);
                    eventData2.setCallID(complimentaryEvent.getLocalID());
                    eventDataList.add(eventData2);
                }
            }
            //now create the eventDataEnvelope to wrap the list of eventData variables
            //along with other required variables
            String phoneNumFirst4 = "";
            if (strPhone != null && strPhone.length() > 4)
                phoneNumFirst4 = strPhone.substring(0, 4);

            eventDataEnvelope = generateEventDataEnvFromEventList(eventDataList, phoneNumFirst4);
            // when event is filled in, travel and fillin would like to see it before sending
            if (owner.isServiceRunning() && owner.getTravelDetector() != null)
                owner.getTravelDetector().eventCompleted(event);
        } else // null event create dummy event envelope to trigger sending the event queue (without adding a new event)
            eventDataEnvelope = new EventDataEnvelope();

        boolean bSent = false, bFromQueue = false, bAddedQueue = false;
        loadEventsQueue(); // only loads if queue hasn't loaded yet (ensure loaded)
        ConcurrentLinkedQueue<EventDataEnvelope> eventQueue = owner.getEventManager().getEventQueue();

        // Send this event and any other events that were in the queue, as long as it didn't fail to send
        while (eventDataEnvelope != null) {
            bSent = uploadEventEnvelope(eventDataEnvelope, bFromQueue); // as long as event was sent to server, it sent (even if server had an error)
            if (!bSent) {
                //if (!bFromQueue)
                {
                    bAddedQueue = true;
                    eventQueue.add(eventDataEnvelope);
                    while (eventQueue.size() > 200)
                        eventQueue.poll();
                }
                break;
            } else {
                eventDataEnvelope = eventQueue.poll();
                bFromQueue = true;
            }
        }
        // persist the queue every 3 hrs in case something happens
        if (event != null && (event.isCheckin || bAddedQueue))
            saveEvents(eventQueue);
    } finally {
        if (!local) {
            //LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "report(false)", "uploadingEvent(false)");
            owner.uploadingEvent(false);

        }
    }
}

From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java

/**
 * Change String to queue./* w  w w .j ava  2 s .  c  om*/
 * @return ConcurrentLinkedQueue<IMessage>
 */
@SuppressWarnings("unchecked")
private ConcurrentLinkedQueue<IMessage> stringToQueue(String queueBuffer) {
    ConcurrentLinkedQueue<IMessage> queue = new ConcurrentLinkedQueue<IMessage>();
    if (queueBuffer != null) {
        String[] msgs = queueBuffer.split(Constants.SPACE_SPLIT_FLAG);
        for (int i = 0; i < msgs.length; i++) {
            // Note BSPMessage Is Temporayly Left.Should Be class.newInstance().
            // class Should Be Transferred In.
            IMessage msg = new BSPMessage();
            msg.fromString(msgs[i]);
            queue.add(msg);
        }
    }
    return queue;
}

From source file:org.opendaylight.vpnservice.elan.internal.ElanInterfaceManager.java

@Override
protected void add(InstanceIdentifier<ElanInterface> identifier, ElanInterface elanInterfaceAdded) {
    String elanInstanceName = elanInterfaceAdded.getElanInstanceName();
    String interfaceName = elanInterfaceAdded.getName();
    InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
    if (interfaceInfo == null) {
        logger.warn("Interface {} is removed from Interface Oper DS due to port down ", interfaceName);
        return;// ww w. ja  va 2s  .c  o  m
    }
    ElanInstance elanInstance = ElanUtils.getElanInstanceByName(elanInstanceName);

    if (elanInstance == null) {
        elanInstance = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
                .setDescription(elanInterfaceAdded.getDescription()).build();
        //Add the ElanInstance in the Configuration data-store
        ElanUtils.updateOperationalDataStore(broker, idManager, elanInstance);
        elanInstance = ElanUtils.getElanInstanceByName(elanInstanceName);
    }

    Long elanTag = elanInstance.getElanTag();
    // If elan tag is not updated, then put the elan interface into unprocessed entry map and entry. Let entries
    // in this map get processed during ELAN update DCN.
    if (elanTag == null) {
        ConcurrentLinkedQueue<ElanInterface> elanInterfaces = unProcessedElanInterfaces.get(elanInstanceName);
        if (elanInterfaces == null) {
            elanInterfaces = new ConcurrentLinkedQueue<ElanInterface>();
        }
        elanInterfaces.add(elanInterfaceAdded);
        unProcessedElanInterfaces.put(elanInstanceName, elanInterfaces);
        return;
    }
    DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
    ElanInterfaceAddWorker addWorker = new ElanInterfaceAddWorker(elanInstanceName, elanInterfaceAdded,
            interfaceInfo, elanInstance, this);
    coordinator.enqueueJob(elanInstanceName, addWorker, ElanConstants.JOB_MAX_RETRIES);
}

From source file:com.ibm.crail.tools.CrailBenchmark.java

void readSequentialAsync(String filename, int size, int loop, int batch) throws Exception {
    System.out.println("readSequentialAsync, filename " + filename + ", size " + size + ", loop " + loop
            + ", batch " + batch);

    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    for (int i = 0; i < batch; i++) {
        CrailBuffer buf = null;//  ww  w .j  a  v  a  2  s .  c  o  m
        if (size == CrailConstants.BUFFER_SIZE) {
            buf = fs.allocateBuffer();
        } else if (size < CrailConstants.BUFFER_SIZE) {
            CrailBuffer _buf = fs.allocateBuffer();
            _buf.clear().limit(size);
            buf = _buf.slice();
        } else {
            buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
        }
        bufferQueue.add(buf);
    }

    //warmup
    warmUp(filename, warmup, bufferQueue);

    //benchmark
    System.out.println("starting benchmark...");
    double sumbytes = 0;
    double ops = 0;
    fs.getStatistics().reset();
    CrailFile file = fs.lookup(filename).get().asFile();
    CrailInputStream directStream = file.getDirectInputStream(file.getCapacity());
    HashMap<Integer, CrailBuffer> futureMap = new HashMap<Integer, CrailBuffer>();
    LinkedBlockingQueue<Future<CrailResult>> futureQueue = new LinkedBlockingQueue<Future<CrailResult>>();
    long start = System.currentTimeMillis();
    for (int i = 0; i < batch - 1 && ops < loop; i++) {
        CrailBuffer buf = bufferQueue.poll();
        buf.clear();
        Future<CrailResult> future = directStream.read(buf);
        futureQueue.add(future);
        futureMap.put(future.hashCode(), buf);
        ops = ops + 1.0;
    }
    while (ops < loop) {
        CrailBuffer buf = bufferQueue.poll();
        buf.clear();
        Future<CrailResult> future = directStream.read(buf);
        futureQueue.add(future);
        futureMap.put(future.hashCode(), buf);

        future = futureQueue.poll();
        CrailResult result = future.get();
        buf = futureMap.get(future.hashCode());
        bufferQueue.add(buf);

        sumbytes = sumbytes + result.getLen();
        ops = ops + 1.0;
    }
    while (!futureQueue.isEmpty()) {
        Future<CrailResult> future = futureQueue.poll();
        CrailResult result = future.get();
        futureMap.get(future.hashCode());
        sumbytes = sumbytes + result.getLen();
        ops = ops + 1.0;
    }
    long end = System.currentTimeMillis();
    double executionTime = ((double) (end - start)) / 1000.0;
    double throughput = 0.0;
    double latency = 0.0;
    double sumbits = sumbytes * 8.0;
    if (executionTime > 0) {
        throughput = sumbits / executionTime / 1000.0 / 1000.0;
        latency = 1000000.0 * executionTime / ops;
    }
    directStream.close();

    System.out.println("execution time " + executionTime);
    System.out.println("ops " + ops);
    System.out.println("sumbytes " + sumbytes);
    System.out.println("throughput " + throughput);
    System.out.println("latency " + latency);

    fs.getStatistics().print("close");
}

From source file:com.ibm.crail.tools.CrailBenchmark.java

void writeAsync(String filename, int size, int loop, int batch, int storageClass, int locationClass)
        throws Exception {
    System.out.println("writeAsync, filename " + filename + ", size " + size + ", loop " + loop + ", batch "
            + batch + ", storageClass " + storageClass + ", locationClass " + locationClass);

    ConcurrentLinkedQueue<CrailBuffer> bufferQueue = new ConcurrentLinkedQueue<CrailBuffer>();
    for (int i = 0; i < batch; i++) {
        CrailBuffer buf = null;/*from   ww  w.j a va2 s  .  c o  m*/
        if (size == CrailConstants.BUFFER_SIZE) {
            buf = fs.allocateBuffer();
        } else if (size < CrailConstants.BUFFER_SIZE) {
            CrailBuffer _buf = fs.allocateBuffer();
            _buf.clear().limit(size);
            buf = _buf.slice();
        } else {
            buf = OffHeapBuffer.wrap(ByteBuffer.allocateDirect(size));
        }
        bufferQueue.add(buf);
    }

    //warmup
    warmUp(filename, warmup, bufferQueue);

    //benchmark
    System.out.println("starting benchmark...");
    LinkedBlockingQueue<Future<CrailResult>> futureQueue = new LinkedBlockingQueue<Future<CrailResult>>();
    HashMap<Integer, CrailBuffer> futureMap = new HashMap<Integer, CrailBuffer>();
    fs.getStatistics().reset();
    long _loop = (long) loop;
    long _bufsize = (long) CrailConstants.BUFFER_SIZE;
    long _capacity = _loop * _bufsize;
    double sumbytes = 0;
    double ops = 0;
    CrailFile file = fs.create(filename, CrailNodeType.DATAFILE, CrailStorageClass.get(storageClass),
            CrailLocationClass.get(locationClass)).get().asFile();
    CrailOutputStream directStream = file.getDirectOutputStream(_capacity);
    long start = System.currentTimeMillis();
    for (int i = 0; i < batch - 1 && ops < loop; i++) {
        CrailBuffer buf = bufferQueue.poll();
        buf.clear();
        Future<CrailResult> future = directStream.write(buf);
        futureQueue.add(future);
        futureMap.put(future.hashCode(), buf);
        ops = ops + 1.0;
    }
    while (ops < loop) {
        CrailBuffer buf = bufferQueue.poll();
        buf.clear();
        Future<CrailResult> future = directStream.write(buf);
        futureQueue.add(future);
        futureMap.put(future.hashCode(), buf);

        future = futureQueue.poll();
        future.get();
        buf = futureMap.get(future.hashCode());
        bufferQueue.add(buf);

        sumbytes = sumbytes + buf.capacity();
        ops = ops + 1.0;
    }
    while (!futureQueue.isEmpty()) {
        Future<CrailResult> future = futureQueue.poll();
        future.get();
        CrailBuffer buf = futureMap.get(future.hashCode());
        sumbytes = sumbytes + buf.capacity();
        ops = ops + 1.0;
    }
    long end = System.currentTimeMillis();
    double executionTime = ((double) (end - start)) / 1000.0;
    double throughput = 0.0;
    double latency = 0.0;
    double sumbits = sumbytes * 8.0;
    if (executionTime > 0) {
        throughput = sumbits / executionTime / 1000.0 / 1000.0;
        latency = 1000000.0 * executionTime / ops;
    }
    directStream.close();

    System.out.println("execution time " + executionTime);
    System.out.println("ops " + ops);
    System.out.println("sumbytes " + sumbytes);
    System.out.println("throughput " + throughput);
    System.out.println("latency " + latency);

    fs.getStatistics().print("close");
}

From source file:com.ibm.crail.tools.CrailBenchmark.java

private void warmUp(String filename, int operations, ConcurrentLinkedQueue<CrailBuffer> bufferList)
        throws Exception {
    Random random = new Random();
    String warmupFilename = filename + random.nextInt();
    System.out.println("warmUp, warmupFile " + warmupFilename + ", operations " + operations);
    if (operations > 0) {
        CrailFile warmupFile = fs.create(warmupFilename, CrailNodeType.DATAFILE, CrailStorageClass.DEFAULT,
                CrailLocationClass.DEFAULT).get().asFile();
        CrailBufferedOutputStream warmupStream = warmupFile.getBufferedOutputStream(0);
        for (int i = 0; i < operations; i++) {
            CrailBuffer buf = bufferList.poll();
            buf.clear();//from w  w  w .j av a2 s .c o m
            warmupStream.write(buf.getByteBuffer());
            bufferList.add(buf);
        }
        warmupStream.purge().get();
        warmupStream.close();
        fs.delete(warmupFilename, false).get().syncDir();
    }
}