Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
Rename Java support Controller to Action
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlugter committed Sep 21, 2020
1 parent d5dfbd4 commit 34ae044
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import akka.stream.Materializer;
import com.typesafe.config.Config;
import com.google.protobuf.Descriptors;
import io.cloudstate.javasupport.controller.Controller;
import io.cloudstate.javasupport.controller.ControllerHandler;
import io.cloudstate.javasupport.action.Action;
import io.cloudstate.javasupport.action.ActionHandler;
import io.cloudstate.javasupport.crdt.CrdtEntity;
import io.cloudstate.javasupport.crdt.CrdtEntityFactory;
import io.cloudstate.javasupport.eventsourced.EventSourcedEntity;
import io.cloudstate.javasupport.eventsourced.EventSourcedEntityFactory;
import io.cloudstate.javasupport.impl.AnySupport;
import io.cloudstate.javasupport.impl.controller.AnnotationBasedControllerSupport;
import io.cloudstate.javasupport.impl.controller.ControllerService;
import io.cloudstate.javasupport.impl.action.AnnotationBasedActionSupport;
import io.cloudstate.javasupport.impl.action.ActionService;
import io.cloudstate.javasupport.impl.crdt.AnnotationBasedCrdtSupport;
import io.cloudstate.javasupport.impl.crdt.CrdtStatefulService;
import io.cloudstate.javasupport.impl.eventsourced.AnnotationBasedEventSourcedSupport;
Expand Down Expand Up @@ -239,68 +239,67 @@ public CloudState registerCrdtEntity(
}

/**
* Register an annotated Controller service.
* Register an annotated Action service.
*
* <p>The controller class must be annotated with {@link
* io.cloudstate.javasupport.controller.Controller}.
* <p>The action class must be annotated with {@link Action}.
*
* @param controller The controller object.
* @param descriptor The descriptor for the service that this controller implements.
* @param action The action object.
* @param descriptor The descriptor for the service that this action implements.
* @param additionalDescriptors Any additional descriptors that should be used to look up protobuf
* types when needed.
* @return This Cloudstate builder.
*/
public CloudState registerController(
Object controller,
public CloudState registerAction(
Object action,
Descriptors.ServiceDescriptor descriptor,
Descriptors.FileDescriptor... additionalDescriptors) {

Controller controllerAnnotation = controller.getClass().getAnnotation(Controller.class);
if (controllerAnnotation == null) {
Action actionAnnotation = action.getClass().getAnnotation(Action.class);
if (actionAnnotation == null) {
throw new IllegalArgumentException(
controller.getClass() + " does not declare an " + Controller.class + " annotation!");
action.getClass() + " does not declare an " + Action.class + " annotation!");
}

final AnySupport anySupport = newAnySupport(additionalDescriptors);

services.put(
descriptor.getFullName(),
system ->
new ControllerService(
new AnnotationBasedControllerSupport(
controller, anySupport, descriptor, Materializer.createMaterializer(system)),
new ActionService(
new AnnotationBasedActionSupport(
action, anySupport, descriptor, Materializer.createMaterializer(system)),
descriptor,
anySupport));

return this;
}

/**
* Register a Controller handler.
* Register an Action handler.
*
* <p>This is a low level API intended for custom (eg, non reflection based) mechanisms for
* implementing the controller.
* implementing the action.
*
* @param controller The controller handler.
* @param descriptor The descriptor for the service that this controller implements.
* @param action The action handler.
* @param descriptor The descriptor for the service that this action implements.
* @param additionalDescriptors Any additional descriptors that should be used to look up protobuf
* types when needed.
* @return This Cloudstate builder.
*/
public CloudState registerController(
ControllerHandler controller,
public CloudState registerAction(
ActionHandler action,
Descriptors.ServiceDescriptor descriptor,
Descriptors.FileDescriptor... additionalDescriptors) {

Controller controllerAnnotation = controller.getClass().getAnnotation(Controller.class);
if (controllerAnnotation == null) {
Action actionAnnotation = action.getClass().getAnnotation(Action.class);
if (actionAnnotation == null) {
throw new IllegalArgumentException(
controller.getClass() + " does not declare an " + Controller.class + " annotation!");
action.getClass() + " does not declare an " + Action.class + " annotation!");
}

final AnySupport anySupport = newAnySupport(additionalDescriptors);

ControllerService service = new ControllerService(controller, descriptor, anySupport);
ActionService service = new ActionService(action, descriptor, anySupport);

services.put(descriptor.getFullName(), system -> service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.impl.CloudStateAnnotation;

Expand All @@ -23,8 +23,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** A controller. */
/** An action. */
@CloudStateAnnotation
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Controller {}
public @interface Action {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.Metadata;
import io.cloudstate.javasupport.MetadataContext;

/** Context for controller calls. */
public interface ControllerContext extends MetadataContext {
/** Context for action calls. */
public interface ActionContext extends MetadataContext {
/**
* Get the metadata associated with this call.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,58 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import akka.NotUsed;
import akka.stream.javadsl.Source;
import com.google.protobuf.Any;

import java.util.concurrent.CompletionStage;

/** Low level interface for handling for controller calls. */
public interface ControllerHandler {
/** Low level interface for handling for action calls. */
public interface ActionHandler {

/**
* Handle a unary call.
*
* @param commandName The name of the command this call is for.
* @param message The message envelope of the message.
* @param context The controller context.
* @param context The action context.
* @return A future of the message to return.
*/
CompletionStage<ControllerReply<Any>> handleUnary(
String commandName, MessageEnvelope<Any> message, ControllerContext context);
CompletionStage<ActionReply<Any>> handleUnary(
String commandName, MessageEnvelope<Any> message, ActionContext context);

/**
* Handle a streamed out call call.
*
* @param commandName The name of the command this call is for.
* @param message The message envelope of the message.
* @param context The controller context.
* @param context The action context.
* @return The stream of messages to return.
*/
Source<ControllerReply<Any>, NotUsed> handleStreamedOut(
String commandName, MessageEnvelope<Any> message, ControllerContext context);
Source<ActionReply<Any>, NotUsed> handleStreamedOut(
String commandName, MessageEnvelope<Any> message, ActionContext context);

/**
* Handle a streamed in call.
*
* @param commandName The name of the command this call is for.
* @param stream The stream of messages to handle.
* @param context The controller context.
* @param context The action context.
* @return A future of the message to return.
*/
CompletionStage<ControllerReply<Any>> handleStreamedIn(
String commandName, Source<MessageEnvelope<Any>, NotUsed> stream, ControllerContext context);
CompletionStage<ActionReply<Any>> handleStreamedIn(
String commandName, Source<MessageEnvelope<Any>, NotUsed> stream, ActionContext context);

/**
* Handle a full duplex streamed in call.
*
* @param commandName The name of the command this call is for.
* @param stream The stream of messages to handle.
* @param context The controller context.
* @param context The action context.
* @return The stream of messages to return.
*/
Source<ControllerReply<Any>, NotUsed> handleStreamed(
String commandName, Source<MessageEnvelope<Any>, NotUsed> stream, ControllerContext context);
Source<ActionReply<Any>, NotUsed> handleStreamed(
String commandName, Source<MessageEnvelope<Any>, NotUsed> stream, ActionContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.Metadata;
import io.cloudstate.javasupport.ServiceCall;
import io.cloudstate.javasupport.impl.controller.ForwardReplyImpl;
import io.cloudstate.javasupport.impl.controller.MessageReplyImpl;
import io.cloudstate.javasupport.impl.controller.NoReply;
import io.cloudstate.javasupport.impl.action.ForwardReplyImpl;
import io.cloudstate.javasupport.impl.action.MessageReplyImpl;
import io.cloudstate.javasupport.impl.action.NoReply;

import java.util.Collection;

/**
* A controller reply.
* An action reply.
*
* <p>Controller replies allow returning forwards and attaching effects to messages.
* <p>Action replies allow returning forwards and attaching effects to messages.
*
* @param <T> The type of the message that must be returned by this controller call.
* @param <T> The type of the message that must be returned by this action call.
*/
public interface ControllerReply<T> {
public interface ActionReply<T> {
/**
* The effects attached to this reply.
*
Expand All @@ -45,7 +45,7 @@ public interface ControllerReply<T> {
* @param effects The effects to attach.
* @return A new reply with the attached effects.
*/
ControllerReply<T> withEffects(Effect... effects);
ActionReply<T> withEffects(Effect... effects);

/**
* Create a message reply.
Expand Down Expand Up @@ -85,7 +85,7 @@ static <T> ForwardReply<T> forward(ServiceCall serviceCall) {
*
* @return The reply.
*/
static <T> ControllerReply<T> noReply() {
static <T> ActionReply<T> noReply() {
return NoReply.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.impl.CloudStateAnnotation;

Expand All @@ -24,9 +24,9 @@
import java.lang.annotation.Target;

/**
* A controller call handler.
* An action call handler.
*
* <p>This annotation should be placed on methods that handle Controller service calls.
* <p>This annotation should be placed on methods that handle Action service calls.
*
* <p>The types of the input and output parameters for these methods depend on whether the call is a
* unary or streamed call.
Expand All @@ -41,12 +41,12 @@
*
* <p>Calls with a unary out argument may either return synchronously, or return a {@link
* java.util.concurrent.CompletionStage}. The argument return type may either be the raw protobuf
* output type of the call, or wrapped in {@link MessageEnvelope} or {@link ControllerReply}.
* output type of the call, or wrapped in {@link MessageEnvelope} or {@link ActionReply}.
*
* <p>Calls with a streamed out argument may either return a {@link akka.stream.javadsl.Source},
* {@link org.reactivestreams.Publisher} or a {@link java.util.concurrent.Flow.Publisher}. The
* element type of these may either be the raw protobuf output type of the call, or wrapped in
* {@link MessageEnvelope} or {@link ControllerReply}.
* {@link MessageEnvelope} or {@link ActionReply}.
*/
@CloudStateAnnotation
@Target(ElementType.METHOD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.ServiceCall;
import io.cloudstate.javasupport.impl.controller.EffectImpl;
import io.cloudstate.javasupport.impl.action.EffectImpl;

/** An effect. */
public interface Effect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.ServiceCall;

/** A forward reply. */
public interface ForwardReply<T> extends ControllerReply<T> {
public interface ForwardReply<T> extends ActionReply<T> {

/**
* The service call that is being forwarded to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.Metadata;
import io.cloudstate.javasupport.impl.controller.MessageEnvelopeImpl;
import io.cloudstate.javasupport.impl.action.MessageEnvelopeImpl;

/** A message envelope. */
public interface MessageEnvelope<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package io.cloudstate.javasupport.controller;
package io.cloudstate.javasupport.action;

import io.cloudstate.javasupport.Metadata;

/** A message reply. */
public interface MessageReply<T> extends ControllerReply<T> {
public interface MessageReply<T> extends ActionReply<T> {

/**
* The payload of the message reply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import akka.http.scaladsl._
import akka.http.scaladsl.model._
import akka.stream.{ActorMaterializer, Materializer}
import com.google.protobuf.Descriptors
import io.cloudstate.javasupport.impl.controller.{ControllerService, StatelessFunctionImpl}
import io.cloudstate.javasupport.impl.action.{ActionService, StatelessFunctionImpl}
import io.cloudstate.javasupport.impl.eventsourced.{EventSourcedImpl, EventSourcedStatefulService}
import io.cloudstate.javasupport.impl.{EntityDiscoveryImpl, ResolvedServiceCallFactory, ResolvedServiceMethod}
import io.cloudstate.javasupport.impl.crdt.{CrdtImpl, CrdtStatefulService}
Expand Down Expand Up @@ -109,10 +109,10 @@ final class CloudStateRunner private[this] (
val crdtImpl = new CrdtImpl(system, crdtServices, rootContext)
route orElse CrdtHandler.partial(crdtImpl)

case (route, (serviceClass, controllerServices: Map[String, ControllerService] @unchecked))
if serviceClass == classOf[ControllerService] =>
val controllerImpl = new StatelessFunctionImpl(system, controllerServices, rootContext)
route orElse StatelessFunctionHandler.partial(controllerImpl)
case (route, (serviceClass, actionServices: Map[String, ActionService] @unchecked))
if serviceClass == classOf[ActionService] =>
val actionImpl = new StatelessFunctionImpl(system, actionServices, rootContext)
route orElse StatelessFunctionHandler.partial(actionImpl)

case (_, (serviceClass, _)) =>
sys.error(s"Unknown StatefulService: $serviceClass")
Expand Down
Loading

0 comments on commit 34ae044

Please sign in to comment.