io.vlingo.actors.Address Java Examples

The following examples show how to use io.vlingo.actors.Address. 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: Calculation.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Completes<CalculationState> calculate(final Stage stage,
                                             final Operation operation,
                                             final Integer anOperand,
                                             final Integer anotherOperand) {

    final Completes<Set<CalculationState>> calculations =
            CalculationQueryProvider.instance().queries().allCalculations();

    return calculations.andThenTo(existingCalculations -> {
        final Address address =
                stage.addressFactory().uniqueWith(generateName());

        final Definition definition =
                Definition.has(CalculationEntity.class, Definition.parameters(CalculationId.from(address.idString())));

        final Calculation calculation = stage.actorFor(Calculation.class, definition, address);

        return calculation.calculate(operation, anOperand, anotherOperand, existingCalculations);
    });
}
 
Example #2
Source File: OutboundGridActorControl.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void relocate(
        final Id receiver,
        final Id sender,
        final Definition.SerializationProxy definitionProxy,
        final Address address,
        final Object snapshot, List<? extends io.vlingo.actors.Message> pending) {

  final List<Deliver<?>> messages =
          pending
            .stream()
            .map(Deliver.from(correlation))
            .collect(Collectors.toList());

  send(receiver, new Relocate(address, definitionProxy, snapshot, messages));
}
 
Example #3
Source File: Order.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Completes<OrderState> register(final ApplicationRegistry registry,
                                      final ProductId productId,
                                      final Integer quantity,
                                      final Site site) {

    final Stage stage = registry.retrieveStage();

    final MessagingClient messagingClient = registry.retrieveMessagingClient();

    final Address address = stage.addressFactory().uniqueWith(generateName());

    final OrderId orderId = OrderId.from(address.idString());

    final Order order =
            stage.actorFor(Order.class,
                    Definition.has(OrderEntity.class, Definition.parameters(orderId)), address);

    final DomainEventNotifier notifier =
            stage.actorFor(DomainEventNotifier.class,
                    Definition.has(DomainEventNotifierActor.class, Definition.parameters(messagingClient)));

    return order.register(productId, quantity, site).andThen(newOrder -> {
        notifier.notify(new OrderWasRegistered(productId, quantity, site));
        return newOrder;
    });
}
 
Example #4
Source File: OrderResource.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Completes<ObjectResponse<String>> create(final OrderCreateRequest request) {
    final Address orderAddress = addressFactory.uniquePrefixedWith("order-");
    Map<ProductId, Integer> quantityByProductId = new HashMap<>();
    request.quantityByIdOfProduct.forEach((key, value) -> quantityByProductId.put(new ProductId(key), value));


    Order orderActor = stage.actorFor(
            Order.class,
            Definition.has(OrderActor.class,
                    Definition.parameters(orderAddress.idString())),
            orderAddress);

    orderActor.initOrderForUserProducts(request.userId, quantityByProductId);
    return Completes.withSuccess(
            ObjectResponse.of(Created,
                    headers(of(Location, urlLocation(orderAddress.idString()))),
                    ""));
}
 
Example #5
Source File: Product.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
static Tuple2<ProductId, Product> defineWith(
        final Stage stage,
        final Tenant tenant,
        final ProductOwner productOwner,
        final String name,
        final String description,
        final boolean hasDiscussion) {

    assert (tenant != null && tenant.id != null);
    assert (productOwner != null && productOwner.id != null);
    assert (name != null);
    assert (description != null);

    Address address = stage.addressFactory().unique();
    final ProductId productId = ProductId.fromExisting(address.idString());
    final Definition definition = Definition.has(ProductEntity.class, Definition.parameters(tenant, productId), productId.id);
    final Product product = stage.actorFor(Product.class, definition);
    product.define(productOwner, name, description, hasDiscussion);
    return Tuple2.from(productId, product);
}
 
Example #6
Source File: Deliver.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public Deliver(final Class<T> protocol,
               final Address address,
               final Definition.SerializationProxy definition,
               final SerializableConsumer<T> consumer,
               final String representation) {
  this(protocol, address, definition, consumer, null, representation);
}
 
Example #7
Source File: TestActor.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Construct my default state.
 * @param actor the Actor inside being tested
 * @param protocol the T protocol being tested
 * @param address the Address of the actor
 */
public TestActor(final Actor actor, final T protocol, final Address address) {
  this.actor = actor;
  this.protocolActor = protocol;
  this.address = address;
  this.context = new TestContext();

  this.actor.viewTestStateInitialization(context);
}
 
Example #8
Source File: LogEvent.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
public LogEvent(final Class<?> source, final String sourceThread, final Instant eventTimestamp, final String message, final Object[] args,
                final Throwable throwable, final Address sourceActorAddress) {
  this.source = source;
  this.message = message;
  this.args = args;
  this.throwable = throwable;
  this.sourceThread = sourceThread;
  this.eventTimestamp = eventTimestamp;
  this.sourceActorAddress = sourceActorAddress;
}
 
Example #9
Source File: Organization.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
static Completes<OrganizationState> with(
        final Stage stage,
        final Class<? extends Actor> entityType,
        final Id organizationId,
        final String name,
        final String description) {
  final String actorName = nameFrom(organizationId);
  final Address address = stage.addressFactory().from(organizationId.value, actorName);
  final Definition definition = Definition.has(entityType, Definition.parameters(organizationId), actorName);
  final Organization organization = stage.actorFor(Organization.class, definition, address);
  return organization.defineWith(name, description);
}
 
Example #10
Source File: Stock.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
static Completes<StockState> unload(final Stage stage, final Location location, final ItemId itemId, final Integer quantity) {
    return StockQueryProvider.instance()
            .queries().queryByLocation(location)
            .andThenTo(state -> {
                final Address address = stage.addressFactory().from(state.stockId().value);
                return stage.actorOf(Stock.class, address);
            })
            .andThenTo(stock -> stock.unload(itemId, quantity));
}
 
Example #11
Source File: Stock.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
static Completes<StockState> increaseAvailabilityFor(final Stage stage, final Location location, final ItemId itemId, final Integer quantity) {
    return StockQueryProvider.instance()
            .queries().queryByLocation(location)
            .andThenTo(state -> {
                final Address address = stage.addressFactory().from(state.stockId().value);
                return stage.actorOf(Stock.class, address);
            })
            .andThenTo(stock -> stock.increaseAvailabilityFor(itemId, quantity));
}
 
Example #12
Source File: Stock.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
static Completes<StockState> openIn(final Stage stage, final Location location) {
    final Address address =
            stage.addressFactory().uniqueWith(generateName());

    final StockId stockId = StockId.from(address.idString());

    final Stock stock =
            stage.actorFor(Stock.class,
                    Definition.has(StockEntity.class, Definition.parameters(stockId)), address);

    return stock.openIn(location);
}
 
Example #13
Source File: CartResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<ObjectResponse<String>> create(final UserId userId) {
    final Address cartAddress = addressFactory.uniquePrefixedWith("cart-");
    final Cart cartActor = stage.actorFor(
            Cart.class,
            Definition.has(CartActor.class, Definition.parameters(cartAddress.idString())),
            cartAddress);

    cartActor.createEmptyCartFor(userId);

    final Headers<ResponseHeader> headers = headers(of(Location, urlLocation(cartAddress.idString())));
    return Completes.withSuccess(ObjectResponse.of(Created, headers, ""));
}
 
Example #14
Source File: UserResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> register(final UserData userData) {
  final Address userAddress = addressFactory.uniquePrefixedWith("u-");

  final User.UserState userState =
    User.from(
      userAddress.idString(),
      Name.from(userData.nameData.given, userData.nameData.family),
      Contact.from(userData.contactData.emailAddress, userData.contactData.telephoneNumber),
      Security.from(userData.publicSecurityToken));

  stage.actorFor(User.class, Definition.has(UserEntity.class, Definition.parameters(userState)), userAddress);

  return Completes.withSuccess(Response.of(Created, headers(of(Location, userLocation(userState.id))), serialized(UserData.from(userState))));
}
 
Example #15
Source File: UserResourceFluent.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
public Completes<Response> register(final UserData userData) {
  final Address userAddress = ServerBootstrap.instance.world.addressFactory().uniquePrefixedWith("u-"); // stage().world().addressFactory().uniquePrefixedWith("u-");
  final User.State userState =
          User.from(
                  userAddress.idString(),
                  Name.from(userData.nameData.given, userData.nameData.family),
                  Contact.from(userData.contactData.emailAddress, userData.contactData.telephoneNumber));

  stage.actorFor(User.class, Definition.has(UserActor.class, Definition.parameters(userState)), userAddress);

  repository.save(userState);

  return Completes.withSuccess(Response.of(Created, headers(of(Location, userLocation(userState.id))), serialized(UserData.from(userState))));
}
 
Example #16
Source File: GridActorControl.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
void relocate(
final Id receiver,
final Id sender,
final Definition.SerializationProxy definitionProxy,
final Address address,
final Object snapshot,
final List<? extends io.vlingo.actors.Message> pending);
 
Example #17
Source File: GridActorControl.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
<T> void deliver(
final Id recipient,
final Id sender,
final Returns<?> returns,
final Class<T> protocol,
final Address address,
final Definition.SerializationProxy definitionProxy,
final SerializableConsumer<T> consumer,
final String representation);
 
Example #18
Source File: OutboundGridActorControl.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public <T> void start(
        final Id recipient,
        final Id sender,
        final Class<T> protocol,
        final Address address,
        final Definition.SerializationProxy definitionProxy) {

  send(recipient, new Start<>(protocol, address, definitionProxy));
}
 
Example #19
Source File: Deliver.java    From vlingo-lattice with Mozilla Public License 2.0 5 votes vote down vote up
public Deliver(final Class<T> protocol,
               final Address address,
               final Definition.SerializationProxy definition,
               final SerializableConsumer<T> consumer,
               final UUID answerCorrelationId,
               final String representation) {
  this.protocol = protocol;
  this.address = address;
  this.definition = definition;
  this.consumer = consumer;
  this.answerCorrelationId = answerCorrelationId;
  this.representation = representation;
}
 
Example #20
Source File: MockCompletesEventually.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Address address() {
  return null;
}
 
Example #21
Source File: MockCompletesEventuallyResponse.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public Address address() {
  return null;
}
 
Example #22
Source File: MockCompletesEventuallyProvider.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public CompletesEventually provideCompletesFor(final Address address, final Returns<?> clientReturns) {
  ++provideCompletesForCount;
  return completesEventually;
}
 
Example #23
Source File: TestWorld.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
public List<Message> allMessagesFor(final Address address) {
  final List<Message> all = actorMessages.get(address.id());
  
  return all == null ? new ArrayList<>() : all;
}
 
Example #24
Source File: Start.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
public Start(Class<T> protocol, Address address, Definition.SerializationProxy definition) {
  this.protocol = protocol;
  this.address = address;
  this.definition = definition;
}
 
Example #25
Source File: LogEvent.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
public Builder withSourceActorAddress(final Address sourceActorAddress) {
  this.sourceActorAddress = sourceActorAddress;
  return this;
}
 
Example #26
Source File: LogEvent.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
public Optional<Address> getSourceActorAddress() {
  return Optional.ofNullable(sourceActorAddress);
}
 
Example #27
Source File: Relocate.java    From vlingo-lattice with Mozilla Public License 2.0 4 votes vote down vote up
public Relocate(Address address, Definition.SerializationProxy definition, Object snapshot, List<Deliver<?>> pending) {
  this.address = address;
  this.definition = definition;
  this.snapshot = snapshot;
  this.pending = pending;
}
 
Example #28
Source File: OrganizationEntityTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private Address address(final String id) {
  return grid.addressFactory().from(id);
}
 
Example #29
Source File: OrganizationEntityTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private Address address(final String id) {
  return grid.addressFactory().from(id);
}
 
Example #30
Source File: OrganizationEntityTest.java    From vlingo-examples with Mozilla Public License 2.0 4 votes vote down vote up
private Address address(final String id) {
  return grid.addressFactory().from(id);
}