Suppose I have some class which has a property actor_
of type Actor
. Is there a problem with me doing
def someMethod() = {
actor_ ! "HELLO"
}
Or should sending a message always be done from another actor; e.g.
def someMethod() = {
Actor.actor { actor_ ! "HELLO" }
}
In Akka, actors communicate to each other by sending and receiving messages. Akka provides two predefined methods tell() and ask() for message exchange. An actor can send messages to another Actor through these following methods. It is used to send a message asynchronously.
An actor does not belong to the system: it should therefore not appear as a lifeline. Typically, what should appear as a lifeline instead, is an instance of some classifier that belongs to the UI and that would notify the user of the information.
It is however a common and convenient practice to include an actor in a sequence diagram. After all, the UML standard sees the actor as a classifier (clause 18.1.2), although it doesn't belong to the system. As this is not foreseen by the standard, there are no clear rules about what can be done and the applicable semantics.
The threat actor appeared to have a goal of network disruption and appeared to use a common security hack tool that overwhelmed a particular server with a large amount of traffic. This traffic rendered the server inoperable.
It depends. When you send a message to an actor from non-actor code, an ActorProxy is automatically created and stored in a thread local. This creates a potential memory leak, albeit a very small one, because the ActorProxy won't be GC'd until the thread is GC'd. The ActorProxy essentially enables the non-actor thread to in many ways behave like an Actor, including receiving message.
The bigger problem is if your thread being managed, similar to the way the actor library manages threads, so that what represents a logical context may at one time be on one thread, and at another time be on another thread. A good example of this would be a servlet container. Your logical context may be a servlet or a session, but the ActorProxy is going to be bound to the thread, and thus shared across logical contexts. If your actors aren't replying to the ActorProxy this isn't such a big deal, but if they are it will likely lead to problems because either (a) the replies will potentially be received by the wrong context, or (b) the messages are never received, and thus the previously mentioned small leak becomes a large one as the mailboxes of the ActorProxies fill up.
[Edit] Hmm...I seem to have a problem reading questions! Surrounding it in the actor block creates a new actor object that will be GC'd properly when it terminates. Keep in mind that putting the message send in an actor block means that the message send will be done in a new reaction on another thread, not in the thread creating the actor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With