Search in sources :

Example 41 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class AbstractFileOutputOperator method requestFinalize.

/**
 * Requests a file to be finalized. When it is writing to a rolling file, this will
 * request for finalizing the current open part and all the prev parts which weren't requested yet.
 *
 * @param fileName name of the file; part file name in case of rotation.
 * @throws IOException
 */
protected void requestFinalize(String fileName) {
    Set<String> filesPerWindow = finalizedFiles.get(currentWindow);
    if (filesPerWindow == null) {
        filesPerWindow = Sets.newHashSet();
        finalizedFiles.put(currentWindow, filesPerWindow);
    }
    if (rollingFile) {
        MutableInt part = finalizedPart.get(fileName);
        if (part == null) {
            part = new MutableInt(-1);
            finalizedPart.put(fileName, part);
        }
        MutableInt currentOpenPart = openPart.get(fileName);
        for (int x = part.getValue() + 1; x <= currentOpenPart.getValue(); x++) {
            String prevPartNotFinalized = getPartFileName(fileName, x);
            LOG.debug("request finalize {}", prevPartNotFinalized);
            filesPerWindow.add(prevPartNotFinalized);
        }
        fileName = getPartFileNamePri(fileName);
        part.setValue(currentOpenPart.getValue());
    }
    filesPerWindow.add(fileName);
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 42 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class GPOUtils method serialize.

/**
 * Serializes the given {@link GPOMutable} object while excluding the provided fields from the serialization.
 * @param gpo The {@link GPOMutable} to serialize.
 * @param excludedFields The fields from the {@link GPOMutable} object to exclude.
 * @return A byte array containing the serialized {@link GPOMutable}.
 */
public static byte[] serialize(GPOMutable gpo, Fields excludedFields) {
    int slength = serializedLength(gpo);
    byte[] sbytes = new byte[slength];
    MutableInt offset = new MutableInt(0);
    Set<String> fields = gpo.getFieldDescriptor().getFields().getFields();
    Set<String> exFieldsSet = excludedFields.getFields();
    for (String field : fields) {
        if (exFieldsSet.contains(field)) {
            continue;
        }
        Type type = gpo.getFieldDescriptor().getType(field);
        GPOType gpoType = GPOType.GPO_TYPE_ARRAY[type.ordinal()];
        gpoType.serialize(gpo, field, sbytes, offset);
    }
    return sbytes;
}
Also used : Type(org.apache.apex.malhar.lib.appdata.schemas.Type) MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 43 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project knime-core by knime.

the class WorkflowLock method unlock.

/**
 * Unlocks as per {@link ReentrantLock#unlock()}, possibly causing a state update check and notification on the
 * workflow when this is the last unlock.
 */
public void unlock() {
    CheckUtils.checkState(m_reentrantLock.isHeldByCurrentThread(), "Lock not held by current thread");
    final MutableInt lockHierarchyLevel = m_lockHierarchyLevelThreadLocal.get();
    CheckUtils.checkState(lockHierarchyLevel.intValue() > 0, "ReentrantLock is held by current thread but not associated with this workflow lock");
    lockHierarchyLevel.decrement();
    try {
        if (lockHierarchyLevel.getValue() == 0 && m_checkForNodeStateChanges) {
            boolean propagateChanges = m_propagateChanges;
            m_propagateChanges = false;
            m_checkForNodeStateChanges = false;
            m_wfm.setInternalStateAfterLockRelease(m_wfm.computeNewState(), propagateChanges);
        }
    } finally {
        m_reentrantLock.unlock();
    }
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 44 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class RandomKeysGenerator method emitTuples.

@Override
public void emitTuples() {
    for (int i = 0; i < tupleBlast; i++) {
        int key = random.nextInt(numKeys);
        outPort.emit(key);
        if (verificationPort.isConnected()) {
            // maintain history for later verification.
            MutableInt count = history.get(key);
            if (count == null) {
                count = new MutableInt(0);
                history.put(key, count);
            }
            count.increment();
        }
    }
    try {
        if (sleepTime != 0) {
            Thread.sleep(sleepTime);
        }
    } catch (Exception ex) {
    // Ignore.
    }
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 45 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class AbstractSingleFileOutputOperatorTest method checkpoint.

private CheckPointOutputOperator checkpoint(AbstractSingleFileOutputOperator<Integer> writer) {
    CheckPointOutputOperator checkPointWriter = new CheckPointOutputOperator();
    checkPointWriter.counts = Maps.newHashMap();
    for (String keys : writer.counts.keySet()) {
        checkPointWriter.counts.put(keys, new MutableLong(writer.counts.get(keys).longValue()));
    }
    checkPointWriter.endOffsets = Maps.newHashMap();
    for (String keys : writer.endOffsets.keySet()) {
        checkPointWriter.endOffsets.put(keys, new MutableLong(writer.endOffsets.get(keys).longValue()));
    }
    checkPointWriter.openPart = Maps.newHashMap();
    for (String keys : writer.openPart.keySet()) {
        checkPointWriter.openPart.put(keys, new MutableInt(writer.openPart.get(keys).intValue()));
    }
    checkPointWriter.filePath = writer.filePath;
    checkPointWriter.maxOpenFiles = writer.maxOpenFiles;
    checkPointWriter.replication = writer.replication;
    checkPointWriter.totalBytesWritten = writer.totalBytesWritten;
    checkPointWriter.maxLength = writer.maxLength;
    checkPointWriter.rollingFile = writer.rollingFile;
    checkPointWriter.outputFileName = writer.outputFileName;
    return checkPointWriter;
}
Also used : MutableLong(org.apache.commons.lang.mutable.MutableLong) MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Aggregations

MutableInt (org.apache.commons.lang3.mutable.MutableInt)46 Test (org.junit.Test)16 Type (org.apache.apex.malhar.lib.appdata.schemas.Type)6 HashMap (java.util.HashMap)5 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)5 List (java.util.List)4 Map (java.util.Map)4 TimeoutException (java.util.concurrent.TimeoutException)4 FieldsDescriptor (org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)2 AllelicCountCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)2 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)2 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)2