io.vlingo.actors.Actor Java Examples
The following examples show how to use
io.vlingo.actors.Actor.
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: EntryReader.java From vlingo-symbio with Mozilla Public License 2.0 | 6 votes |
public Advice( final Object configuration, final Class<? extends Actor> entryReaderClass, final String queryEntryBatchExpression, final String queryEntryIdsExpression, final String queryEntryExpression, final String queryCount, final String queryLatestOffset, final String queryUpdateCurrentOffset) { this.configuration = configuration; this.entryReaderClass = entryReaderClass; this.queryEntryBatchExpression = queryEntryBatchExpression; this.queryEntryIdsExpression = queryEntryIdsExpression; this.queryEntryExpression = queryEntryExpression; this.queryCount = queryCount; this.queryLatestOffset = queryLatestOffset; this.queryUpdateCurrentOffset = queryUpdateCurrentOffset; }
Example #2
Source File: SseStreamResourceDispatcher.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public void dispatchToHandlerWith(final Context context, final MappedParameters mappedParameters) { Consumer<SseStreamResource> consumer = null; try { switch (mappedParameters.actionId) { case 0: // GET /eventstreams/{streamName} subscribeToStream(String streamName, Class<? extends Actor> feedClass, int feedPayload, int feedInterval) consumer = (handler) -> handler.subscribeToStream((String) mappedParameters.mapped.get(0).value, (Class<? extends Actor>) mappedParameters.mapped.get(1).value, (int) mappedParameters.mapped.get(2).value, (int) mappedParameters.mapped.get(3).value, (String) mappedParameters.mapped.get(4).value); pooledHandler().handleFor(context, consumer); break; case 1: // DELETE /eventstreams/{streamName}/{id} unsubscribeFromStream(String streamName, String id) consumer = (handler) -> handler.unsubscribeFromStream((String) mappedParameters.mapped.get(0).value, (String) mappedParameters.mapped.get(1).value); pooledHandler().handleFor(context, consumer); break; } } catch (Exception e) { throw new IllegalArgumentException("Action mismatch: Request: " + context.request + "Parameters: " + mappedParameters); } }
Example #3
Source File: SseStreamResource.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
public void subscribeToStream(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) { final RequestResponseContext<?> clientContext = context().clientContext(); clientContext.whenClosing(unsubscribeRequest()); final String correlationId = context().request().headerValueOr(RequestHeader.XCorrelationID, ""); final Headers<ResponseHeader> headers = headers(correlationId(correlationId)); final SseSubscriber subscriber = new SseSubscriber( streamName, new SseClient(clientContext, headers), correlationId, context().request().headerValueOr(RequestHeader.LastEventID, "")); publisherFor(streamName, feedClass, feedPayload, feedInterval, feedDefaultId).subscribe(subscriber); }
Example #4
Source File: SseStreamResource.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public SsePublisherActor(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) { this.streamName = streamName; this.subscribers = new HashMap<>(); final ActorInstantiator<?> instantiator = ActorInstantiatorRegistry.instantiatorFor(feedClass); if(instantiator==null)throw new IllegalArgumentException("No ActorInstantiator registred for feedClass="+feedClass.toString()); instantiator.set("feedClass", feedClass); instantiator.set("streamName", streamName); instantiator.set("feedPayload", feedPayload); instantiator.set("feedDefaultId", feedDefaultId); this.feed = stage().actorFor(SseFeed.class, Definition.has(feedClass, instantiator)); this.cancellable = stage().scheduler().schedule(selfAs(Scheduled.class), null, 10, feedInterval); logger().info("SsePublisher started for: " + this.streamName); }
Example #5
Source File: Specification.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
public Specification( final Class<?> protocol, final Class<? extends Actor> type, final Window parent, final String title, final Rectangle rectangle, final boolean enabled, String tag, final Object...parameters) { this.protocol = protocol; this.rectangle = rectangle; this.windowInfo = new WindowInfo(parent, Id.unique(), tag, title); this.enabled = enabled; this.parameters = Arrays.asList(parameters); this.definition = Definition.has(type, Definition.NoParameters); }
Example #6
Source File: FeedResourceDispatcher.java From vlingo-http with Mozilla Public License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public void dispatchToHandlerWith(final Context context, final MappedParameters mappedParameters) { Consumer<FeedResource> consumer = null; try { switch (mappedParameters.actionId) { case 0: // GET /feeds/{feedName}/{feedItemId} feed(String feedName, String feedProductId, Class<? extends Actor> feedProducerClass, int feedProductElements) consumer = (handler) -> handler.feed((String) mappedParameters.mapped.get(0).value, (String) mappedParameters.mapped.get(1).value, (Class<? extends Actor>) mappedParameters.mapped.get(2).value, (int) mappedParameters.mapped.get(3).value); pooledHandler().handleFor(context, consumer); break; } } catch (Exception e) { throw new IllegalArgumentException("Action mismatch: Request: " + context.request + "Parameters: " + mappedParameters); } }
Example #7
Source File: SourcedTypeRegistry.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
/** * Construct my default state with {@code sourcedTypes} creating the {@code Journal} * of type {@code journalType}, and register me with the {@code world}. * @param world the World to which I am registered * @param journalType the concrete {@code Actor} type of the Journal to create * @param dispatcher the {@code Dispatcher<Dispatchable<Entry<?>,State<?>>>} of the journalType * @param sourcedTypes all {@code Class<Sourced<?>>} types of to register * @param <A> the type of Actor used for the Journal implementation * @param <S> the {@code Sourced<?>} types to register */ @SuppressWarnings({ "unchecked", "rawtypes" }) public <A extends Actor, S extends Sourced<?>> SourcedTypeRegistry( final World world, final Class<A> journalType, final Dispatcher<Dispatchable<Entry<?>,State<?>>> dispatcher, final Class<S> ... sourcedTypes) { this(world); final Journal<?> journal = world.actorFor(Journal.class, journalType, dispatcher); EntryAdapterProvider.instance(world); for (Class<S> sourcedType : sourcedTypes) { this.register(new Info(journal, sourcedType, sourcedType.getSimpleName())); } }
Example #8
Source File: FeedResource.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
/** * Feed the resource identified by {@code name} and {@code feedItemId}. * @param feedName the String name of the feed to serve * @param feedProductId the String identity of the feed product to serve * @param feedProducerClass the {@code Class<? extends Actor>} of FeedProducer * @param feedProductElements the int maximum number of elements in the product */ public void feed( final String feedName, final String feedProductId, final Class<? extends Actor> feedProducerClass, final int feedProductElements) { final FeedProducer producer = feedProducer(feedName, feedProducerClass); if (producer == null) { completes().with(Response.of(NotFound, "Feed '" + feedName + "' does not exist.")); } else { producer.produceFeedFor(new FeedProductRequest(context(), feedName, feedProductId, feedProductElements)); } }
Example #9
Source File: SseStreamResource.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
private SsePublisher publisherFor(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) { SsePublisher publisher = publishers.get(streamName); if (publisher == null) { publisher = world.actorFor(SsePublisher.class, Definition.has(SsePublisherActor.class, new SsePublisherInstantiator(streamName, feedClass, feedPayload, feedInterval, feedDefaultId))); final SsePublisher presentPublisher = publishers.putIfAbsent(streamName, publisher); if (presentPublisher != null) { publisher.stop(); publisher = presentPublisher; } } return publisher; }
Example #10
Source File: TestMailbox.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
private void resumeAll() { while (!queue.isEmpty()) { final Message queued = queue.poll(); if (queued != null) { final Actor actor = queued.actor(); if (actor != null) { actor.viewTestStateInitialization(null); queued.deliver(); } } } }
Example #11
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 #12
Source File: ConfiguredSupervisor.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") static Class<? extends Actor> supervisorFrom(final String supervisorClassname) { try { return (Class<? extends Actor>) Class.forName(supervisorClassname); } catch (Exception e) { throw new IllegalStateException("Cannot load class for: " + supervisorClassname); } }
Example #13
Source File: TestWorld.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
public <T> TestActor<T> actorFor(final Class<T> protocol, final Class<? extends Actor> type, final Object...parameters) { if (isTerminated()) { throw new IllegalStateException("vlingo/actors: Stopped."); } return world.stage().testActorFor(protocol, type, parameters); }
Example #14
Source File: TestActor.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
/** * 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 #15
Source File: SsePublisher.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
public SsePublisherInstantiator(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) { this.streamName = streamName; this.feedClass = feedClass; this.feedPayload = feedPayload; this.feedInterval = feedInterval; this.feedDefaultId = feedDefaultId; }
Example #16
Source File: Space__Proxy.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override public <T>io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> get(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Period arg1) { if (!actor.isStopped()) { ActorProxyBase<Space> self = this; final SerializableConsumer<Space> consumer = (actor) -> actor.get(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1)); final io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> returnValue = Completes.using(actor.scheduler()); if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), getRepresentation1); } else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), getRepresentation1)); } return returnValue; } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, getRepresentation1)); } return null; }
Example #17
Source File: ProjectionDispatcher.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * Construct my default state. * @param projectionType the Class of the projectionType that must be an Actor extender * @param constructionParameter the {@code Optional<Object>} to pass as the projectionType constructor parameter, or empty * @param becauseOf the String[] causes/reasons that the projectionType handles */ public ProjectToDescription(final Class<? extends Actor> projectionType, final Optional<Object> constructionParameter, final String... becauseOf) { if (!Projection.class.isAssignableFrom(projectionType)) { throw new IllegalArgumentException("Class of projectionType must extend Actor and implement Projection."); } this.projectionType = projectionType; this.becauseOf = becauseOf; this.constructionParameter = constructionParameter; }
Example #18
Source File: Space__Proxy.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override public <T>io.vlingo.common.Completes<io.vlingo.lattice.grid.spaces.KeyItem<T>> put(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Item<T> arg1) { if (!actor.isStopped()) { ActorProxyBase<Space> self = this; final SerializableConsumer<Space> consumer = (actor) -> actor.put(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1)); final io.vlingo.common.Completes<io.vlingo.lattice.grid.spaces.KeyItem<T>> returnValue = Completes.using(actor.scheduler()); if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), putRepresentation2); } else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), putRepresentation2)); } return returnValue; } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, putRepresentation2)); } return null; }
Example #19
Source File: ProjectionDispatcher.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * Answer a new ProjectToDescription with {@code projectionType} for matches in {@code packageContext}. * @param projectionType the Class of the projectionType that must be an Actor extender * @param constructionParameter the {@code Optional<Object>} to pass as the projectionType constructor parameter, or empty * @param contentsOf the Package used as a prefix wildcard that the projectionType handles * @return ProjectToDescription */ public static ProjectToDescription with(final Class<? extends Actor> projectionType, final Optional<Object> constructionParameter, final Package... contentsOf) { final String[] representations = new String[contentsOf.length]; int index = 0; for (final Package p : contentsOf) { representations[index++] = p.getName() + "*"; } return new ProjectToDescription(projectionType, constructionParameter, representations); }
Example #20
Source File: RoutableCommand.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
protected RoutableCommand( final Class<P> protocol, final Class<? extends Actor> actorType, final String address, final C command, final Completes<A> answer, final CommandDispatcher handler) { this.protocol = protocol; this.actorType = actorType; this.address = address; this.command = command; this.answer = answer; this.handler = handler; }
Example #21
Source File: Space__Proxy.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override public <T>io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> take(io.vlingo.lattice.grid.spaces.Key arg0, io.vlingo.lattice.grid.spaces.Period arg1) { if (!actor.isStopped()) { ActorProxyBase<Space> self = this; final SerializableConsumer<Space> consumer = (actor) -> actor.take(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1)); final io.vlingo.common.Completes<java.util.Optional<io.vlingo.lattice.grid.spaces.KeyItem<T>>> returnValue = Completes.using(actor.scheduler()); if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), takeRepresentation3); } else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), takeRepresentation3)); } return returnValue; } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, takeRepresentation3)); } return null; }
Example #22
Source File: Space__Proxy.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override public <T>io.vlingo.common.Completes<T> itemFor(java.lang.Class<T> arg0, java.lang.Class<? extends io.vlingo.actors.Actor> arg1, java.lang.Object... arg2) { if (!actor.isStopped()) { ActorProxyBase<Space> self = this; final SerializableConsumer<Space> consumer = (actor) -> actor.itemFor(ActorProxyBase.thunk(self, (Actor)actor, arg0), ActorProxyBase.thunk(self, (Actor)actor, arg1), ActorProxyBase.thunk(self, (Actor)actor, arg2)); final io.vlingo.common.Completes<T> returnValue = Completes.using(actor.scheduler()); if (mailbox.isPreallocated()) { mailbox.send(actor, Space.class, consumer, Returns.value(returnValue), itemForRepresentation4); } else { mailbox.send(new LocalMessage<Space>(actor, Space.class, consumer, Returns.value(returnValue), itemForRepresentation4)); } return returnValue; } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, itemForRepresentation4)); } return null; }
Example #23
Source File: Loader.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
private static Map<String, ConfigurationResource<?>> loadFeedResources(final Properties properties) { final Map<String, ConfigurationResource<?>> feedResourceActions = new HashMap<>(); for (final String feedResourceName : findResources(properties, feedProducerNamePrefix)) { final String feedURI = properties.getProperty(feedResourceName); final String resourceName = feedResourceName.substring(feedProducerNamePrefix.length()); final String feedProducerClassnameKey = "feed.resource." + resourceName + ".producer.class"; final String feedProducerClassname = properties.getProperty(feedProducerClassnameKey); final String feedElementsKey = "feed.resource." + resourceName + ".elements"; final int maybeFeedElements = Integer.parseInt(properties.getProperty(feedElementsKey, "20")); final int feedElements = maybeFeedElements <= 0 ? 20 : maybeFeedElements; final String poolKey = "feed.resource." + resourceName + ".pool"; final int maybePoolSize = Integer.parseInt(properties.getProperty(poolKey, "1")); final int handlerPoolSize = maybePoolSize <= 0 ? 1 : maybePoolSize; final String feedRequestURI = feedURI.replaceAll(resourceName, feedNamePathParameter) + "/" + feedProductIdPathParameter; try { final Class<? extends Actor> feedClass = ActorFactory.actorClassWithProtocol(feedProducerClassname, FeedProducer.class); final MappedParameter mappedParameterProducerClass = new MappedParameter("Class<? extends Actor>", feedClass); final MappedParameter mappedParameterProductElements = new MappedParameter("int", feedElements); final List<Action> actions = new ArrayList<>(1); final List<MappedParameter> additionalParameters = Arrays.asList(mappedParameterProducerClass, mappedParameterProductElements); actions.add(new Action(0, Method.GET.name, feedRequestURI, feedProducerFeed, null, additionalParameters)); final ConfigurationResource<?> resource = resourceFor(resourceName, FeedResource.class, handlerPoolSize, actions); feedResourceActions.put(resourceName, resource); } catch (Exception e) { final String message = "vlingo/http: Failed to load feed resource: " + resourceName + " because: " + e.getMessage(); System.out.println(message); e.printStackTrace(); throw new IllegalArgumentException(message, e); } } return feedResourceActions; }
Example #24
Source File: ProjectionDispatcher.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
/** * Answer a new ProjectToDescription with {@code projectionType} for matches on types in {@code becauseOf}. * @param projectionType the Class of the projectionType that must be an Actor extender * @param constructionParameter the {@code Optional<Object>} to pass as the projectionType constructor parameter, or empty * @param becauseOf the {@code Class<? extends Source<?>>} causes/reasons that the projectionType handles * @return ProjectToDescription */ @SuppressWarnings("unchecked") public static ProjectToDescription with(final Class<? extends Actor> projectionType, final Optional<Object> constructionParameter, final Class<? extends Source<?>>... becauseOf) { final String[] representations = new String[becauseOf.length]; int index = 0; for (final Class<?> sourceType : becauseOf) { representations[index++] = sourceType.getName(); } return new ProjectToDescription(projectionType, constructionParameter, representations); }
Example #25
Source File: FeedProducer__Proxy.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
@Override public void produceFeedFor(io.vlingo.http.resource.feed.FeedProductRequest arg0) { if (!actor.isStopped()) { ActorProxyBase<FeedProducer> self = this; final SerializableConsumer<FeedProducer> consumer = (actor) -> actor.produceFeedFor(ActorProxyBase.thunk(self, (Actor)actor, arg0)); if (mailbox.isPreallocated()) { mailbox.send(actor, FeedProducer.class, consumer, null, produceFeedForRepresentation1); } else { mailbox.send(new LocalMessage<FeedProducer>(actor, FeedProducer.class, consumer, produceFeedForRepresentation1)); } } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, produceFeedForRepresentation1)); } }
Example #26
Source File: FeedResource.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
private FeedProducer feedProducer(final String feedName, final Class<? extends Actor> feedProducerClass) { FeedProducer producer = producers.get(feedName); if (producer == null) { producer = FeedProducer.using(world.stage(), feedProducerClass); producers.put(feedName, producer); } return producer; }
Example #27
Source File: ProjectionControl__Proxy.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
@Override public void confirmProjected(java.lang.String arg0) { if (!actor.isStopped()) { ActorProxyBase<ProjectionControl> self = this; final SerializableConsumer<ProjectionControl> consumer = (actor) -> actor.confirmProjected(ActorProxyBase.thunk(self, (Actor)actor, arg0)); if (mailbox.isPreallocated()) { mailbox.send(actor, ProjectionControl.class, consumer, null, confirmProjectedRepresentation1); } else { mailbox.send(new LocalMessage<ProjectionControl>(actor, ProjectionControl.class, consumer, confirmProjectedRepresentation1)); } } else { actor.deadLetters().failedDelivery(new DeadLetter(actor, confirmProjectedRepresentation1)); } }
Example #28
Source File: ConfiguredSupervisor.java From vlingo-actors with Mozilla Public License 2.0 | 4 votes |
ConfiguredSupervisor(final String stageName, final String supervisorName, final Class<? extends Actor> supervisorClass) { this.stageName = stageName; this.supervisorName = supervisorName; this.supervisedProtocol = null; this.supervisorClass = supervisorClass; }
Example #29
Source File: StateProjectionDispatcherTest.java From vlingo-lattice with Mozilla Public License 2.0 | 4 votes |
@Override protected Class<? extends Actor> projectionDispatcherClass() { return TextProjectionDispatcherActor.class; }
Example #30
Source File: JournalAppendResultInterest__Proxy.java From vlingo-symbio with Mozilla Public License 2.0 | 4 votes |
public JournalAppendResultInterest__Proxy(final Actor actor, final Mailbox mailbox){ this.actor = actor; this.mailbox = mailbox; }