|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Target(value={PARAMETER,FIELD,METHOD})
@Retention(value=RUNTIME)
public @interface Shared
The Shared annotation is used to state that a variable, field or property
refers to a thread-safe object that can be shared among actors.
@Shared is used for three purposes:
Message annotations, to mark an argument as
shared between caller and called actor
Actor, to mark the field as refering to an object that
can be safely used in a ConcurrencyModel.Stateless actor or method
Prop annotated getter, to mark the property as refering to an object
that can be safely used in a ConcurrencyModel.Stateless actor or method@Shared must be fully
multi-thead-safe, as they will be used in several threads simultanously.
@Shared as method argument annotation should be avoided if possible,
as shared can only work if caller and callee run in the same VM. Currently ActorsGuild
supports only actors in the same VM, and thus it will always work, but in future
versions this may be different.
Example:
@Message public AsyncResultsendMessage(@Shared Socket socket, String msg) throws Exception { try { String path = HTTPHelper.readHeader(socket.getInputStream()); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); bw.write(msg); bw.flush(); } finally { socket.close(); } return noResult(); }
ConcurrencyModel.Stateless actors must not have any state, it is forbidden
for them to have any non-final field, but they actors to be configured at
their creation with final fields referring to Immutable values or actors.
However, an exception is being made for final fields annotated with @Shared.
This is needed sometimes, for example to configure a JDBC DataSource.
ConcurrencyModel.Stateless messages in non-stateless actors are required to use
only stateless fields of the actor, thus final fields refering to immutable values,
actors or that use a @Shared annotation.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||