Tabnine Logo
AnnotatedAggregate
Code IndexAdd Tabnine to your IDE (free)

How to use
AnnotatedAggregate
in
org.axonframework.modelling.command.inspection

Best Java code snippets using org.axonframework.modelling.command.inspection.AnnotatedAggregate (Showing top 20 results out of 315)

origin: AxonFramework/AxonFramework

/**
 * Initialize an aggregate with the given {@code aggregateRoot} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateRoot  The aggregate root instance
 * @param aggregateModel The model describing the aggregate structure
 * @param eventBus       The EventBus to publish events on
 * @param <T>            The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 */
public static <T> AnnotatedAggregate<T> initialize(T aggregateRoot,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus) {
  return initialize(aggregateRoot, aggregateModel, eventBus, null);
}
origin: AxonFramework/AxonFramework

@Override
protected void doDeleteWithLock(AnnotatedAggregate<T> aggregate) {
  EntityManager entityManager = entityManagerProvider.getEntityManager();
  entityManager.remove(aggregate.getAggregateRoot());
  if (forceFlushOnSave) {
    entityManager.flush();
  }
}
origin: AxonFramework/AxonFramework

@SuppressWarnings("unchecked")
@Override
public Object handle(Message<?> message) throws Exception {
  Callable<Object> messageHandling;
  if (message instanceof CommandMessage) {
    messageHandling = () -> handle((CommandMessage) message);
  } else if (message instanceof EventMessage) {
    messageHandling = () -> handle((EventMessage) message);
  } else {
    throw new IllegalArgumentException("Unsupported message type: " + message.getClass());
  }
  return executeWithResult(messageHandling);
}
origin: AxonFramework/AxonFramework

@Override
public ApplyMore andThenApply(Supplier<?> payloadOrMessageSupplier) {
  return andThen(() -> applyMessageOrPayload(payloadOrMessageSupplier.get()));
}
origin: AxonFramework/AxonFramework

/**
 * Initialize an aggregate created by the given {@code aggregateFactory} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateFactory   The factory to create the aggregate root instance with
 * @param aggregateModel     The model describing the aggregate structure
 * @param eventBus           The EventBus to publish events on
 * @param repositoryProvider Provides repositories for specific aggregate types
 * @param generateSequences  Whether to generate sequence numbers on events published from this aggregate
 * @param <T>                The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 *
 * @throws Exception when an error occurs creating the aggregate root instance
 */
public static <T> AnnotatedAggregate<T> initialize(Callable<T> aggregateFactory,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus,
                          RepositoryProvider repositoryProvider,
                          boolean generateSequences) throws Exception {
  AnnotatedAggregate<T> aggregate =
      new AnnotatedAggregate<>(aggregateModel, eventBus, repositoryProvider);
  if (generateSequences) {
    aggregate.initSequence();
  }
  aggregate.registerRoot(aggregateFactory);
  return aggregate;
}
origin: AxonFramework/AxonFramework

@Test
public void testCommandsAreRoutedToCorrectEntity() throws Exception {
  AggregateModel<Book> bookAggregateModel = AnnotatedAggregateMetaModelFactory.inspectAggregate(Book.class);
  EventBus mockEventBus = SimpleEventBus.builder().build();
  mockEventBus.subscribe(m -> m.forEach(i -> System.out.println(i.getPayloadType().getName())));
  AnnotatedAggregate<Book> bookAggregate = AnnotatedAggregate.initialize((Book) null,
                                      bookAggregateModel,
                                      mockEventBus);
  bookAggregate.handle(command(new CreateBookCommand("book1")));
  bookAggregate.handle(command(new CreatePageCommand("book1")));
  bookAggregate.handle(command(new CreateParagraphCommand("book1", 0)));
  bookAggregate.handle(command(new CreateParagraphCommand("book1", 0)));
  bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 0, "Hello world")));
  bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 1, "Hello world2")));
  assertEquals("Hello world",
         bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(0).getText());
  assertEquals("Hello world2",
         bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(1).getText());
}
origin: AxonFramework/AxonFramework

@Override
protected <P> ApplyMore doApply(P payload, MetaData metaData) {
  if (!applying && aggregateRoot != null) {
    applying = true;
    try {
      publish(createMessage(payload, metaData));
      while (!delayedTasks.isEmpty()) {
        delayedTasks.remove().run();
      }
    } finally {
      delayedTasks.clear();
      applying = false;
    }
  } else {
    delayedTasks.add(() -> publish(createMessage(payload, metaData)));
  }
  return this;
}
origin: AxonFramework/AxonFramework

@Override
protected void publishOnEventBus(EventMessage<?> msg) {
  if (!initializing) {
    // force conversion of LazyIdentifierDomainEventMessage to Generic to release reference to Aggregate.
    super.publishOnEventBus(msg.andMetaData(Collections.emptyMap()));
  }
}
origin: AxonFramework/AxonFramework

@Override
protected void publish(EventMessage<?> msg) {
  super.publish(msg);
  snapshotTrigger.eventHandled(msg);
  if (identifierAsString() == null) {
    throw new IncompatibleAggregateException("Aggregate identifier must be non-null after applying an event. " +
                             "Make sure the aggregate identifier is initialized at " +
                             "the latest when handling the creation event.");
  }
}
origin: AxonFramework/AxonFramework

/**
 * Apply a new event message to the aggregate and then publish this message to external systems. If the given {@code
 * payloadOrMessage} is an instance of a {@link Message} an event message is applied with the payload and metadata
 * of the given message, otherwise an event message is applied with given payload and empty metadata.
 *
 * @param payloadOrMessage defines the payload and optionally metadata to apply to the aggregate
 */
protected void applyMessageOrPayload(Object payloadOrMessage) {
  if (payloadOrMessage instanceof Message) {
    Message message = (Message) payloadOrMessage;
    apply(message.getPayload(), message.getMetaData());
  } else if (payloadOrMessage != null) {
    apply(payloadOrMessage, MetaData.emptyInstance());
  }
}
origin: AxonFramework/AxonFramework

/**
 * Initialize an aggregate with the given {@code aggregateRoot} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateRoot      The aggregate root instance
 * @param aggregateModel     The model describing the aggregate structure
 * @param eventBus           The EventBus to publish events on
 * @param repositoryProvider Provides repositories for specific aggregate types
 * @param <T>                The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 */
public static <T> AnnotatedAggregate<T> initialize(T aggregateRoot,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus,
                          RepositoryProvider repositoryProvider) {
  return new AnnotatedAggregate<>(aggregateRoot, aggregateModel, eventBus, repositoryProvider);
}
origin: org.axonframework/axon-modelling

@Override
protected <P> ApplyMore doApply(P payload, MetaData metaData) {
  if (!applying && aggregateRoot != null) {
    applying = true;
    try {
      publish(createMessage(payload, metaData));
      while (!delayedTasks.isEmpty()) {
        delayedTasks.remove().run();
      }
    } finally {
      delayedTasks.clear();
      applying = false;
    }
  } else {
    delayedTasks.add(() -> publish(createMessage(payload, metaData)));
  }
  return this;
}
origin: org.axonframework/axon-modelling

/**
 * Initialize an aggregate created by the given {@code aggregateFactory} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateFactory   The factory to create the aggregate root instance with
 * @param aggregateModel     The model describing the aggregate structure
 * @param eventBus           The EventBus to publish events on
 * @param repositoryProvider Provides repositories for specific aggregate types
 * @param generateSequences  Whether to generate sequence numbers on events published from this aggregate
 * @param <T>                The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 *
 * @throws Exception when an error occurs creating the aggregate root instance
 */
public static <T> AnnotatedAggregate<T> initialize(Callable<T> aggregateFactory,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus,
                          RepositoryProvider repositoryProvider,
                          boolean generateSequences) throws Exception {
  AnnotatedAggregate<T> aggregate =
      new AnnotatedAggregate<>(aggregateModel, eventBus, repositoryProvider);
  if (generateSequences) {
    aggregate.initSequence();
  }
  aggregate.registerRoot(aggregateFactory);
  return aggregate;
}
origin: AxonFramework/AxonFramework

/**
 * Publish an event to the aggregate root and its entities first and external event handlers (using the given
 * event bus) later.
 *
 * @param msg the event message to publish
 */
protected void publish(EventMessage<?> msg) {
  if (msg instanceof DomainEventMessage) {
    lastKnownSequence = ((DomainEventMessage) msg).getSequenceNumber();
  }
  inspector.publish(msg, aggregateRoot);
  publishOnEventBus(msg);
}
origin: org.axonframework/axon-eventsourcing

@Override
protected void publish(EventMessage<?> msg) {
  super.publish(msg);
  snapshotTrigger.eventHandled(msg);
  if (identifierAsString() == null) {
    throw new IncompatibleAggregateException("Aggregate identifier must be non-null after applying an event. " +
                             "Make sure the aggregate identifier is initialized at " +
                             "the latest when handling the creation event.");
  }
}
origin: org.axonframework/axon-modelling

@Override
public ApplyMore andThenApply(Supplier<?> payloadOrMessageSupplier) {
  return andThen(() -> applyMessageOrPayload(payloadOrMessageSupplier.get()));
}
origin: org.axonframework/axon-modelling

/**
 * Apply a new event message to the aggregate and then publish this message to external systems. If the given {@code
 * payloadOrMessage} is an instance of a {@link Message} an event message is applied with the payload and metadata
 * of the given message, otherwise an event message is applied with given payload and empty metadata.
 *
 * @param payloadOrMessage defines the payload and optionally metadata to apply to the aggregate
 */
protected void applyMessageOrPayload(Object payloadOrMessage) {
  if (payloadOrMessage instanceof Message) {
    Message message = (Message) payloadOrMessage;
    apply(message.getPayload(), message.getMetaData());
  } else if (payloadOrMessage != null) {
    apply(payloadOrMessage, MetaData.emptyInstance());
  }
}
origin: org.axonframework/axon-modelling

/**
 * Initialize an aggregate with the given {@code aggregateRoot} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateRoot      The aggregate root instance
 * @param aggregateModel     The model describing the aggregate structure
 * @param eventBus           The EventBus to publish events on
 * @param repositoryProvider Provides repositories for specific aggregate types
 * @param <T>                The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 */
public static <T> AnnotatedAggregate<T> initialize(T aggregateRoot,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus,
                          RepositoryProvider repositoryProvider) {
  return new AnnotatedAggregate<>(aggregateRoot, aggregateModel, eventBus, repositoryProvider);
}
origin: AxonFramework/AxonFramework

/**
 * Initialize an aggregate created by the given {@code aggregateFactory} which is described in the given
 * {@code aggregateModel}. The given {@code eventBus} is used to publish events generated by the aggregate.
 *
 * @param aggregateFactory   The factory to create the aggregate root instance with
 * @param aggregateModel     The model describing the aggregate structure
 * @param eventBus           The EventBus to publish events on
 * @param repositoryProvider Provides repositories for specific aggregate types
 * @param <T>                The type of the Aggregate root
 * @return An Aggregate instance, fully initialized
 *
 * @throws Exception when an error occurs creating the aggregate root instance
 */
public static <T> AnnotatedAggregate<T> initialize(Callable<T> aggregateFactory,
                          AggregateModel<T> aggregateModel,
                          EventBus eventBus,
                          RepositoryProvider repositoryProvider) throws Exception {
  return initialize(aggregateFactory, aggregateModel, eventBus, repositoryProvider, false);
}
origin: org.axonframework/axon-modelling

@SuppressWarnings("unchecked")
@Override
public Object handle(Message<?> message) throws Exception {
  Callable<Object> messageHandling;
  if (message instanceof CommandMessage) {
    messageHandling = () -> handle((CommandMessage) message);
  } else if (message instanceof EventMessage) {
    messageHandling = () -> handle((EventMessage) message);
  } else {
    throw new IllegalArgumentException("Unsupported message type: " + message.getClass());
  }
  return executeWithResult(messageHandling);
}
org.axonframework.modelling.command.inspectionAnnotatedAggregate

Javadoc

Implementation of the Aggregate interface that allows for an aggregate root to be a POJO with annotations on its Command and Event Handler methods.

This wrapper ensures that aggregate members can use the AggregateLifecycle#apply(Object) method in a static context, as long as access to the instance is done via the #execute(Consumer) or #invoke(Function)methods.

Most used methods

  • initialize
    Initialize an aggregate created by the given aggregateFactory which is described in the given aggreg
  • getAggregateRoot
    Get the annotated aggregate instance. Note that this method should probably never be used in normal
  • handle
  • publish
    Publish an event to the aggregate root and its entities first and external event handlers (using the
  • publishOnEventBus
    Publish an event to external event handlers using the given event bus.
  • <init>
    Initialize an Aggregate instance for the given aggregateRoot, described by the given aggregateModel
  • andThen
  • apply
  • applyMessageOrPayload
    Apply a new event message to the aggregate and then publish this message to external systems. If the
  • createMessage
    Creates an EventMessage with given payload and metaData.
  • doApply
  • execute
  • doApply,
  • execute,
  • executeWithResult,
  • identifier,
  • identifierAsString,
  • initSequence,
  • isDeleted,
  • registerRoot,
  • type,
  • version

Popular in Java

  • Making http requests using okhttp
  • getExternalFilesDir (Context)
  • putExtra (Intent)
  • getSystemService (Context)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • JOptionPane (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now