io.pravega.common.Exceptions.checkArgument()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(121)

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

Exceptions.checkArgument介绍

[英]Throws an IllegalArgumentException if the validCondition argument is false.
[中]如果validCondition参数为false,则引发IllegalArgumentException。

代码示例

代码示例来源:origin: pravega/pravega

/**
 * Sets the length of the StreamSegment at the time of sealing.
 *
 * @param value The length.
 */
public void setStreamSegmentOffset(long value) {
  Exceptions.checkArgument(value >= 0, "value", "StreamSegment Offset must be a non-negative number.");
  this.streamSegmentOffset = value;
}

代码示例来源:origin: pravega/pravega

/**
 * Sets the length of the StreamSegment at the time of sealing.
 *
 * @param value The length.
 */
public void setStreamSegmentOffset(long value) {
  Exceptions.checkArgument(value >= 0, "value", "StreamSegment Offset must be a non-negative number.");
  this.streamSegmentOffset = value;
}

代码示例来源:origin: pravega/pravega

/**
 * Creates a new instance of the SegmentToContainerMapper class.
 *
 * @param containerCount The number of containers that are available.
 */
public SegmentToContainerMapper(int containerCount) {
  Exceptions.checkArgument(containerCount > 0, "containerCount", "containerCount must be a positive integer.");
  this.containerCount = containerCount;
}

代码示例来源:origin: pravega/pravega

@Override
public synchronized void setStartOffset(long value) {
  if (this.startOffset == value) {
    // Nothing to do.
    return;
  }
  Exceptions.checkArgument(value >= 0, "value", "StartOffset must be a non-negative number.");
  Exceptions.checkArgument(value >= this.startOffset, "value", "New StartOffset cannot be smaller than the previous one.");
  Exceptions.checkArgument(value <= this.length, "value", "New StartOffset cannot be larger than Length.");
  log.debug("{}: StartOffset changed from {} to {}.", this.traceObjectId, this.startOffset, value);
  this.startOffset = value;
}

代码示例来源:origin: pravega/pravega

@Override
public synchronized void setStorageLength(long value) {
  Exceptions.checkArgument(value >= 0, "value", "Storage Length must be a non-negative number.");
  Exceptions.checkArgument(value >= this.storageLength, "value", "New Storage Length cannot be smaller than the previous one.");
  log.trace("{}: StorageLength changed from {} to {}.", this.traceObjectId, this.storageLength, value);
  this.storageLength = value;
}

代码示例来源:origin: pravega/pravega

@Override
public synchronized void setLength(long value) {
  Exceptions.checkArgument(value >= 0, "value", "Length must be a non-negative number.");
  Exceptions.checkArgument(value >= this.length, "value", "New Length cannot be smaller than the previous one.");
  log.trace("{}: Length changed from {} to {}.", this.traceObjectId, this.length, value);
  this.length = value;
}

代码示例来源:origin: pravega/pravega

@Override
public void setValidTruncationPoint(long sequenceNumber) {
  Exceptions.checkArgument(sequenceNumber >= 0, "sequenceNumber", "Operation Sequence Number must be a positive number.");
  synchronized (this.truncationMarkers) {
    this.truncationPoints.add(sequenceNumber);
  }
}

代码示例来源:origin: pravega/pravega

/**
 * Sets the Sequence Number for this operation, if not already set.
 *
 * @param value The Sequence Number to set.
 * @throws IllegalStateException    If the Sequence Number has already been set.
 * @throws IllegalArgumentException If the Sequence Number is negative.
 */
public void setSequenceNumber(long value) {
  Preconditions.checkState(this.sequenceNumber < 0, "Sequence Number has been previously set for this entry. Cannot set a new one.");
  Exceptions.checkArgument(value >= 0, "value", "Sequence Number must be a non-negative number.");
  this.sequenceNumber = value;
}

代码示例来源:origin: pravega/pravega

/**
 * Creates a new instance of the CompletableOperation class.
 *
 * @param operation      The operation to wrap.
 * @param callbackFuture A CompletableFuture that will be used to indicate the outcome of this operation.
 *                       If successful, the CompletableFuture will contain the Sequence Number of the Operation as its payload.
 * @throws IllegalArgumentException If the given callbackFuture is already done.
 */
public CompletableOperation(Operation operation, CompletableFuture<Void> callbackFuture) {
  this(operation, callbackFuture::complete, callbackFuture::completeExceptionally);
  Exceptions.checkArgument(!callbackFuture.isDone(), "callbackFuture", "CallbackFuture is already done.");
}

代码示例来源:origin: pravega/pravega

StoreClientConfigImpl(final StoreType storeType, final Optional<ZKClientConfig> zkClientConfig) {
  Preconditions.checkNotNull(storeType, "storeType");
  Preconditions.checkNotNull(zkClientConfig, "zkClientConfig");
  if (storeType == StoreType.Zookeeper) {
    Exceptions.checkArgument(zkClientConfig.isPresent(), "zkClientConfig", "Should be non-empty");
  }
  this.storeType = storeType;
  this.zkClientConfig = zkClientConfig;
}

代码示例来源:origin: pravega/pravega

@Override
public void setOperationSequenceNumber(long value) {
  ensureRecoveryMode();
  // Note: This check-and-set is not atomic, but in recovery mode we are executing in a single thread, so this is ok.
  Exceptions.checkArgument(value >= this.sequenceNumber.get(), "value", "Invalid SequenceNumber. Expecting greater than %d.", this.sequenceNumber.get());
  this.sequenceNumber.set(value);
}

代码示例来源:origin: pravega/pravega

WriteEntryHeader(ByteArraySegment headerContents) {
  Exceptions.checkArgument(headerContents.getLength() == HEADER_SIZE, "headerContents",
      "Invalid headerContents size. Expected %d, given %d.", HEADER_SIZE, headerContents.getLength());
  this.data = headerContents;
}

代码示例来源:origin: pravega/pravega

@Override
public void recordTruncationMarker(long operationSequenceNumber, LogAddress address) {
  Exceptions.checkArgument(operationSequenceNumber >= 0, "operationSequenceNumber",
      "Operation Sequence Number must be a positive number.");
  Preconditions.checkNotNull(address, "address");
  synchronized (this.truncationMarkers) {
    LogAddress existing = this.truncationMarkers.getOrDefault(operationSequenceNumber, null);
    if (existing == null || existing.getSequence() < address.getSequence()) {
      this.truncationMarkers.put(operationSequenceNumber, address);
    }
  }
}

代码示例来源:origin: pravega/pravega

@Override
public ReadResult read(long streamSegmentId, long offset, int maxLength, Duration timeout) throws StreamSegmentNotExistsException {
  Exceptions.checkNotClosed(this.closed.get(), this);
  log.debug("{}: read (StreamSegmentId = {}, Offset = {}, MaxLength = {}).", this.traceObjectId, streamSegmentId, offset, maxLength);
  StreamSegmentReadIndex index = getOrCreateIndex(streamSegmentId);
  Exceptions.checkArgument(!index.isMerged(), "streamSegmentId", "StreamSegment is merged. Cannot access it anymore.");
  return index.read(offset, maxLength, timeout);
}

代码示例来源:origin: pravega/pravega

@Override
public void append(long streamSegmentId, long offset, byte[] data) throws StreamSegmentNotExistsException {
  Exceptions.checkNotClosed(this.closed.get(), this);
  log.debug("{}: append (StreamSegmentId = {}, Offset = {}, DataLength = {}).", this.traceObjectId, streamSegmentId, offset, data.length);
  // Append the data to the StreamSegment Index. It performs further validation with respect to offsets, etc.
  StreamSegmentReadIndex index = getOrCreateIndex(streamSegmentId);
  Exceptions.checkArgument(!index.isMerged(), "streamSegmentId", "StreamSegment is merged. Cannot append to it anymore.");
  index.append(offset, data);
}

代码示例来源:origin: pravega/pravega

@Override
public void beginMerge(long targetStreamSegmentId, long offset, long sourceStreamSegmentId) throws StreamSegmentNotExistsException {
  Exceptions.checkNotClosed(this.closed.get(), this);
  log.debug("{}: beginMerge (TargetId = {}, Offset = {}, SourceId = {}).", this.traceObjectId, targetStreamSegmentId, offset, sourceStreamSegmentId);
  StreamSegmentReadIndex targetIndex = getOrCreateIndex(targetStreamSegmentId);
  StreamSegmentReadIndex sourceIndex = getOrCreateIndex(sourceStreamSegmentId);
  Exceptions.checkArgument(!targetIndex.isMerged(), "targetStreamSegmentId", "StreamSegment is merged. Cannot access it anymore.");
  Exceptions.checkArgument(!sourceIndex.isMerged(), "sourceStreamSegmentId", "StreamSegment is merged. Cannot access it anymore.");
  targetIndex.beginMerge(offset, sourceIndex);
  sourceIndex.markMerged();
}

代码示例来源:origin: pravega/pravega

public CompletableFuture<ScaleStatusResponse> checkScale(final String scope, final String stream, final int epoch) {
  Exceptions.checkNotNullOrEmpty(scope, "scope");
  Exceptions.checkNotNullOrEmpty(stream, "stream");
  Exceptions.checkArgument(epoch >= 0, "epoch", "Epoch cannot be less than 0");
  return streamMetadataTasks.checkScale(scope, stream, epoch, null);
}

代码示例来源:origin: pravega/pravega

/**
 * Tests the checkArgument method.
 */
@Test
public void testCheckArgument() {
  AssertExtensions.assertThrows(
      "Unexpected behavior for checkArgument(arg, msg) with valid=false argument.",
      () -> Exceptions.checkArgument(false, "invalid-arg", "format msg %s", "foo"),
      ex -> ex instanceof IllegalArgumentException);
  // These should not throw.
  Exceptions.checkArgument(true, "valid-arg", "format msg %s", "foo");
}

代码示例来源:origin: pravega/pravega

private void appendEntry(ReadIndexEntry entry) {
  log.debug("{}: Append (Offset = {}, Length = {}).", this.traceObjectId, entry.getStreamSegmentOffset(), entry.getLength());
  long lastOffset = entry.getLastStreamSegmentOffset();
  synchronized (this.lock) {
    Exceptions.checkArgument(this.lastAppendedOffset < 0 || entry.getStreamSegmentOffset() == this.lastAppendedOffset + 1, "entry", "The given range of bytes (%d-%d) does not start right after the last appended range (%d).", entry.getStreamSegmentOffset(), lastOffset, this.lastAppendedOffset);
    // Finally, append the entry.
    // Key is Offset + Length -1 = Last Offset Of Entry. Value is entry itself. This makes searching easier.
    ReadIndexEntry oldEntry = addToIndex(entry);
    assert oldEntry == null : String.format("Added a new entry in the ReadIndex that overrode an existing element. New = %s, Old = %s.", entry, oldEntry);
    this.lastAppendedOffset = lastOffset;
  }
}

代码示例来源:origin: pravega/pravega

public static final Controller.StreamCutRangeResponse createStreamCutRangeResponse(final String scope, final String stream,
                                          final List<SegmentId> segments, String delegationToken) {
  Exceptions.checkNotNullOrEmpty(scope, "scope");
  Exceptions.checkNotNullOrEmpty(stream, "stream");
  Exceptions.checkArgument(segments.stream().allMatch(x -> x.getStreamInfo().getScope().equals(scope) &&
          x.getStreamInfo().getStream().equals(stream)),
      "streamInfo", "stream info does not match segment id", scope, stream, segments);
  return Controller.StreamCutRangeResponse.newBuilder()
      .addAllSegments(segments)
      .setDelegationToken(delegationToken)
      .build();
}

相关文章