Permalink
Browse files

Extracted the trading context into separate module

The trade engine itself can be seen as a separate context. It is now
split into separate modules: one for the API, and one for the handler.
Part 2/2 ;-)
  • Loading branch information...
1 parent 7e35dab commit 3ab49f276e6e37901b601e1de5eab48595c7dd92 @abuijze abuijze committed Feb 1, 2012
Showing with 113 additions and 40 deletions.
  1. +7 −2 app/pom.xml
  2. +2 −2 app/src/main/java/org/axonframework/samples/trader/app/command/trading/BuyTradeManagerSaga.java
  3. +2 −2 app/src/main/java/org/axonframework/samples/trader/app/command/trading/SellTradeManagerSaga.java
  4. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListener.java
  5. +0 −8 app/src/main/resources/META-INF/spring/command-context.xml
  6. +1 −1 app/src/test/java/org/axonframework/samples/trader/app/command/trading/BuyTradeManagerSagaTest.java
  7. +1 −1 app/src/test/java/org/axonframework/samples/trader/app/command/trading/SellTradeManagerSagaTest.java
  8. +1 −1 ...a/org/axonframework/samples/trader/app/command/trading/matchers/CreateBuyOrderCommandMatcher.java
  9. +1 −1 .../org/axonframework/samples/trader/app/command/trading/matchers/CreateSellOrderCommandMatcher.java
  10. +4 −4 ...t/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListenerIntegrationTest.java
  11. +2 −0 pom.xml
  12. +7 −0 trade-engine-api/pom.xml
  13. +48 −0 trade-engine/pom.xml
  14. +4 −4 trade-engine/src/main/java/org/axonframework/samples/trader/app/command/trading/OrderBook.java
  15. +3 −9 ...e/src/main/java/org/axonframework/samples/trader/app/command/trading/OrderBookCommandHandler.java
  16. +15 −1 trade-engine/src/main/resources/META-INF/spring/trade-engine-context.xml
  17. +7 −2 ...c/test/java/org/axonframework/samples/trader/app/command/trading/OrderBookCommandHandlerTest.java
  18. +5 −0 web-ui/pom.xml
  19. +1 −1 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java
  20. +1 −0 web-ui/src/main/webapp/WEB-INF/web.xml
View
@@ -30,6 +30,12 @@
<dependencies>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axon-trader-trade-engine-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.axonframework</groupId>
<artifactId>axon-core</artifactId>
<version>${axon.version}</version>
@@ -92,8 +98,7 @@
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
- </dependency>
-
+ </dependency>
<!-- test dependencies -->
<dependency>
@@ -19,8 +19,8 @@
import org.axonframework.saga.annotation.EndSaga;
import org.axonframework.saga.annotation.SagaEventHandler;
import org.axonframework.saga.annotation.StartSaga;
-import org.axonframework.samples.trader.app.api.order.CreateBuyOrderCommand;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateBuyOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.samples.trader.app.api.portfolio.item.AddItemsToPortfolioCommand;
import org.axonframework.samples.trader.app.api.portfolio.money.*;
import org.axonframework.samples.trader.app.api.transaction.*;
@@ -18,8 +18,8 @@
import org.axonframework.saga.annotation.EndSaga;
import org.axonframework.saga.annotation.SagaEventHandler;
import org.axonframework.saga.annotation.StartSaga;
-import org.axonframework.samples.trader.app.api.order.CreateSellOrderCommand;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.samples.trader.app.api.portfolio.item.*;
import org.axonframework.samples.trader.app.api.portfolio.money.DepositMoneyToPortfolioCommand;
import org.axonframework.samples.trader.app.api.transaction.*;
@@ -17,7 +17,7 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.eventhandling.annotation.EventHandler;
-import org.axonframework.samples.trader.app.api.order.*;
+import org.axonframework.samples.trader.tradeengine.api.order.*;
import org.axonframework.samples.trader.app.query.company.CompanyEntry;
import org.axonframework.samples.trader.app.query.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookQueryRepository;
@@ -29,14 +29,6 @@
<context:component-scan base-package="org.axonframework.samples.trader.app"/>
- <axon:event-sourcing-repository id="orderBookRepository"
- aggregate-type="org.axonframework.samples.trader.app.command.trading.OrderBook"
- cache-ref="ehcache"
- event-bus="eventBus"
- event-store="eventStore">
- <axon:snapshotter-trigger event-count-threshold="50" snapshotter-ref="snapshotter"/>
- </axon:event-sourcing-repository>
-
<axon:event-sourcing-repository id="companyRepository"
aggregate-type="org.axonframework.samples.trader.app.command.trading.Company"
cache-ref="ehcache"
@@ -17,7 +17,7 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.domain.UUIDAggregateIdentifier;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.samples.trader.app.api.portfolio.money.MoneyReservedFromPortfolioEvent;
import org.axonframework.samples.trader.app.api.portfolio.money.NotEnoughMoneyInPortfolioToMakeReservationEvent;
import org.axonframework.samples.trader.app.api.transaction.*;
@@ -17,7 +17,7 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.domain.UUIDAggregateIdentifier;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.samples.trader.app.api.portfolio.item.ItemsReservedEvent;
import org.axonframework.samples.trader.app.api.portfolio.item.NotEnoughItemsAvailableToReserveInPortfolio;
import org.axonframework.samples.trader.app.api.transaction.*;
@@ -16,7 +16,7 @@
package org.axonframework.samples.trader.app.command.trading.matchers;
import org.axonframework.domain.AggregateIdentifier;
-import org.axonframework.samples.trader.app.api.order.CreateBuyOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateBuyOrderCommand;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
@@ -16,7 +16,7 @@
package org.axonframework.samples.trader.app.command.trading.matchers;
import org.axonframework.domain.AggregateIdentifier;
-import org.axonframework.samples.trader.app.api.order.CreateSellOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
@@ -17,10 +17,10 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.domain.UUIDAggregateIdentifier;
-import org.axonframework.samples.trader.app.api.order.BuyOrderPlacedEvent;
-import org.axonframework.samples.trader.app.api.order.OrderBookCreatedEvent;
-import org.axonframework.samples.trader.app.api.order.SellOrderPlacedEvent;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.BuyOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookCreatedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.SellOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.samples.trader.app.query.company.CompanyEntry;
import org.axonframework.samples.trader.app.query.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookQueryRepository;
View
@@ -36,6 +36,8 @@
<modules>
<module>app</module>
<module>web-ui</module>
+ <module>trade-engine-api</module>
+ <module>trade-engine</module>
</modules>
<build>
@@ -11,4 +11,11 @@
<artifactId>axon-trader-trade-engine-api</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.axonframework</groupId>
+ <artifactId>axon-core</artifactId>
+ <version>${axon.version}</version>
+ </dependency>
+ </dependencies>
</project>
View
@@ -11,4 +11,52 @@
<artifactId>axon-trader-trade-engine</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axon-trader-trade-engine-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.axonframework</groupId>
+ <artifactId>axon-core</artifactId>
+ <version>${axon.version}</version>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.axonframework</groupId>
+ <artifactId>axon-test</artifactId>
+ <version>${axon.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
@@ -18,10 +18,10 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.eventsourcing.annotation.AbstractAnnotatedAggregateRoot;
-import org.axonframework.samples.trader.app.api.order.BuyOrderPlacedEvent;
-import org.axonframework.samples.trader.app.api.order.OrderBookCreatedEvent;
-import org.axonframework.samples.trader.app.api.order.SellOrderPlacedEvent;
-import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.BuyOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookCreatedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.SellOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import java.util.Comparator;
import java.util.SortedSet;
@@ -18,17 +18,13 @@
import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.domain.UUIDAggregateIdentifier;
import org.axonframework.repository.Repository;
-import org.axonframework.samples.trader.app.api.order.CreateBuyOrderCommand;
-import org.axonframework.samples.trader.app.api.order.CreateOrderBookCommand;
-import org.axonframework.samples.trader.app.api.order.CreateSellOrderCommand;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateBuyOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateOrderBookCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
/**
* @author Allard Buijze
*/
-@Component
public class OrderBookCommandHandler {
private Repository<OrderBook> repository;
@@ -60,8 +56,6 @@ public void handleCreateOrderBook(CreateOrderBookCommand command) {
repository.add(orderBook);
}
- @Autowired
- @Qualifier("orderBookRepository")
public void setRepository(Repository<OrderBook> orderBookRepository) {
this.repository = orderBookRepository;
}
@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+ xmlns:axon="http://www.axonframework.org/schema/core"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.axonframework.org/schema/core http://www.axonframework.org/schema/axon-core-1.2.xsd">
+
+ <bean class="org.axonframework.samples.trader.app.command.trading.OrderBookCommandHandler">
+ <property name="repository" ref="orderBookRepository"/>
+ </bean>
+
+ <axon:event-sourcing-repository id="orderBookRepository"
+ aggregate-type="org.axonframework.samples.trader.app.command.trading.OrderBook"
+ cache-ref="ehcache"
+ event-bus="eventBus"
+ event-store="eventStore">
+ <axon:snapshotter-trigger event-count-threshold="50" snapshotter-ref="snapshotter"/>
+ </axon:event-sourcing-repository>
</beans>
@@ -17,10 +17,15 @@
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.domain.UUIDAggregateIdentifier;
+import org.axonframework.samples.trader.tradeengine.api.order.BuyOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateOrderBookCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateSellOrderCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.OrderBookCreatedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.SellOrderPlacedEvent;
+import org.axonframework.samples.trader.tradeengine.api.order.TradeExecutedEvent;
import org.axonframework.test.FixtureConfiguration;
import org.axonframework.test.Fixtures;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
/**
* @author Allard Buijze
View
@@ -51,6 +51,11 @@
<artifactId>axon-trader-app</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>axon-trader-trade-engine</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- spring dependencies -->
<dependency>
@@ -23,7 +23,7 @@
import org.axonframework.eventstore.mongo.MongoEventStore;
import org.axonframework.saga.repository.mongo.MongoTemplate;
import org.axonframework.samples.trader.app.api.company.CreateCompanyCommand;
-import org.axonframework.samples.trader.app.api.order.CreateOrderBookCommand;
+import org.axonframework.samples.trader.tradeengine.api.order.CreateOrderBookCommand;
import org.axonframework.samples.trader.app.api.portfolio.item.AddItemsToPortfolioCommand;
import org.axonframework.samples.trader.app.api.portfolio.money.DepositMoneyToPortfolioCommand;
import org.axonframework.samples.trader.app.api.user.CreateUserCommand;
@@ -31,6 +31,7 @@
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/spring/command-context.xml,
+ classpath:META-INF/spring/trade-engine-context.xml,
classpath:META-INF/spring/configuration-context.xml,
classpath:META-INF/spring/cqrs-infrastructure-context.xml,
classpath:META-INF/spring/persistence-infrastructure-context.xml,

0 comments on commit 3ab49f2

Please sign in to comment.