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);
}
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;
}
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();
}
}
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.
}
}
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;
}
Aggregations