Skip to content

Commit

Permalink
add null constraints for better Kotlin compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijgerd committed Mar 16, 2023
1 parent eceaea2 commit 0e28136
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.elasticsoftware.elasticactors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map;
Expand Down Expand Up @@ -52,6 +53,7 @@ public interface ActorContext {
*
* @return the {@link ActorRef} instance that references the Actor
*/
@Nonnull
ActorRef getSelf();

/**
Expand All @@ -74,12 +76,14 @@ public interface ActorContext {
*
* @param state the new {@link ActorState} to set (and store)
*/
void setState(ActorState state);
@SuppressWarnings("rawtypes")
void setState(@Nonnull ActorState state);

/**
*
* @return the {@link ActorSystem} this actor is part of
*/
@Nonnull
ActorSystem getActorSystem();

/**
Expand All @@ -93,6 +97,7 @@ public interface ActorContext {
*
* @return the collection of {@link PersistentSubscription}s or and empty collection if there are none
*/
@Nonnull
Collection<PersistentSubscription> getSubscriptions();

/**
Expand All @@ -103,5 +108,6 @@ public interface ActorContext {
* (class)Name and as a value the Set of subscribed actors. If there are no subscribers and empty Map will
* be returned
*/
@Nonnull
Map<String, Set<ActorRef>> getSubscribers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package org.elasticsoftware.elasticactors;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
* @author Joost van de Wijgerd
*/
@ParametersAreNonnullByDefault
public interface ActorLifecycleListener<T extends ActorState> {
Class<? extends ElasticActor> getActorClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import org.elasticsoftware.elasticactors.concurrent.ActorCompletableFuture;
import org.reactivestreams.Publisher;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* This is the main entry point for the ElasticActors API. When a {@link org.elasticsoftware.elasticactors.serialization.Message}
* needs to be send to an {@link ElasticActor} first the {@link ActorRef} needs to be obtained. An Actor Reference
Expand All @@ -41,13 +44,15 @@
* @author Joost van de Wijgerd
*/
public interface ActorRef {
@Nonnull
String getActorCluster();
/**
* The path of an actor is the Shard (or Node) where the actor is located. It looks like:
* {@code <actorSystem>/shards/<shardId>} or {@code <actorSystem>/nodes/<nodeId>}
*
* @return the actor path as a string
*/
@Nonnull
String getActorPath();

/**
Expand All @@ -59,6 +64,7 @@ public interface ActorRef {
* @see ActorSystem#serviceActorFor(String)
* @return the actor id for this {@link ActorRef}
*/
@Nonnull
String getActorId();

/**
Expand All @@ -68,7 +74,7 @@ public interface ActorRef {
* @param sender the sender, this can be self, but it can also be another {@link ActorRef}
* @throws MessageDeliveryException when something is wrong with the Messaging Subsystem
*/
void tell(Object message, ActorRef sender) throws MessageDeliveryException;
void tell(@Nonnull Object message,@Nullable ActorRef sender) throws MessageDeliveryException;

/**
* Equivalent to calling ActorRef.tell(message,getSelf())
Expand All @@ -77,7 +83,7 @@ public interface ActorRef {
* @throws IllegalStateException if the method is not called withing a {@link ElasticActor} lifecycle or on(Message) method
* @throws MessageDeliveryException when somthing is wrong with the Messaging Subsystem
*/
void tell(Object message) throws IllegalStateException, MessageDeliveryException;
void tell(@Nonnull Object message) throws IllegalStateException, MessageDeliveryException;

/**
* Send a message to an {@link ElasticActor} and request a response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.elasticsoftware.elasticactors;

import javax.annotation.Nullable;
import java.util.Collection;

/**
Expand All @@ -30,7 +31,7 @@ public interface ActorRefGroup {
* @param sender the sender, this can be self, but it can also be another {@link ActorRef}
* @throws MessageDeliveryException when something is wrong with the Messaging Subsystem
*/
void tell(Object message, ActorRef sender) throws MessageDeliveryException;
void tell(Object message, @Nullable ActorRef sender) throws MessageDeliveryException;

/**
* Equivalent to calling ActorRefGroup.tell(message,getSelf())
Expand All @@ -41,9 +42,11 @@ public interface ActorRefGroup {
*/
void tell(Object message) throws IllegalStateException, MessageDeliveryException;

@SuppressWarnings("unused")
Collection<? extends ActorRef> getMembers();

@SuppressWarnings("unused")
ActorRefGroup withMembersAdded(ActorRef... membersToAdd);

@SuppressWarnings("unused")
ActorRefGroup withMembersRemoved(ActorRef... membersToRemove);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import org.elasticsoftware.elasticactors.serialization.SerializationFramework;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Tagging interface for the state object of an {@link ElasticActor}. The interface has a generic
* type Body that should normally be the same type as the implementing class. The reason behind this
Expand All @@ -34,13 +37,15 @@ public interface ActorState<Body> {
*
* @return the body (the actual state)
*/
@Nonnull
Body getBody();

/**
* The type of the SerializationFramework that should be used to serialize this state class
*
* @return the type of the SerializationFramework that should be used to serialize this state class
*/
@Nonnull
Class<? extends SerializationFramework> getSerializationFramework();
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsoftware.elasticactors.cluster.ActorSystemEventListenerRegistry;
import org.elasticsoftware.elasticactors.scheduler.Scheduler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;

Expand All @@ -40,6 +41,7 @@ public interface ActorSystem {
*
* @return the name of this {@link ActorSystem}
*/
@Nonnull
String getName();

/**
Expand All @@ -56,6 +58,7 @@ public interface ActorSystem {
* @return the {@link ActorRef} pointing to the newly created actor
* @throws Exception when something unexpected happens
*/
@Nonnull
<T> ActorRef actorOf(String actorId, Class<T> actorClass) throws Exception;


Expand All @@ -78,6 +81,7 @@ public interface ActorSystem {
* @return the {@link ActorRef} pointing to the newly created actor
* @throws Exception when something unexpected happens
*/
@Nonnull
ActorRef actorOf(String actorId, String actorClassName) throws Exception;

/**
Expand All @@ -95,6 +99,7 @@ public interface ActorSystem {
* @return the {@link ActorRef} pointing to the newly created actor
* @throws Exception when something unexpected happens
*/
@Nonnull
<T> ActorRef actorOf(String actorId, Class<T> actorClass, ActorState initialState) throws Exception;

/**
Expand All @@ -117,8 +122,10 @@ public interface ActorSystem {
* @return the {@link ActorRef} pointing to the newly created actor
* @throws Exception when something unexpected happens
*/
@Nonnull
ActorRef actorOf(String actorId, String actorClassName, ActorState initialState) throws Exception;

@Nonnull
ActorRef actorOf(String actorId, String actorClassName, ActorState initialState, ActorRef creatorRef) throws Exception;

/**
Expand All @@ -135,6 +142,7 @@ public interface ActorSystem {
* @throws Exception when something unexpected happens
* @return the {@link ActorRef} pointing to the newly created actor
*/
@Nonnull
<T> ActorRef tempActorOf(Class<T> actorClass,@Nullable ActorState initialState) throws Exception;

/**
Expand All @@ -148,6 +156,7 @@ public interface ActorSystem {
* @param actorId the id of the (Standard) Actor to reference
* @return the {@link ActorRef} to the Actor (not guaranteed to exist!)
*/
@Nonnull
ActorRef actorFor(String actorId);

/**
Expand All @@ -158,6 +167,7 @@ public interface ActorSystem {
* @param actorId the id of the Service Actor to reference
* @return the {@link ActorRef} to the Service Actor
*/
@Nonnull
ActorRef serviceActorFor(String actorId);

/**
Expand All @@ -171,6 +181,7 @@ public interface ActorSystem {
* @param actorId the id of the Service Actor to reference
* @return the {@link ActorRef} to the Service Actor
*/
@Nonnull
ActorRef serviceActorFor(String nodeId, String actorId);

/**
Expand All @@ -179,6 +190,7 @@ public interface ActorSystem {
*
* @return the configured {@link Scheduler}
*/
@Nonnull
Scheduler getScheduler();

/**
Expand All @@ -187,6 +199,7 @@ public interface ActorSystem {
*
* @return the parent of this {@link ActorSystem}
*/
@Nonnull
ActorSystems getParent();

/**
Expand All @@ -204,6 +217,7 @@ public interface ActorSystem {
*
* @return the configuration object
*/
@Nonnull
ActorSystemConfiguration getConfiguration();

/**
Expand All @@ -216,6 +230,7 @@ public interface ActorSystem {
*
* @return the {@link org.elasticsoftware.elasticactors.cluster.ActorSystemEventListenerRegistry} for this {@link org.elasticsoftware.elasticactors.ActorSystem}
*/
@Nonnull
ActorSystemEventListenerRegistry getEventListenerRegistry();

/**
Expand All @@ -230,6 +245,7 @@ public interface ActorSystem {
* @throws IllegalArgumentException if one of the members is not a Persistent Actor
* (i.e. not created with {@link #actorOf(String, Class, ActorState)}, {@link #actorOf(String, Class)} or {@link #actorFor(String)} }
*/
@Nonnull
ActorRefGroup groupOf(Collection<ActorRef> members) throws IllegalArgumentException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.elasticsoftware.elasticactors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* @author Joost van de Wijgerd
*/
Expand All @@ -26,6 +29,7 @@ public interface ActorSystemConfiguration {
*
* @return the name of this {@link ActorSystem}
*/
@Nonnull
String getName();

/**
Expand Down Expand Up @@ -123,6 +127,7 @@ public interface ActorSystemConfiguration {
*
* @return the version of the ActorSystem
*/
@Nonnull
String getVersion();

/**
Expand All @@ -136,6 +141,7 @@ public interface ActorSystemConfiguration {
* @return the property value associated with the given key, or {@code null} if the key cannot be resolved.
* @see #getRequiredProperty(Class, String, Class)
*/
@Nullable
<T> T getProperty(Class component,String key, Class<T> targetType);

/**
Expand All @@ -150,6 +156,7 @@ public interface ActorSystemConfiguration {
* @return the property value associated with the given key, or {@code defaultValue} if the key cannot be resolved.
* @see #getRequiredProperty(Class,String, Class)
*/
@Nonnull
<T> T getProperty(Class component,String key, Class<T> targetType, T defaultValue);

/**
Expand All @@ -163,7 +170,9 @@ public interface ActorSystemConfiguration {
* @return the property value associated with the given key, converted to the given {@code targetType} (never {@code null}).
* @throws IllegalStateException if the given key cannot be resolved
*/
<T> T getRequiredProperty(Class component,String key, Class<T> targetType) throws IllegalStateException;
@SuppressWarnings("unused")
@Nonnull
<T> T getRequiredProperty(Class component,String key, Class<T> targetType) throws IllegalStateException;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.elasticsoftware.elasticactors.cluster.RebalancingEventListener;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
Expand All @@ -33,6 +34,7 @@ public interface ActorSystems {
*
* @return the name of the local ElasticActors cluster
*/
@Nonnull
String getClusterName();

/**
Expand All @@ -41,6 +43,7 @@ public interface ActorSystems {
* @param actorSystemName the name of the {@link ActorSystem} or null to get the default
* @return the local {@link ActorSystem} instance
*/
@Nonnull
ActorSystem get(@Nullable String actorSystemName);

/**
Expand All @@ -51,6 +54,7 @@ public interface ActorSystems {
* @param actorSystemName the {@link ActorSystem} name in the remote cluster or null to get the default
* @return the remote {@link ActorSystem} instance or null if it doesn't exist / is not configured
*/
@Nullable
ActorSystem getRemote(String clusterName,@Nullable String actorSystemName);

/**
Expand All @@ -62,6 +66,7 @@ public interface ActorSystems {
* @return the remote {@link ActorSystem} instance or null if it doesn't exist / is not configured
* @throws IllegalArgumentException if there is more than one match
*/
@Nullable
ActorSystem getRemote(String actorSystemName);

/**
Expand Down
Loading

0 comments on commit 0e28136

Please sign in to comment.