score:0
you could also use the produce directive. it allows you to decouple the actual marshalling from the request completion:
get {
produce(instanceof[person]) { personcompleter =>
databaseactor ! showpersonjob(personcompleter)
}
}
the produce directive in this example extracts a function person => unit that you can use to complete the request transparently deep within the business logic layer, which should not be aware of spray.
https://github.com/spray/spray/wiki/marshalling-unmarshalling
score:3
in regards to your first question, yes, you are on the right track. (although i would also like to see some alternative ways to handle this sort of issue).
one suggestion i have is to insulate the persister
actor from knowing about requests at all. you can pass the request as an any
type. your matcher in your service code can automagically cast the cookie back into a request
.
case class schedulepersisted(businessobjectid: string, cookie: any)
// in your actor
override def receive = super.receive orelse {
case schedulepersisted(businessobjectid, request: request) =>
request.complete("/businessobject/%s".format(businessobjectid))
}
in regards to your second question, actor classes are really no different than regular classes. but you do need to make sure you call the superclass's receive
method, so that it can handle its own messages. i had some other ways of doing this in my original answer, but i think i prefer chaining partial functions like this:
class specialhttpservice extends httpservice {
override def receive = super.receive orelse {
case specialmessage(x) =>
// handle special message
}
}
Source: stackoverflow.com
Related Query
- How to implement Actor based HTTP Routing in Akka
- How to properly test actor behavior in case of failure
- How to use scala actor based event sourcing app from another language (python)
- How to set up logging in akka-typed so that actor paths are properly showing?
- How can I get the name of an Akka actor from within the actor itself?
- Akka - How many instances of an actor should you create?
- How to restrict actor messages to specific types?
- How to get Akka actor by name as an ActorRef?
- How do I create a TestActorRef in Scala for an Actor with constructor params?
- Actor-based webservice - How to do it properly?
- Design patterns for Agent / Actor based concurrent design
- How to wait for Akka actor system to terminate?
- how to use asInstanceOf properly in Scala
- How to debug a scala based Spark program on Intellij IDEA
- How do the Scala based frameworks stack up for a complete Scala newbie - Lift, Play, Circumflex, etc
- SPARK DataFrame: How to efficiently split dataframe for each group based on same column values
- How to update column based on a condition (a value in a group)?
- akka: how to test that an actor was stopped
- How do I filter rows based on whether a column value is in a Set of Strings in a Spark DataFrame
- How to generate datasets dynamically based on schema?
- How to properly access dbutils in Scala when using Databricks Connect
- How to write a timer actor in Scala?
- How is "become" implemented in languages that support the actor model?
- How to select akka actor with actorSelection?
- How to test Akka Actor functionality by mocking one or more methods in it
- How to get the actor system reference from inside the actor
- How to test that Akka actor was created in Scala
- How do I test an Akka actor that sends a message to another actor?
- How do I get the absolute remote actor url from inside the actor?
- How to call the correct method in Scala/Java based the types of two objects without using a switch statement?
More Query from same tag
- Best way to instantiate a type parameter class in Scala
- Invoke a java method which accepts `<? super T>` type parameter from scala code?
- Backquote Used in Scala Swing Event
- jupyter-scala install behind a proxy
- Curried type "does not take type parameters"
- Filtering futures using values in another future
- Def macro - scala 2.13 - not found: value cond
- How to access Tuples of a List in a Map in Scala?
- Security of scala runtime
- Flattening nested JSON objects with Circe
- How do you uninstall the Scala Eclipse plugin?
- Scala application compiles error in IDEA due to the connection refuse
- Spray - deserializing optional query parameter
- Scala implicit return and if-then-else statement
- ConcurrentModificationException when using Spark collectionAccumulator
- get one random letter from each tuple then return them all as a string
- Gatling - UniformRandomSwitch doesn't work as expected
- Scala - Updating JFreeChart with Swing
- My Play Application's Constructor takes an argument, how do I give a mocked argument at Spec Test?
- Delay a shutdown when background actors must finish their tasks
- How to pass error message dynamically to a custom exception in scala
- For comprehension and number of function creation
- Scala .init method example
- I'm using Scala 2.11.7 but sbt tries to compile my classes to target/scala-2.10
- Filters not working in play 2.5.X
- Inner join in spark dataframes not getting proper columns as expected
- Implicit Resolution Failure?
- How to perform a join and/or cogroup operation on two maps in scala
- Scala-fy a java function?
- AUX pattern workaround