org.axonframework.common.Assert.isTrue()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(148)

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

Assert.isTrue介绍

[英]Asserts that the given expression is true. If not, an IllegalArgumentException is thrown.
[中]断言给定的表达式为真。如果不是,则抛出IllegalArgumentException。

代码示例

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

@Override
public TrackingToken lowerBound(TrackingToken other) {
  Assert.isTrue(other instanceof GlobalSequenceTrackingToken, () -> "Incompatible token type provided.");
  GlobalSequenceTrackingToken otherToken = (GlobalSequenceTrackingToken) other;
  if (otherToken.globalIndex < this.globalIndex) {
    return otherToken;
  } else {
    return this;
  }
}

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

@Override
public TrackingToken upperBound(TrackingToken other) {
  Assert.isTrue(other instanceof GlobalSequenceTrackingToken, () -> "Incompatible token type provided.");
  if (((GlobalSequenceTrackingToken) other).globalIndex > this.globalIndex) {
    return other;
  }
  return this;
}

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

/**
 * Assert that the given {@code value} is not {@code null}. If not, an IllegalArgumentException is
 * thrown.
 *
 * @param value           the value not to be {@code null}
 * @param messageSupplier Supplier of the exception message if the assertion fails
 * @return the provided {@code value}
 */
public static <T> T nonNull(T value, Supplier<String> messageSupplier) {
  isTrue(value != null, messageSupplier);
  return value;
}

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

/**
 * @param batchSize The maximum number of events to process in a single batch.
 * @return {@code this} for method chaining
 */
public TrackingEventProcessorConfiguration andBatchSize(int batchSize) {
  Assert.isTrue(batchSize > 0, () -> "Batch size must be greater or equal to 1");
  this.batchSize = batchSize;
  return this;
}

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

@Override
public boolean covers(TrackingToken other) {
  Assert.isTrue(other instanceof GlobalSequenceTrackingToken, () -> "Incompatible token type provided.");
  GlobalSequenceTrackingToken otherToken = (GlobalSequenceTrackingToken) other;
  return otherToken.globalIndex <= this.globalIndex;
}

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

/**
 * Assert that the given {@code value} is not {@code null}. If not, an IllegalArgumentException is
 * thrown.
 *
 * @param value           the value not to be {@code null}
 * @param messageSupplier Supplier of the exception message if the assertion fails
 */
public static void notNull(Object value, Supplier<String> messageSupplier) {
  isTrue(value != null, messageSupplier);
}

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

/**
 * Initializes a ThreadFactory instance that create each thread in the given {@code group} with given
 * {@code priority}.
 *
 * @param priority The priority of the threads to create
 * @param group    The ThreadGroup to create each thread in
 * @see Thread#setPriority(int)
 */
public AxonThreadFactory(int priority, ThreadGroup group) {
  Assert.isTrue(priority <= Thread.MAX_PRIORITY && priority >= Thread.MIN_PRIORITY,
         () -> "Given priority is invalid");
  this.priority = priority;
  this.threadGroup = group;
}

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

/**
 * The duration of a single attempt to acquire the internal lock. In combination with the
 * {@link #acquireAttempts(int)}, this defines the total timeout of an acquisition attempt.
 * <p>
 * Defaults to 600ms.
 *
 * @param lockAttemptTimeout The duration of a single aqcuisition attempt of the internal lock, in milliseconds
 * @return this Builder, for further configuration
 */
public Builder lockAttemptTimeout(int lockAttemptTimeout) {
  Assert.isTrue(
      lockAttemptTimeout >= 0,
      () -> "lockAttemptTimeout needs to be a non negative integer, but was '" + lockAttemptTimeout + "'"
  );
  this.lockAttemptTimeout = lockAttemptTimeout;
  return this;
}

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

/**
 * Defines the maximum number of queued threads to allow for this lock. If the given number of threads are
 * waiting to acquire a lock, and another thread joins, that thread will immediately fail any attempt to acquire
 * the lock, as if it had timed out.
 * <p>
 * Defaults to unbounded.
 *
 * @param maximumQueued The maximum number of threads to allow in the queue for this lock
 * @return this Builder, for further configuration
 */
public Builder queueLengthThreshold(int maximumQueued) {
  Assert.isTrue(
      maximumQueued > 0,
      () -> "queueLengthThreshold needs to be a positive integer, but was '" + maximumQueued + "'"
  );
  this.maximumQueued = maximumQueued;
  return this;
}

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

/**
 * Indicates howmany attempts should be done to acquire a lock. In combination with the
 * {@link #lockAttemptTimeout(int)}, this defines the total timeout of a lock acquisition.
 * <p>
 * Defaults to 100.
 *
 * @param acquireAttempts The number of attempts to acquire the lock
 * @return this Builder, for further configuration
 */
public Builder acquireAttempts(int acquireAttempts) {
  Assert.isTrue(
      acquireAttempts > 0 || acquireAttempts == -1,
      () -> "acquireAttempts needs to be a positive integer or -1, but was '" + acquireAttempts + "'"
  );
  this.acquireAttempts = acquireAttempts;
  return this;
}

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

@Override
public boolean covers(TrackingToken other) {
  Assert.isTrue(other instanceof GapAwareTrackingToken, () -> "Incompatible token type provided.");
  GapAwareTrackingToken otherToken = (GapAwareTrackingToken) other;
  return otherToken.index <= this.index
      && !this.gaps.contains(otherToken.index)
      && otherToken.gaps.containsAll(this.gaps.headSet(otherToken.index));
}

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

@Override
public TrackingToken upperBound(TrackingToken otherToken) {
  Assert.isTrue(otherToken instanceof GapAwareTrackingToken, () -> "Incompatible token type provided.");
  GapAwareTrackingToken other = (GapAwareTrackingToken) otherToken;
  SortedSet<Long> newGaps = CollectionUtils.intersect(this.gaps, other.gaps, ConcurrentSkipListSet::new);
  long min = Math.min(this.index, other.index) + 1;
  SortedSet<Long> mergedGaps = CollectionUtils.merge(this.gaps.tailSet(min), other.gaps.tailSet(min), ConcurrentSkipListSet::new);
  newGaps.addAll(mergedGaps);
  return new GapAwareTrackingToken(Math.max(this.index, other.index), newGaps);
}

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

/**
 * Returns the boxed wrapper type for the given {@code primitiveType}.
 *
 * @param primitiveType The primitive type to return boxed wrapper type for
 * @return the boxed wrapper type for the given {@code primitiveType}
 * @throws IllegalArgumentException will be thrown instead of returning null if no wrapper class was found.
 */
public static Class<?> resolvePrimitiveWrapperType(Class<?> primitiveType) {
  Assert.notNull(primitiveType, () -> "primitiveType may not be null");
  Assert.isTrue(primitiveType.isPrimitive(), () -> "primitiveType is not actually primitive: " + primitiveType);
  Class<?> primitiveWrapperType = primitiveWrapperTypeMap.get(primitiveType);
  Assert.notNull(primitiveWrapperType, () -> "no wrapper found for primitiveType: " + primitiveType);
  return primitiveWrapperType;
}

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

private Route joinedWith(ContentTypeConverter newVertex) {
  Assert.isTrue(endPoint.equals(newVertex.expectedSourceType()),
         () -> "Cannot append a vertex if it does not start where the current Route ends");
  return new Route(nodes, newVertex);
}

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

/**
 * Calculates the Segment that represents the merger of this segment with the given {@code other} segment.
 *
 * @param other the segment to merge this one with
 * @return The Segment representing the merged segments
 */
public Segment mergedWith(Segment other) {
  Assert.isTrue(this.isMergeableWith(other), () -> "Given Segment cannot be merged with this segment.");
  return new Segment(Math.min(this.segmentId, other.segmentId), this.mask >>> 1);
}

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

/**
 * Creates a new instance that uses the given {@code delegates} to form a chain of converters. Note that the
 * {@code delegates} must for a Continuous chain, meaning that each item must produce an
 * IntermediateRepresentation of a type that can be consumed by the next delegate.
 * <p/>
 * To automatically calculate a route between converters, see {@link #calculateChain(Class source, Class target,
 * java.util.Collection candidates) calculateChain(source, target, candidates)}
 *
 * @param delegates the chain of delegates to perform the conversion
 */
@SuppressWarnings({"unchecked", "ConstantConditions"})
public ChainedConverter(List<ContentTypeConverter<?,?>> delegates) {
  Assert.isTrue(delegates != null && !delegates.isEmpty(), () -> "The given delegates may not be null or empty");
  Assert.isTrue(isContinuous(delegates), () -> "The given delegates must form a continuous chain");
  this.delegates = new ArrayList<>(delegates);
  target = (Class<T>) this.delegates.get(this.delegates.size() - 1).targetType();
  source = (Class<S>) delegates.get(0).expectedSourceType();
}

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

@Override
public GapAwareTrackingToken lowerBound(TrackingToken other) {
  Assert.isTrue(other instanceof GapAwareTrackingToken, () -> "Incompatible token type provided.");
  GapAwareTrackingToken otherToken = (GapAwareTrackingToken) other;
  SortedSet<Long> mergedGaps = new ConcurrentSkipListSet<>(this.gaps);
  mergedGaps.addAll(otherToken.gaps);
  long mergedIndex = calculateIndex(otherToken, mergedGaps);
  mergedGaps.removeIf(i -> i >= mergedIndex);
  return new GapAwareTrackingToken(mergedIndex, mergedGaps);
}

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

/**
 * Returns a new {@link GapAwareTrackingToken} instance based on the given {@code index} and collection of {@code
 * gaps}.
 *
 * @param index the highest global sequence number of events up until (and including) this tracking token
 * @param gaps  global sequence numbers of events that have not been seen yet even though these sequence numbers are
 *              smaller than the current index. These missing sequence numbers may be filled in later when those
 *              events get committed to the store or may never be filled in if those events never get committed.
 * @return a new tracking token from given index and gaps
 */
@JsonCreator
public static GapAwareTrackingToken newInstance(@JsonProperty("index") long index,
                        @JsonProperty("gaps") Collection<Long> gaps) {
  if (gaps.isEmpty()) {
    return new GapAwareTrackingToken(index, Collections.emptySortedSet());
  }
  SortedSet<Long> gapSet = new ConcurrentSkipListSet<>(gaps);
  Assert.isTrue(gapSet.last() < index,
         () -> String.format("Gap indices [%s] should all be smaller than head index [%d]", gaps, index));
  return new GapAwareTrackingToken(index, gapSet);
}

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

@Override
public A newInstance(Callable<T> factoryMethod) throws Exception {
  UnitOfWork<?> uow = CurrentUnitOfWork.get();
  AtomicReference<A> aggregateReference = new AtomicReference<>();
  // a constructor may apply events, and the persistence of an aggregate must take precedence over publishing its events.
  uow.onPrepareCommit(x -> {
    A aggregate = aggregateReference.get();
    // aggregate construction may have failed with an exception. In that case, no action is required on commit
    if (aggregate != null) {
      prepareForCommit(aggregate);
    }
  });
  A aggregate = doCreateNew(factoryMethod);
  aggregateReference.set(aggregate);
  Assert.isTrue(aggregateModel.entityClass().isAssignableFrom(aggregate.rootType()),
         () -> "Unsuitable aggregate for this repository: wrong type");
  Map<String, A> aggregates = managedAggregates(uow);
  Assert.isTrue(aggregates.putIfAbsent(aggregate.identifierAsString(), aggregate) == null,
         () -> "The Unit of Work already has an Aggregate with the same identifier");
  uow.onRollback(u -> aggregates.remove(aggregate.identifierAsString()));
  return aggregate;
}

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

@CommandHandler
public void handle(UpdateParagraphCommand cmd) {
  Assert.isTrue(cmd.getParagraphId() == paragraphId, () -> "UpdatePageCommand reached the wrong paragraph");
  apply(new ParagraphUpdatedEvent(cmd.getBookId(), cmd.getPageNumber(), paragraphId, cmd.getText()));
}

相关文章