Hi all, 

I am working on a video recoding application with Akka and I have a bunch 
of actors which share a bit of information, namely how to start a recording.

There are different ways of starting a recording, so I use a base trait and 
specific case classes. 

For example:
sealed trait StartRecording

/** Start recording at a given date*/
case class StartRecordingByDate(date: Long) extends StartRecording

/** Start recording straight away*/
case object StartRecordingStraightAway extends StartRecording

I want to be able to mutate how a recording start (i.e. update the start 
time, or even better change the start record mode), so I was thinking of 
using an Agent[StartRecording]. However, Agents are invariant so this does 
not really work.

One option is was thinking about is to have a wrapper and create an agent 
for that wrapper, like so:

case class Wrapper(wrapped: StartRecording)

val agent = Agent(Wrapper(StartRecordingStraighAway))

This compiles and work, but I am wondering if it is a good idea or if there 
is a better way.

Guillaume.

PS: Here is a working code example:

package org.kafecho.learning.akka


import akka.actor.ActorSystem

import akka.agent.Agent


object AgentTest extends App{

sealed trait StartRecording


/** Start recording at a given date*/

case class StartRecordingByDate(date: Long) extends StartRecording


/** Start recording straight away*/

case object StartRecordingStraightAway extends StartRecording


implicit val system = ActorSystem("Agents")


val agent = Agent(StartRecordingStraightAway)


// This does not compile

//agent.update(StartRecordingByDate(System.currentTimeMillis() + 1000))


case class Wrapper(startRecording: StartRecording)


// This compiles, but is it a good idea?

val agent2 = Agent(Wrapper(StartRecordingStraightAway))

agent2.update(Wrapper(StartRecordingByDate(System.currentTimeMillis() + 1000
)))

}



-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to