org.apache.flink.util.Preconditions.checkState()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(360)

本文整理了Java中org.apache.flink.util.Preconditions.checkState()方法的一些代码示例,展示了Preconditions.checkState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Preconditions.checkState()方法的具体详情如下:
包路径:org.apache.flink.util.Preconditions
类名称:Preconditions
方法名:checkState

Preconditions.checkState介绍

[英]Checks the given boolean condition, and throws an IllegalStateException if the condition is not met (evaluates to false).
[中]检查给定的布尔条件,如果不满足该条件,则抛出非法状态异常(计算结果为false)。

代码示例

代码示例来源:origin: apache/flink

public void pushBack(IN element) {
    Preconditions.checkState(pushBack == null, "Already contains an element that was pushed back. This indicates a programming error.");
    pushBack = element;
  }
}

代码示例来源:origin: apache/flink

/**
 * Sets the part size above which a part file will have to roll.
 * @param size the allowed part size.
 */
public DefaultRollingPolicy.PolicyBuilder withMaxPartSize(final long size) {
  Preconditions.checkState(size > 0L);
  return new PolicyBuilder(size, rolloverInterval, inactivityInterval);
}

代码示例来源:origin: apache/flink

/**
 * Sets the interval of allowed inactivity after which a part file will have to roll.
 * @param interval the allowed inactivity interval.
 */
public DefaultRollingPolicy.PolicyBuilder withInactivityInterval(final long interval) {
  Preconditions.checkState(interval > 0L);
  return new PolicyBuilder(partSize, rolloverInterval, interval);
}

代码示例来源:origin: apache/flink

@Override
protected NullableSerializer<T> createOuterSerializerWithNestedSerializers(TypeSerializer<?>[] nestedSerializers) {
  checkState(nullPaddingLength >= 0,
    "Negative padding size after serializer construction: %d",
    nullPaddingLength);
  final byte[] padding = (nullPaddingLength == 0) ? EMPTY_BYTE_ARRAY : new byte[nullPaddingLength];
  TypeSerializer<T> nestedSerializer = (TypeSerializer<T>) nestedSerializers[0];
  return new NullableSerializer<>(nestedSerializer, padding);
}

代码示例来源:origin: apache/flink

private Set<String> generateNewTransactionalIds() {
  checkState(nextTransactionalIdHint != null, "nextTransactionalIdHint must be present for EXACTLY_ONCE");
  Set<String> transactionalIds = transactionalIdsGenerator.generateIdsToUse(nextTransactionalIdHint.nextFreeTransactionalId);
  LOG.info("Generated new transactionalIds {}", transactionalIds);
  return transactionalIds;
}

代码示例来源:origin: apache/flink

/**
 * Sets the max time a part file can stay open before having to roll.
 * @param interval the desired rollover interval.
 */
public DefaultRollingPolicy.PolicyBuilder withRolloverInterval(final long interval) {
  Preconditions.checkState(interval > 0L);
  return new PolicyBuilder(partSize, interval, inactivityInterval);
}

代码示例来源:origin: apache/flink

@Override
  public void snapshotState(FunctionSnapshotContext context) throws Exception {
    Preconditions.checkState(this.checkpointedState != null,
      "The " + getClass().getSimpleName() + " state has not been properly initialized.");

    this.checkpointedState.clear();
    this.checkpointedState.add(this.globalModificationTime);

    if (LOG.isDebugEnabled()) {
      LOG.debug("{} checkpointed {}.", getClass().getSimpleName(), globalModificationTime);
    }
  }
}

代码示例来源:origin: apache/flink

@Override
public void snapshotState(FunctionSnapshotContext context) throws Exception {
  Preconditions.checkState(this.checkpointedState != null,
    "The " + getClass().getSimpleName() + " has not been properly initialized.");
  this.checkpointedState.clear();
  this.checkpointedState.add(this.numElementsEmitted);
}

代码示例来源:origin: apache/flink

@Override
public void snapshotState(FunctionSnapshotContext context) throws Exception {
  Preconditions.checkState(this.checkpointedState != null,
    "The " + getClass().getSimpleName() + " state has not been properly initialized.");
  this.checkpointedState.clear();
  for (Long v : this.valuesToEmit) {
    this.checkpointedState.add(v);
  }
}

代码示例来源:origin: apache/flink

public synchronized CompletableFuture<?> setExpectedRecord(long record) {
  checkState(!expectedRecord.isDone());
  checkState(!recordsProcessed.isDone());
  expectedRecord.complete(record);
  expectedRecordCounter = 0;
  return recordsProcessed;
}

代码示例来源:origin: apache/flink

public Collection<String> read(String name) {
  List<String> content = filesContent.get(name);
  checkState(content != null, "Unknown file [%s]", name);
  List<String> result = new ArrayList<>(content);
  return result;
}

代码示例来源:origin: apache/flink

@Override
public final void writeSnapshot(DataOutputView out) throws IOException {
  checkState(serializer != null, "the prior serializer has not been set on this");
  // write the snapshot for a non-updated serializer.
  // this mimics the previous behavior where the TypeSerializer was
  // Java-serialized, for backwards compatibility
  TypeSerializerSerializationUtil.writeSerializer(out, serializer);
  // now delegate to the snapshots own writing code
  write(out);
}

代码示例来源:origin: apache/flink

public void snapshotStateForKeyGroup(DataOutputView stream, int keyGroupIdx) throws IOException {
  Preconditions.checkState(useLegacySynchronousSnapshots);
  InternalTimerServiceSerializationProxy<K> serializationProxy =
    new InternalTimerServiceSerializationProxy<>(this, keyGroupIdx);
  serializationProxy.write(stream);
}

代码示例来源:origin: apache/flink

@Override
public void snapshotState(FunctionSnapshotContext context) throws Exception {
  Preconditions.checkState(bucketStates != null && maxPartCountersState != null, "sink has not been initialized");
  buckets.snapshotState(
      context.getCheckpointId(),
      bucketStates,
      maxPartCountersState);
}

代码示例来源:origin: apache/flink

private synchronized void finishProcessingExpectedRecords() {
  checkState(expectedRecord.isDone());
  checkState(!recordsProcessed.isDone());
  recordsProcessed.complete(null);
  expectedRecord = new CompletableFuture<>();
  recordsProcessed = new CompletableFuture<>();
}

代码示例来源:origin: apache/flink

private void awaitPendingPartsUpload() throws IOException {
  checkState(currentUploadInfo.getRemainingParts() == uploadsInProgress.size());
  while (currentUploadInfo.getRemainingParts() > 0) {
    CompletableFuture<PartETag> next = uploadsInProgress.peekFirst();
    PartETag nextPart = awaitPendingPartUploadToComplete(next);
    currentUploadInfo.registerCompletePart(nextPart);
    uploadsInProgress.removeFirst();
  }
}

代码示例来源:origin: apache/flink

private void putContent(String name, List<String> values) {
  List<String> content = filesContent.get(name);
  checkState(content != null, "Unknown file [%s]", name);
  if (!writable) {
    throw new NotWritableException(name);
  }
  content.addAll(values);
}

代码示例来源:origin: apache/flink

@Override
public EitherSerializer<L, R> restoreSerializer() {
  checkState(nestedSnapshot != null);
  return new EitherSerializer<>(
      nestedSnapshot.getRestoredNestedSerializer(0),
      nestedSnapshot.getRestoredNestedSerializer(1));
}

代码示例来源:origin: apache/flink

private ApplicationReport getOnlyApplicationReport() throws IOException, YarnException {
  final YarnClient yarnClient = getYarnClient();
  checkState(yarnClient != null);
  final List<ApplicationReport> apps = yarnClient.getApplications(EnumSet.of(YarnApplicationState.RUNNING));
  assertEquals(1, apps.size()); // Only one running
  return apps.get(0);
}

代码示例来源:origin: apache/flink

private void waitForApplicationAttempt(final ApplicationId applicationId, final int attemptId) throws Exception {
  final YarnClient yarnClient = getYarnClient();
  checkState(yarnClient != null, "yarnClient must be initialized");
  waitUntilCondition(() -> {
    final ApplicationReport applicationReport = yarnClient.getApplicationReport(applicationId);
    return applicationReport.getCurrentApplicationAttemptId().getAttemptId() >= attemptId;
  }, Deadline.fromNow(TIMEOUT));
}

相关文章