Package com.netflix.zeno.util

Examples of com.netflix.zeno.util.SimultaneousExecutor


     * Fill a deserialization state from the serialized data which exists in this ByteArrayOrdinalMap
     *
     * @param copyTo
     */
    void fillDeserializationStateFromData(final FastBlobTypeDeserializationState<?> fill) {
        SimultaneousExecutor executor = new SimultaneousExecutor(1);
        final int numThreads = executor.getMaximumPoolSize();

        fill.ensureCapacity(maxOrdinal() + 1);

        for(int i=0;i<numThreads;i++) {
            final int threadNumber = i;
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    FastBlobDeserializationRecord rec = new FastBlobDeserializationRecord(fill.getSchema(), byteData.getUnderlyingArray());
                    for(int i=threadNumber;i<pointersAndOrdinals.length();i += numThreads) {
                        long pointerAndOrdinal = pointersAndOrdinals.get(i);
                        if(pointerAndOrdinal != EMPTY_BUCKET_VALUE) {
                            long pointer = pointerAndOrdinal & 0xFFFFFFFFFL;
                            int ordinal = (int)(pointerAndOrdinal >> 36);

                            int sizeOfData = VarInt.readVInt(byteData.getUnderlyingArray(), pointer);
                            pointer += VarInt.sizeOfVInt(sizeOfData);

                            rec.position(pointer);

                            fill.add(ordinal, rec);
                        }
                    }
                }
            });
        }

        executor.awaitUninterruptibly();
    }
View Full Code Here


    void copySerializedObjectData(final FastBlobTypeSerializationState<?> destState, final ThreadSafeBitSet imageMemberships[],
            final OrdinalMapping ordinalMapping) {

        final StateOrdinalMapping stateOrdinalMapping = ordinalMapping.createStateOrdinalMapping(destState.getName(), maxOrdinal());

        SimultaneousExecutor executor = new SimultaneousExecutor(8);
        final int numThreads = executor.getMaximumPoolSize();

        for(int i=0;i<numThreads;i++) {
            final int threadNumber = i;
            executor.submit( new Runnable() {
                @Override
                public void run() {
                    final ByteDataBuffer mappedBuffer = new ByteDataBuffer();
                    final FastBlobDeserializationRecord rec = new FastBlobDeserializationRecord(destState.getSchema(), byteData.getUnderlyingArray());
                    final boolean imageMembershipsFlags[] = new boolean[imageMemberships.length];
                    final OrdinalRemapper remapper = new OrdinalRemapper(ordinalMapping);

                    for(int j = threadNumber;j < pointersAndOrdinals.length();j += numThreads) {
                        long pointerAndOrdinal = pointersAndOrdinals.get(j);
                        if(pointerAndOrdinal != EMPTY_BUCKET_VALUE) {
                            long pointer = pointerAndOrdinal & 0xFFFFFFFFFL;
                            int ordinal = (int)(pointerAndOrdinal >> 36);

                            for(int imageIndex=0;imageIndex<imageMemberships.length;imageIndex++) {
                                imageMembershipsFlags[imageIndex] = imageMemberships[imageIndex].get(ordinal);
                            }

                            int sizeOfData = VarInt.readVInt(byteData.getUnderlyingArray(), pointer);
                            pointer += VarInt.sizeOfVInt(sizeOfData);

                            rec.position(pointer);
                            remapper.remapOrdinals(rec, mappedBuffer);

                            int newOrdinal = destState.addData(mappedBuffer, FastBlobImageUtils.toLong(imageMembershipsFlags));
                            stateOrdinalMapping.setMappedOrdinal(ordinal, newOrdinal);

                            mappedBuffer.reset();
                        }
                    }
                }
            });
        }

        executor.awaitUninterruptibly();
    }
View Full Code Here

    }

    private void newHistoricalState(final DiffHistoryDataState from, final DiffHistoryDataState to) {
        final DiffHistoricalState historicalState = new DiffHistoricalState(to.getVersion());

        SimultaneousExecutor executor = new SimultaneousExecutor();

        for(final TypeDiffInstruction<?> typeInstruction : from.getTypeDiffInstructions()) {
            executor.execute(new Runnable() {
                public void run() {
                    Map<Object, Object> fromTypeState = from.getTypeState(typeInstruction.getTypeIdentifier());
                    Map<Object, Object> toTypeState = to.getTypeState(typeInstruction.getTypeIdentifier());

                    historicalState.addTypeState(typeInstruction, fromTypeState, toTypeState);
                }
            });
        }

        executor.awaitUninterruptibly();

        historicalStates.addFirst(historicalState);
        historicalStateHeaderTags.put(to.getVersion(), new HashMap<String, String>(stateEngine.getHeaderTags()));

        /// trim historical entries beyond desired size.
View Full Code Here

     * Copy serialization states whose serializer's name doesn't match the ones provided in the ignore collection
     */
    public void copyTo(FastBlobStateEngine otherStateEngine, Collection<String> topLevelSerializersToIgnore) {
        fillDeserializationStatesFromSerializedData();

        SimultaneousExecutor executor = new SimultaneousExecutor(4.0d);

        List<String> topLevelSerializersToCopy = new ArrayList<String>();
        for(NFTypeSerializer<?> serializer : getTopLevelSerializers()) {
            String serializerName = serializer.getName();
            if(!topLevelSerializersToIgnore.contains(serializerName)) {
                topLevelSerializersToCopy.add(serializer.getName());
            }
        }

        CountDownLatch latch = new CountDownLatch(executor.getMaximumPoolSize() * topLevelSerializersToCopy.size());

        for(String serializerizerName : topLevelSerializersToCopy) {
            executor.submit(getFillSerializationStateRunnable(otherStateEngine, serializerizerName, executor, latch));
        }

        try {
            latch.await();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
        executor.shutdown();
    }
View Full Code Here

TOP

Related Classes of com.netflix.zeno.util.SimultaneousExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.