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

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

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

Assert.notNull介绍

[英]Assert that the given value is not null. If not, an IllegalArgumentException is thrown.
[中]断言给定的值不为null。如果不是,则抛出IllegalArgumentException。

代码示例

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

/**
 * Initializes the strategy using given {@code unresolvedRoutingKeyPolicy} prescribing what happens when a
 * routing key cannot be resolved.
 *
 * @param unresolvedRoutingKeyPolicy The policy for unresolved routing keys.
 */
public AbstractRoutingStrategy(UnresolvedRoutingKeyPolicy unresolvedRoutingKeyPolicy) {
  Assert.notNull(unresolvedRoutingKeyPolicy, () -> "unresolvedRoutingKeyPolicy may not be null");
  this.unresolvedRoutingKeyPolicy = unresolvedRoutingKeyPolicy;
}

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

/**
 * Initializes an instance that always returns the given {@code entityManager}. This class can be used for
 * testing, or when using a ContainerManaged EntityManager.
 *
 * @param entityManager the EntityManager to return on {@link #getEntityManager()}
 */
public SimpleEntityManagerProvider(EntityManager entityManager) {
  Assert.notNull(entityManager, () -> "entityManager should not be null");
  this.entityManager = entityManager;
}

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

/**
 * Initialize a ParameterResolverFactory instance that resolves parameters of type
 * {@code declaredParameterType} annotated with the given {@code annotationType}.
 *
 * @param annotationType        the type of annotation that a prospective parameter should declare
 * @param declaredParameterType the type that the parameter value should be assignable to
 */
protected AbstractAnnotatedParameterResolverFactory(Class<A> annotationType, Class<P> declaredParameterType) {
  Assert.notNull(annotationType, () -> "annotationType may not be null");
  Assert.notNull(declaredParameterType, () -> "declaredParameterType may not be null");
  this.annotationType = annotationType;
  this.declaredParameterType = declaredParameterType;
}

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

/**
 * @param transactionManager    The transaction manager to use
 * @param transactionDefinition The definition for transactions to create
 */
public SpringTransactionManager(PlatformTransactionManager transactionManager,
                TransactionDefinition transactionDefinition) {
  Assert.notNull(transactionManager, () -> "transactionManager may not be null");
  this.transactionManager = transactionManager;
  this.transactionDefinition = transactionDefinition;
}

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

/**
 * Initialize with given {@code objectType} and {@code revisionNumber}
 *
 * @param objectType     The description of the serialized object's type
 * @param revisionNumber The revision of the serialized object's type
 */
public SimpleSerializedType(String objectType, String revisionNumber) {
  Assert.notNull(objectType, () -> "objectType cannot be null");
  this.type = objectType;
  this.revisionId = revisionNumber;
}

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

/**
 * Creates a Association Value instance with the given {@code key} and {@code value}.
 *
 * @param key   The key of the Association Value. Usually indicates where the value comes from.
 * @param value The value corresponding to the key of the association. It is highly recommended to only use
 *              serializable values.
 */
public AssociationValue(String key, String value) {
  Assert.notNull(key, () -> "Cannot associate a Saga with a null key");
  Assert.notNull(value, () -> "Cannot associate a Saga with a null value");
  this.propertyKey = key;
  this.propertyValue = value;
}

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

/**
 * Initializes a SimpleSerializedObject using given {@code data} and {@code serializedType}.
 *
 * @param data           The data of the serialized object
 * @param dataType       The type of data
 * @param serializedType The type description of the serialized object
 */
public SimpleSerializedObject(T data, Class<T> dataType, SerializedType serializedType) {
  Assert.notNull(data, () -> "Data for a serialized object cannot be null");
  Assert.notNull(serializedType, () -> "The type identifier of the serialized object");
  this.data = data;
  this.dataType = dataType;
  this.type = serializedType;
}

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

/**
 * Initialize a message monitor with the given list of <name>messageMonitors</name>
 *
 * @param messageMonitors the list of event monitors to delegate to
 */
public MultiMessageMonitor(List<MessageMonitor<? super T>> messageMonitors) {
  Assert.notNull(messageMonitors, () -> "MessageMonitor list may not be null");
  this.messageMonitors = new ArrayList<>(messageMonitors);
}

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

/**
 * Registers a callback to be invoked when the fixture execution starts recording. This happens right before
 * invocation of the 'when' step (stimulus) of the fixture.
 * <p/>
 * Use this to manage Saga dependencies which are not an Axon first class citizen, but do require monitoring of
 * their interactions. For example, register the callback to set a mock in recording mode.
 *
 * @param onStartRecordingCallback callback to invoke
 */
public void registerStartRecordingCallback(Runnable onStartRecordingCallback) {
  Assert.notNull(onStartRecordingCallback, () -> "onStartRecordingCallback may not be null");
  onStartRecordingCallbacks.add(onStartRecordingCallback);
}

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

/**
 * Creates an instance with the given {@code deserializedObject} object instance. Using this constructor will
 * ensure that no deserializing is required when invoking the {@link #getType()} or {@link #getObject()} methods.
 *
 * @param deserializedObject The deserialized object to return on {@link #getObject()}
 */
@SuppressWarnings("unchecked")
public LazyDeserializingObject(T deserializedObject) {
  Assert.notNull(deserializedObject, () -> "The given deserialized instance may not be null");
  this.serializedObject = null;
  this.serializer = null;
  this.deserializedObject = deserializedObject;
  this.deserializedObjectType = (Class<T>) deserializedObject.getClass();
}

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

MessageMonitorFactoryBuilder add(Class<?> componentType, String componentName, MessageMonitorFactory messageMonitorFactory) {
  assertNotBuilt();
  Assert.notNull(componentType, () -> "componentType may not be null");
  Assert.notNull(componentName, () -> "componentName may not be null");
  Assert.notNull(messageMonitorFactory, () -> "messageMonitorFactory may not be null");
  Map<Class<?>, MessageMonitorFactory> mapByType =
      forNameFactories.computeIfAbsent(componentName, (name) -> new TreeMap<>(classComparator));
  mapByType.put(componentType, messageMonitorFactory);
  return this;
}

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

MessageMonitorFactoryBuilder add(Class<?> componentType, MessageMonitorFactory messageMonitorFactory) {
  assertNotBuilt();
  Assert.notNull(componentType, () -> "componentType may not be null");
  Assert.notNull(messageMonitorFactory, () -> "messageMonitorFactory may not be null");
  forTypeFactories.put(componentType, messageMonitorFactory);
  return this;
}

代码示例来源: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

MessageMonitorFactoryBuilder add(MessageMonitorFactory defaultFactory) {
  assertNotBuilt();
  Assert.notNull(defaultFactory, () -> "defaultFactory may not be null");
  this.defaultFactory = defaultFactory;
  return this;
}

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

/**
 * Returns the boxed wrapper type for the given {@code type} if it is primitive.
 *
 * @param type a {@link Type} to return boxed wrapper type for
 * @return the boxed wrapper type for the give {@code type}, or {@code type} if no wrapper class was found.
 */
public static Type resolvePrimitiveWrapperTypeIfPrimitive(Type type) {
  Assert.notNull(type, () -> "type may not be null");
  return getOrDefault(primitiveWrapperTypeMap.get(type), type);
}

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

/**
 * Wraps the given {@code annotatedCommandHandler}, allowing it to be subscribed to a Command Bus.
 *
 * @param annotatedCommandHandler  The object containing the @CommandHandler annotated methods
 * @param parameterResolverFactory The strategy for resolving handler method parameter values
 * @param handlerDefinition        The handler definition used to create concrete handlers
 */
@SuppressWarnings("unchecked")
public AnnotationCommandHandlerAdapter(T annotatedCommandHandler,
                    ParameterResolverFactory parameterResolverFactory,
                    HandlerDefinition handlerDefinition) {
  Assert.notNull(annotatedCommandHandler, () -> "annotatedCommandHandler may not be null");
  this.model = AnnotatedHandlerInspector.inspectType((Class<T>) annotatedCommandHandler.getClass(),
                            parameterResolverFactory,
                            handlerDefinition);
  this.target = annotatedCommandHandler;
}

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

/**
 * Deregisters the given {@code member} and returns a new {@link ConsistentHash} with updated memberships.
 *
 * @param member the member to remove from the consistent hash
 * @return a new {@link ConsistentHash} instance with updated memberships
 */
public ConsistentHash without(Member member) {
  Assert.notNull(member, () -> "Member may not be null");
  if (!members.containsKey(member.name())) {
    return this;
  }
  Map<String, ConsistentHashMember> newMembers = new TreeMap<>(members);
  newMembers.remove(member.name());
  return new ConsistentHash(newMembers, hashFunction, modCount + 1);
}

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

@Override
@SuppressWarnings("unchecked")
public Configurer registerQueryHandler(int phase, Function<Configuration, Object> annotatedQueryHandlerBuilder) {
  startHandlers.add(new RunnableHandler(phase, () -> {
    Object annotatedHandler = annotatedQueryHandlerBuilder.apply(config);
    Assert.notNull(annotatedHandler, () -> "annotatedQueryHandler may not be null");
    Registration registration = new AnnotationQueryHandlerAdapter(annotatedHandler,
                                   config.parameterResolverFactory(),
                                   config.handlerDefinition(annotatedHandler
                                                    .getClass()))
        .subscribe(config.queryBus());
    shutdownHandlers.add(new RunnableHandler(phase, registration::cancel));
  }));
  return this;
}

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

@Override
public Configurer registerCommandHandler(int phase,
                     Function<Configuration, Object> annotatedCommandHandlerBuilder) {
  startHandlers.add(new RunnableHandler(phase, () -> {
    Object handler = annotatedCommandHandlerBuilder.apply(config);
    Assert.notNull(handler, () -> "annotatedCommandHandler may not be null");
    Registration registration =
        new AnnotationCommandHandlerAdapter(handler,
                          config.parameterResolverFactory(),
                          config.handlerDefinition(handler.getClass()))
            .subscribe(config.commandBus());
    shutdownHandlers.add(new RunnableHandler(phase, registration::cancel));
  }));
  return this;
}

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

@Override
  public VersionedAggregateIdentifier resolveTarget(CommandMessage<?> command) {
    String identifier = (String) command.getMetaData().get(identifierKey);
    Assert.notNull(identifier, () -> "The MetaData for the command does not exist or contains a null value");
    Long version = (Long) (versionKey == null ? null : command.getMetaData().get(versionKey));
    return new VersionedAggregateIdentifier(identifier, version);
  }
}

相关文章