Java Code Examples for io.vlingo.actors.Stage#actorFor()
The following examples show how to use
io.vlingo.actors.Stage#actorFor() .
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: Order.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
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 2
Source File: Product.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
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 3
Source File: CommandModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public static CommandModelStoreProvider using(final Stage stage, final StatefulTypeRegistry registry, final Dispatcher dispatcher) { if (instance != null) return instance; final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(stage.world()); stateAdapterProvider.registerAdapter(UserState.class, new UserStateAdapter()); stateAdapterProvider.registerAdapter(ProfileState.class, new ProfileStateAdapter()); stateAdapterProvider.registerAdapter(UserData.class, new UserDataStateAdapter()); stateAdapterProvider.registerAdapter(ProfileData.class, new ProfileDataStateAdapter()); new EntryAdapterProvider(stage.world()); // future final Protocols storeProtocols = stage.actorFor( new Class<?>[] { StateStore.class, DispatcherControl.class }, Definition.has(InMemoryStateStoreActor.class, Definition.parameters(Arrays.asList(dispatcher)))); final Protocols.Two<StateStore, DispatcherControl> storeWithControl = Protocols.two(storeProtocols); instance = new CommandModelStoreProvider(registry, storeWithControl._1, storeWithControl._2); return instance; }
Example 4
Source File: QueryModelStoreProvider.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") public static QueryModelStoreProvider using(final Stage stage, final StatefulTypeRegistry registry) { if (instance != null) return instance; final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(stage.world()); stateAdapterProvider.registerAdapter(UserData.class, new UserDataStateAdapter()); stateAdapterProvider.registerAdapter(ProfileData.class, new ProfileDataStateAdapter()); new EntryAdapterProvider(stage.world()); // future final Dispatcher noop = new Dispatcher() { public void controlWith(final DispatcherControl control) { } public void dispatch(Dispatchable d) { } }; final StateStore store = stage.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(noop)); final Queries queries = stage.actorFor(Queries.class, QueriesActor.class, store); instance = new QueryModelStoreProvider(registry, store, queries); return instance; }
Example 5
Source File: CommandRouter.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
static CommandRouter of(final Stage stage, final Type type, final int totalRoutees) { switch (type) { case LoadBalancing: return stage.actorFor(CommandRouter.class, LoadBalancingCommandRouter.class, totalRoutees); case Partitioning: return stage.actorFor(CommandRouter.class, PartitioningCommandRouter.class, totalRoutees); case RoundRobin: return stage.actorFor(CommandRouter.class, RoundRobinCommandRouter.class, totalRoutees); } throw new IllegalArgumentException("The command router type is not mapped: " + type); }
Example 6
Source File: Server.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
/** * Answer a new {@code Server} with the given configuration and characteristics. * <p> * WARNING: The Server has been tested with the {@code "queueMailbox"} mailbox type. * This factory method enables you to change that default to another type. If you do * change the mailbox type you do so at your own risk. * * @param stage the Stage in which the Server lives * @param resources the Resource with URI descriptions that the Server understands * @param filters the Filters used to process requests before dispatching to a resource * @param port the int socket port the Server will run on * @param sizing the Sizing such as pool and buffer sizes * @param timing the Timing such as probe interval and missing content timeout * @param severMailboxTypeName the String name of the mailbox to used by the Server * @param channelMailboxTypeName the String name of the mailbox to use by the socket channel * @return Server */ public static Server startWith( final Stage stage, final Resources resources, final Filters filters, final int port, final Sizing sizing, final Timing timing, final String severMailboxTypeName, final String channelMailboxTypeName) { // this may be overridden by using a different RefreshableSelector // initialization that supports a count- or time-based refresh // prior to starting the Server. RefreshableSelector.withNoThreshold(stage.world().defaultLogger()); final Server server = stage.actorFor( Server.class, Definition.has( ServerActor.class, new ServerInstantiator(resources, filters, port, sizing, timing, channelMailboxTypeName), severMailboxTypeName, ServerActor.ServerName), stage.world().addressFactory().withHighId(), stage.world().defaultLogger()); server.startUp(); return server; }
Example 7
Source File: Dispatcher.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
/** * Answer a new {@code Dispatcher} backed by {@code DispatcherActor} within {@code Stage} * and assigned to manage dispatching to the given {@code Resources}. * @param stage the Stage within which the new DispatcherActor will reside * @param resources the Resources that may be dispatched * @return Dispatcher */ public static Dispatcher startWith(final Stage stage, final Resources resources) { final Dispatcher dispatcher = stage.actorFor( Dispatcher.class, Definition.has(DispatcherActor.class, new DispatcherInstantiator(resources))); return dispatcher; }
Example 8
Source File: Resource.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
void allocateHandlerPool(final Stage stage) { for (int idx = 0; idx < handlerPoolSize; ++idx) { handlerPool[idx] = stage.actorFor( ResourceRequestHandler.class, Definition.has( ResourceRequestHandlerActor.class, Definition.parameters(resourceHandlerInstance(stage)))); } }
Example 9
Source File: Organization.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
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: Forum.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
static Tuple2<ForumId, Forum> startWith( final Stage stage, final Tenant tenant, final ForumDescription description) { final Forum forum = stage.actorFor(Forum.class, Definition.has(ForumEntity.class, Definition.parameters(tenant, description.forumId))); forum.startWith(description.creator, description.moderator, description.topic, description.description, description.exclusiveOwner); return Tuple2.from(description.forumId, forum); }
Example 11
Source File: CartQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
public static CartQueryProvider using(final Stage stage, final StatefulTypeRegistry registry, final StateStore stateStore) { if (instance == null) { registerStateAdapter(stage); registerStatefulTypes(stateStore, registry); final CartQuery queries = stage.actorFor(CartQuery.class, CartQueryActor.class, stateStore); instance = new CartQueryProvider(stateStore, queries); } return instance; }
Example 12
Source File: Stock.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
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: Calculator.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
static Calculator with(final Stage stage, final int totalWorkers, final int totalPartitionValues, final int totalMessages) { return stage.actorFor(Calculator.class, CalculatorActor.class, totalWorkers, totalPartitionValues, totalMessages); }
Example 14
Source File: GapRetryReader.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public GapRetryReader(Stage stage, Scheduler scheduler) { this.actor = stage.actorFor(Scheduled.class, GapsFillUpActor.class); this.scheduler = scheduler; }
Example 15
Source File: OrderQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
private OrderQueryProvider(final Stage stage, final ObjectStore objectStore) { this.queries = stage.actorFor(OrderQueries.class, OrderQueriesActor.class, objectStore); }
Example 16
Source File: PartitionCalculator.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
static PartitionCalculator on(final Stage stage) { return stage.actorFor(PartitionCalculator.class, PartitionCalculatorActor.class); }
Example 17
Source File: CalculationQueryProvider.java From vlingo-examples with Mozilla Public License 2.0 | 4 votes |
private CalculationQueryProvider(final Stage stage, final ObjectStore objectStore) { this.queries = stage.actorFor(CalculationQueries.class, CalculationQueriesActor.class, objectStore); }
Example 18
Source File: Journal.java From vlingo-symbio with Mozilla Public License 2.0 | 3 votes |
/** * Answer a new {@code Journal<T>} * @param stage the Stage within which the {@code Journal<T>} is created * @param implementor the {@code Class<A>} of the implementor * @param dispatcher the {@code Dispatcher<T>} * @param additional the Object[] of additional parameters * @param <A> the concrete type of the Actor implementing the {@code Journal<T>} protocol * @param <T> the concrete type of {@code Entry<T>} stored and read, which maybe be String, byte[], or Object * @param <RS> the raw snapshot state type * @return {@code Journal<T>} */ @SuppressWarnings("unchecked") static <A extends Actor, T, RS extends State<?>> Journal<T> using(final Stage stage, final Class<A> implementor, final Dispatcher<Dispatchable<Entry<T>,RS>> dispatcher, final Object...additional) { return additional.length == 0 ? stage.actorFor(Journal.class, implementor, dispatcher) : stage.actorFor(Journal.class, implementor, dispatcher, additional); }
Example 19
Source File: Journal.java From vlingo-symbio with Mozilla Public License 2.0 | 3 votes |
/** * Answer a new {@code Journal<T>} * @param stage the Stage within which the {@code Journal<T>} is created * @param implementor the {@code Class<A>} of the implementor * @param dispatchers the {@code List<Dispatcher<T>>} * @param additional the Object[] of additional parameters * @param <A> the concrete type of the Actor implementing the {@code Journal<T>} protocol * @param <T> the concrete type of {@code Entry<T>} stored and read, which maybe be String, byte[], or Object * @param <RS> the raw snapshot state type * @return {@code Journal<T>} */ @SuppressWarnings("unchecked") static <A extends Actor, T, RS extends State<?>> Journal<T> using(final Stage stage, final Class<A> implementor, final List<Dispatcher<Dispatchable<Entry<T>,RS>>> dispatchers, final Object...additional) { return additional.length == 0 ? stage.actorFor(Journal.class, implementor, dispatchers) : stage.actorFor(Journal.class, implementor, dispatchers, additional); }
Example 20
Source File: FeedProducer.java From vlingo-http with Mozilla Public License 2.0 | 2 votes |
/** * Answer a new {@code FeedProducer}. * @param stage the Stage in which the FeedProducer is created * @param feedProducerClass the {@code Class<? extends Actor>} * @return FeedProducer */ static FeedProducer using(final Stage stage, final Class<? extends Actor> feedProducerClass) { return stage.actorFor(FeedProducer.class, feedProducerClass); }