com.lightbend.lagom.javadsl.persistence.PersistentEntityRef Java Examples
The following examples show how to use
com.lightbend.lagom.javadsl.persistence.PersistentEntityRef.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GreetingServiceImpl.java From tutorials with MIT License | 6 votes |
@Override public ServiceCall<NotUsed, String> handleGreetFrom(String user) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<GreetingCommand> ref = persistentEntityRegistry.refFor(GreetingEntity.class, user); CompletableFuture<String> greetingResponse = ref.ask(new ReceivedGreetingCommand(user)) .toCompletableFuture(); CompletableFuture<WeatherStats> todaysWeatherInfo = (CompletableFuture<WeatherStats>) weatherService.weatherStatsForToday().invoke(); try { return CompletableFuture.completedFuture(greetingResponse.get() + " Today's weather stats: " + todaysWeatherInfo.get().getMessage()); } catch (InterruptedException | ExecutionException e) { return CompletableFuture.completedFuture("Sorry Some Error at our end, working on it"); } }; }
Example #2
Source File: PortfolioRepositoryImpl.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
/** * Initialize a new portfolio. We first generate a new ID for it and send it a setup message. In the very unlikely * circumstance that the ID is already in use we'll get an exception when we send the initialize command, we should * retry with a new UUID. * * @param request * @return The PortfolioModel ID assigned. */ // TODO: Implement retry logic. Theoretically the chance of a collision is astronomically low *given* everything else works. @Override public CompletionStage<PortfolioId> open(OpenPortfolioDetails request) { val portfolioId = PortfolioId.newId(); PersistentEntityRef<PortfolioCommand> ref = persistentEntities.refFor(PortfolioEntity.class, portfolioId.getId()); return ref.ask(new PortfolioCommand.Open(request.getName())) .thenApply(done -> portfolioId); }
Example #3
Source File: ShippingServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
@Override public ServiceCall<String, Leg, Done> addLeg() { return (id, request) -> { CompletionStage<Cargo> response = registrationService.getRegistration().invoke(request.getCargoId(), NotUsed.getInstance()); PersistentEntityRef<ShippingCommand> itinerary = persistentEntityRegistry.refFor(ItineraryEntity.class, id); return itinerary.ask(AddLeg.of(request)); }; }
Example #4
Source File: ShippingServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, Itinerary, Done> createItinerary() { return (id, request) -> { // Look up the itinerary for the given ID. PersistentEntityRef<ShippingCommand> itinerary = persistentEntityRegistry.refFor(ItineraryEntity.class, request.getId()); // Tell the entity to use the greeting message specified. return itinerary.ask(CreateItinerary.of(request)); }; }
Example #5
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 5 votes |
/** * Register Cargo service call * * @return */ @Override public ServiceCall<NotUsed, Cargo, Done> register() { return (id, request) -> { /* Publish received entity into topic named "Topic" */ PubSubRef<Cargo> topic = topics.refFor(TopicId.of(Cargo.class, "topic")); topic.publish(request); log.info("Cargo ID: {}.", request.getId()); /* Look up the Cargo entity for the given ID. */ PersistentEntityRef<RegistrationCommand> ref = persistentEntityRegistry.refFor(CargoEntity.class, request.getId()); /* Tell the entity to use the Cargo information in the request. */ return ref.ask(RegisterCargo.of(request)); }; }
Example #6
Source File: HelloServiceImpl.java From lagom-example with Apache License 2.0 | 5 votes |
@Override public ServiceCall<NotUsed, String> hello(String id) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<HelloCommand> ref = persistentEntityRegistry.refFor(HelloEntity.class, id); // Ask the entity the Hello command. return ref.ask(new Hello(id, Optional.empty())); }; }
Example #7
Source File: HelloServiceImpl.java From lagom-example with Apache License 2.0 | 5 votes |
@Override public ServiceCall<GreetingMessage, Done> useGreeting(String id) { return request -> { // Look up the hello world entity for the given ID. PersistentEntityRef<HelloCommand> ref = persistentEntityRegistry.refFor(HelloEntity.class, id); // Tell the entity to use the greeting message specified. return ref.ask(new UseGreetingMessage(request.message)); }; }
Example #8
Source File: PortfolioRepositoryImpl.java From reactive-stock-trader with Apache License 2.0 | 4 votes |
@Override public PersistentEntityRef<PortfolioCommand> getRef(PortfolioId portfolioId) { return persistentEntities.refFor(PortfolioEntity.class, portfolioId.getId()); }
Example #9
Source File: OrderModelImpl.java From reactive-stock-trader with Apache License 2.0 | 4 votes |
OrderModelImpl(PersistentEntityRef<OrderCommand> orderEntity, TradeService tradeService) { this.orderEntity = orderEntity; this.tradeService = tradeService; }
Example #10
Source File: TransferRepositoryImpl.java From reactive-stock-trader with Apache License 2.0 | 4 votes |
@Override public PersistentEntityRef<TransferCommand> get(TransferId transferId) { return entityRegistry.refFor(TransferEntity.class, transferId.getId()); }
Example #11
Source File: PortfolioRepository.java From reactive-stock-trader with Apache License 2.0 | votes |
PersistentEntityRef<PortfolioCommand> getRef(PortfolioId portfolioId);
Example #12
Source File: TransferRepository.java From reactive-stock-trader with Apache License 2.0 | votes |
PersistentEntityRef<TransferCommand> get(TransferId transferId);