Example usage for java.util ArrayDeque ArrayDeque

List of usage examples for java.util ArrayDeque ArrayDeque

Introduction

In this page you can find the example usage for java.util ArrayDeque ArrayDeque.

Prototype

public ArrayDeque(Collection<? extends E> c) 

Source Link

Document

Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:jetbrains.exodus.entitystore.PersistentEntityStoreImpl.java

void registerTransaction(@NotNull final PersistentStoreTransaction txn) {
    final Thread thread = Thread.currentThread();
    Deque<PersistentStoreTransaction> stack = txns.get(thread);
    if (stack == null) {
        stack = new ArrayDeque<>(4);
        txns.put(thread, stack);//  w  w w. ja  v a2  s . c o  m
    }
    stack.push(txn);
}

From source file:com.sonymobile.android.media.internal.VUParser.java

private boolean parseMtdt(BoxHeader header) {
    boolean parseOK = true;
    // if mCurrentBoxSequence contains trak, then add metadata to current
    // track//from  w  w  w  . jav  a  2 s  . c  o  m
    // else metadata is for file
    // we're currently not interested in anything on track level
    try {
        int numberOfUnits = mDataSource.readShort();
        mHmmpTitles = new ArrayList<String>(1);
        ArrayDeque<String> titleLanguages = new ArrayDeque<String>(1);
        ArrayDeque<String> iconLanguages = new ArrayDeque<String>(1);
        for (int i = 0; i < numberOfUnits; i++) {
            short dataUnitSize = mDataSource.readShort();
            int dataTypeID = mDataSource.readInt();
            short language = mDataSource.readShort();
            char l1 = Character.toChars(((language >> 10) & 0x1F) + 96)[0];
            char l2 = Character.toChars(((language >> 5) & 0x1F) + 96)[0];
            char l3 = Character.toChars(((language) & 0x1F) + 96)[0];
            String languageString = "" + l1 + l2 + l3;
            short encodingType = mDataSource.readShort();
            if (encodingType == 0x01) {
                byte[] metadata = new byte[dataUnitSize - 10];
                mDataSource.read(metadata);
                String metadataString = new String(metadata, "UTF-16BE").trim();
                if ((dataTypeID & 0xFFFF) == 0x01) {
                    mHmmpTitles.add(metadataString);
                    titleLanguages.add(languageString);
                }
            } else if (encodingType == 0x101) {
                if (dataTypeID == 0xA04) {
                    if (mIconList == null) {
                        mIconList = new ArrayList<IconInfo>();
                    }
                    mDataSource.skipBytes(4); // selectionFlags
                    mDataSource.skipBytes(4); // reserved
                    int artworkCount = mDataSource.readInt();
                    for (int j = 0; j < artworkCount; j++) {
                        IconInfo iconInfo = new IconInfo();
                        iconInfo.mtsmId = mDataSource.readInt();
                        iconInfo.mdstIndex = mDataSource.readInt();
                        iconInfo.languageIndex = iconLanguages.size();
                        mDataSource.skipBytes(4);
                        mIconList.add(iconInfo);
                    }
                    iconLanguages.add(languageString);
                }
            }
        }
        addMetaDataValue(KEY_HMMP_TITLE_LANGUAGES, titleLanguages.toArray());
        addMetaDataValue(KEY_HMMP_ICON_LANGUAGES, iconLanguages.toArray());
    } catch (EOFException e) {
        if (LOGS_ENABLED)
            Log.e(TAG, "Exception while reading from 'MTDT' box", e);
        return false;
    } catch (IOException e) {
        if (LOGS_ENABLED)
            Log.e(TAG, "Exception while reading from 'MTDT' box", e);
        return false;
    }
    return parseOK;
}

From source file:com.espertech.esper.core.service.EPRuntimeImpl.java

private void processMatches(EventBean theEvent) {
    // get matching filters
    ArrayBackedCollection<FilterHandle> matches = matchesArrayThreadLocal.get();
    long version = services.getFilterService().evaluate(theEvent, matches);

    if (ThreadLogUtil.ENABLED_TRACE) {
        ThreadLogUtil.trace("Found matches for underlying ", matches.size(), theEvent.getUnderlying());
    }//from w w w .j  a v  a  2s.  c o  m

    if (matches.size() == 0) {
        if (unmatchedListener != null) {
            services.getEventProcessingRWLock().releaseReadLock(); // Allow listener to create new statements
            try {
                unmatchedListener.update(theEvent);
            } catch (Throwable t) {
                log.error("Exception thrown by unmatched listener: " + t.getMessage(), t);
            } finally {
                // acquire read lock for release by caller
                services.getEventProcessingRWLock().acquireReadLock();
            }
        }
        return;
    }

    Map<EPStatementAgentInstanceHandle, Object> stmtCallbacks = matchesPerStmtThreadLocal.get();
    Object[] matchArray = matches.getArray();
    int entryCount = matches.size();

    for (int i = 0; i < entryCount; i++) {
        EPStatementHandleCallback handleCallback = (EPStatementHandleCallback) matchArray[i];
        EPStatementAgentInstanceHandle handle = handleCallback.getAgentInstanceHandle();

        // Self-joins require that the internal dispatch happens after all streams are evaluated.
        // Priority or preemptive settings also require special ordering.
        if (handle.isCanSelfJoin() || isPrioritized) {
            Object callbacks = stmtCallbacks.get(handle);
            if (callbacks == null) {
                stmtCallbacks.put(handle, handleCallback.getFilterCallback());
            } else if (callbacks instanceof ArrayDeque) {
                ArrayDeque<FilterHandleCallback> q = (ArrayDeque<FilterHandleCallback>) callbacks;
                q.add(handleCallback.getFilterCallback());
            } else {
                ArrayDeque<FilterHandleCallback> q = new ArrayDeque<FilterHandleCallback>(4);
                q.add((FilterHandleCallback) callbacks);
                q.add(handleCallback.getFilterCallback());
                stmtCallbacks.put(handle, q);
            }
            continue;
        }

        if ((MetricReportingPath.isMetricsEnabled)
                && (handle.getStatementHandle().getMetricsHandle().isEnabled())) {
            long cpuTimeBefore = MetricUtil.getCPUCurrentThread();
            long wallTimeBefore = MetricUtil.getWall();

            processStatementFilterSingle(handle, handleCallback, theEvent, version);

            long wallTimeAfter = MetricUtil.getWall();
            long cpuTimeAfter = MetricUtil.getCPUCurrentThread();
            long deltaCPU = cpuTimeAfter - cpuTimeBefore;
            long deltaWall = wallTimeAfter - wallTimeBefore;
            services.getMetricsReportingService().accountTime(handle.getStatementHandle().getMetricsHandle(),
                    deltaCPU, deltaWall, 1);
        } else {
            if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isRouteThreading())) {
                services.getThreadingService()
                        .submitRoute(new RouteUnitSingle(this, handleCallback, theEvent, version));
            } else {
                processStatementFilterSingle(handle, handleCallback, theEvent, version);
            }
        }
    }
    matches.clear();
    if (stmtCallbacks.isEmpty()) {
        return;
    }

    for (Map.Entry<EPStatementAgentInstanceHandle, Object> entry : stmtCallbacks.entrySet()) {
        EPStatementAgentInstanceHandle handle = entry.getKey();
        Object callbackList = entry.getValue();

        if ((MetricReportingPath.isMetricsEnabled)
                && (handle.getStatementHandle().getMetricsHandle().isEnabled())) {
            long cpuTimeBefore = MetricUtil.getCPUCurrentThread();
            long wallTimeBefore = MetricUtil.getWall();

            processStatementFilterMultiple(handle, callbackList, theEvent, version);

            long wallTimeAfter = MetricUtil.getWall();
            long cpuTimeAfter = MetricUtil.getCPUCurrentThread();
            long deltaCPU = cpuTimeAfter - cpuTimeBefore;
            long deltaWall = wallTimeAfter - wallTimeBefore;
            int size = 1;
            if (callbackList instanceof Collection) {
                size = ((Collection) callbackList).size();
            }
            services.getMetricsReportingService().accountTime(handle.getStatementHandle().getMetricsHandle(),
                    deltaCPU, deltaWall, size);
        } else {
            if ((ThreadingOption.isThreadingEnabled) && (services.getThreadingService().isRouteThreading())) {
                services.getThreadingService()
                        .submitRoute(new RouteUnitMultiple(this, callbackList, theEvent, handle, version));
            } else {
                processStatementFilterMultiple(handle, callbackList, theEvent, version);
            }

            if ((isPrioritized) && (handle.isPreemptive())) {
                break;
            }
        }
    }
    stmtCallbacks.clear();
}

From source file:com.espertech.esper.core.service.EPRuntimeImpl.java

/**
 * Processing multiple filter matches for a statement.
 * @param handle statement handle//from   www . j  a  v  a2  s. com
 * @param callbackList object containing callbacks
 * @param theEvent to process
 * @param version filter version
 */
public void processStatementFilterMultiple(EPStatementAgentInstanceHandle handle, Object callbackList,
        EventBean theEvent, long version) {
    handle.getStatementAgentInstanceLock().acquireWriteLock(services.getStatementLockFactory());
    try {
        if (handle.isHasVariables()) {
            services.getVariableService().setLocalVersion();
        }
        if (!handle.isCurrentFilter(version)) {
            if (handle.getFilterFaultHandler() != null) {
                handle.getFilterFaultHandler().handleFilterFault(theEvent, version);
            }

            ArrayDeque<FilterHandle> callbackListNew = getCallbackList(theEvent, handle.getStatementId());
            if (callbackListNew.isEmpty()) {
                callbackList = Collections.emptyList();
            } else if (callbackListNew.size() == 1) {
                callbackList = ((EPStatementHandleCallback) callbackListNew.getFirst()).getFilterCallback();
            } else {
                ArrayDeque<FilterHandleCallback> q = new ArrayDeque<FilterHandleCallback>(
                        callbackListNew.size());
                callbackList = q;
                for (FilterHandle callback : callbackListNew) {
                    EPStatementHandleCallback handleCallbackFilter = (EPStatementHandleCallback) callback;
                    q.add(handleCallbackFilter.getFilterCallback());
                }
            }
        }

        if (callbackList instanceof Collection) {
            Collection<FilterHandleCallback> callbackColl = (Collection<FilterHandleCallback>) callbackList;
            if (isSubselectPreeval) {
                // sub-selects always go first
                for (FilterHandleCallback callback : callbackColl) {
                    if (callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }

                for (FilterHandleCallback callback : callbackColl) {
                    if (!callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }
            } else {
                // sub-selects always go last
                for (FilterHandleCallback callback : callbackColl) {
                    if (!callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }

                for (FilterHandleCallback callback : callbackColl) {
                    if (callback.isSubSelect()) {
                        callback.matchFound(theEvent, callbackColl);
                    }
                }
            }
        } else {
            FilterHandleCallback single = (FilterHandleCallback) callbackList;
            single.matchFound(theEvent, null);
        }

        // internal join processing, if applicable
        handle.internalDispatch(this.engineFilterAndDispatchTimeContext);
    } catch (RuntimeException ex) {
        services.getExceptionHandlingService().handleException(ex, handle);
    } finally {
        handle.getStatementAgentInstanceLock().releaseWriteLock(services.getStatementLockFactory());
    }
}

From source file:libepg.common.packet.TestPacket_1000P.java

public Queue<TsPacket> getPacketQueue() throws DecoderException {
    ArrayDeque<TsPacket> q = new ArrayDeque<>(this.getPacketList());
    return q;/*from w ww.j  a va2 s.  c  o m*/
}