Concepts: Useful Annotations

Joe Hegarty edited this page Oct 12, 2016 · 8 revisions

Actor Interface Annotations

StatelessWorker

@StatelessWorker
interface MyActor extends Actor {}

Causes your actor to be a stateless worker. See stateless workers.

NoIdentity

@NoIdentity
interface MyActor extends Actor {}

Denotes that this actor does not have an identity and acts as a singleton. Actor is accessed using Actor.getReference(clazz) instead of Actor.getReference(clazz, id).

PreferLocalPlacement

@PreferLocalPlacement(percentile=100)
interface MyActor extends Actor {}

Denotes that this actor should prefer to be placed locally if not already activated and the local node is capable of hosting it. Optional percentile value allows developers to define the likelihood of preferring local placement (default 100).

NeverDeactivate

@NeverDeactivate
interface MyActor extends Actor {}

Denotes that this actor should prefer not to deactivate once it has been activated, overriding the default deactivation due to inactivity. Please Note: This is a hint, the actor will not start automatically and may still be deactivated in the case of node failure. Applications should ping the actor regularly if they need to ensure it is always alive.

Message Interface Annotations

OneWay

@OneWay
Task someMessage();

This message is OneWay. No result (value or status) will be returned, no guarantee that message will be processed. The Task might contain an exception if there was a problem locating the target object or serializing the message.

OnlyIfActivated

@OnlyIfActivated
Task someMessage();

This message is only executed if the actor has already been activated. Unlike normal messages, this will not cause an actor to activate.

CacheResponse

@CacheResponse(maxEntries = 1000, ttlDuration = 5, ttlUnit = TimeUnit.SECONDS)
Task<String> getAccountName(int id);

This message caches its result, on a per actor, per parameter-set basis. The data persists for the given duration, or until at least the specified number of entries has been reached (whichever constraint is encountered first). Cached values are not guaranteed to immediately evict once maxEntries has been reached.

Caches can be force-flushed using ExecutionCacheFlushManager.

Message Implementation Annotations

Reentrant

@Reentrant
Task<Void> doSomething() {}

Causes your message to be reentrant. See reentrancy.

DTO Annotations

Immutable

@Immutable
class SomeMessageDTO {}

Denotes that an object is considered immutable and therefore the framework does not need to clone it. The application must ensure that the object is actually immutable and does not change once it has been passed to the framework.