org.wso2.carbon.databridge.commons.Credentials Java Examples

The following examples show how to use org.wso2.carbon.databridge.commons.Credentials. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestWso2EventServer.java    From product-cep with Apache License 2.0 5 votes vote down vote up
@Override
public void receive(List<Event> eventList, Credentials credentials) {
    long currentTime = System.currentTimeMillis();
    long currentBatchTotalDelay = 0;
    for (Event event : eventList) {
        currentBatchTotalDelay = currentBatchTotalDelay + (currentTime - event.getTimeStamp());
    }
    /** Following section should ideally be atomic **/
    long localTotalDelay = totalDelay.addAndGet(currentBatchTotalDelay);
    long localCounter = counter.addAndGet(eventList.size());
    /** End of wish for atomic section **/

    long index = localCounter / elapsedCount;

    if (lastIndex.get() != index) {
        if (calcInProgress.compareAndSet(false, true)) {
            //TODO Can be made thread safe further
            lastIndex.set(index);
            long currentWindowEventsReceived = localCounter - lastCounter.getAndSet(localCounter);
            //log.info("Current time: " + System.currentTimeMillis() + ", Event received time: " + currentTime + ", Last calculation time: " + lastTime.get());
            long elapsedTime = currentTime - lastTime.getAndSet(currentTime);
            double throughputPerSecond = (((double) currentWindowEventsReceived) / elapsedTime) * 1000;

            log.info("[" + Thread.currentThread().getName() + "] Received " + currentWindowEventsReceived + " sensor events in " + elapsedTime
                    + " milliseconds with total throughput of " + decimalFormat.format(throughputPerSecond)
                    + " events per second. Average delay is " + decimalFormat.format(localTotalDelay / (double) currentWindowEventsReceived));
            totalDelay.addAndGet(-localTotalDelay);
            calcInProgress.set(false);
        }
    }
}
 
Example #2
Source File: TestWso2EventServer.java    From product-cep with Apache License 2.0 4 votes vote down vote up
@Override
        public void receive(List<Event> eventList, Credentials credentials) {
            long currentTime = System.currentTimeMillis();
//            log.info("Received batch of " + eventList.size() + " events at: " + currentTime);
            long currentBatchTotalDelay = 0;
            for (Event event : eventList) {
                currentTime = System.currentTimeMillis();
                long currentEventLatency = currentTime - event.getTimeStamp();
//                log.info("Received event: " + event.getMetaData()[3] + " at " + currentTime +
//                        "; Event timestamp and value of timestamp attribute: " + event.getMetaData()[0] + ", "
//                        + event.getTimeStamp() + "; Latency(ms) : " + currentEventLatency);
                long currentMaxLatency = maxLatency.get();
                if (currentEventLatency > currentMaxLatency) {
                    maxLatency.compareAndSet(currentMaxLatency, currentEventLatency);
                }
                long currentMinLatency = minLatency.get();
                if (currentEventLatency < currentMinLatency) {
                    minLatency.compareAndSet(currentMinLatency, currentEventLatency);
                }
                currentBatchTotalDelay = currentBatchTotalDelay + currentEventLatency;
            }
            long localCounter = counter.addAndGet(eventList.size());
            long localTotalDelay = totalDelay.addAndGet(currentBatchTotalDelay);

            long index = localCounter / elapsedCount;

            if (lastIndex.get() != index) {
                if (calcInProgress.compareAndSet(false, true)) {
                    lastIndex.set(index);
                    long currentWindowEventsReceived = localCounter - lastCounter.getAndSet(localCounter);
                    long elapsedTime = currentTime - lastTime.getAndSet(currentTime);
                    log.info("Received " + currentWindowEventsReceived + " events in " + elapsedTime + " ms; Latency - Avg: "
                            + decimalFormat.format(localTotalDelay / (double) currentWindowEventsReceived)
                            + ", Min: " + minLatency.get() + ", Max: " + maxLatency.get());
                    maxLatency.set(0);
                    minLatency.set(Long.MAX_VALUE);
                    totalDelay.addAndGet(-localTotalDelay);
                    calcInProgress.set(false);
                }
            }

        }