Skip to content

Commit

Permalink
minor cleanup of type param and improved trace label
Browse files Browse the repository at this point in the history
  • Loading branch information
dmrolfs committed Jun 8, 2016
1 parent 8f1aa5e commit 8cbab34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 10 additions & 13 deletions core/src/main/scala/demesne/AggregateRoot.scala
@@ -1,17 +1,17 @@
package demesne

import scala.reflect.ClassTag
import akka.actor.{ActorLogging, ReceiveTimeout}
import akka.event.LoggingReceive
import akka.persistence.{PersistentActor, SnapshotOffer}
import peds.akka.envelope._
import peds.akka.publish.EventPublisher
import peds.archetype.domain.model.core.Identifiable
import peds.commons.identifier.TaggedID
import peds.commons.{KOp, TryV}
import peds.commons.log.Trace
import peds.commons.util._

import scalaz._
import Scalaz._
import scalaz.Kleisli._


Expand All @@ -31,18 +31,17 @@ object AggregateRoot {
type Acceptance[S] = PartialFunction[(Any, S), S]
}

abstract class AggregateRoot[S]
abstract class AggregateRoot[S: ClassTag]
extends PersistentActor
with EnvelopingActor
with DomainModel.Provider
with AggregateRootType.Provider
with ActorLogging {
outer: EventPublisher =>

type Valid[A] = NonEmptyList[Throwable] \/ A
type StateOperation = Kleisli[Valid, S, S]
type StateOperation = KOp[S, S]

val trace = Trace( "AggregateRoot", log )
val trace = Trace( s"AggregateRoot[${implicitly[ClassTag[S]].runtimeClass.safeSimpleName}]", log )

type Acceptance = AggregateRoot.Acceptance[S]
def acceptance: Acceptance
Expand Down Expand Up @@ -79,11 +78,11 @@ with ActorLogging {
def accept( event: Any ): S = {
acceptOp(event) run state match {
case \/-(s) => s
case -\/(ex) => throw ex.head
case -\/(ex) => throw ex
}
}

def acceptOp( event: Any ): StateOperation = kleisli[Valid, S, S] { (s: S) =>
def acceptOp( event: Any ): StateOperation = kleisli[TryV, S, S] { s =>
trace.block( s"acceptOp($event, $s)" ) {
\/.fromTryCatchNonFatal[S] {
val eventState = (event, s)
Expand All @@ -98,18 +97,16 @@ with ActorLogging {
log debug s"""${Option(s).map{_.getClass.safeSimpleName}} does not accept event ${event.getClass.safeSimpleName}"""
s
}
} leftMap {
NonEmptyList( _ )
}
}
}

def publishOp( event: Any ): StateOperation = kleisli[Valid, S, S] { (s: S) =>
def publishOp( event: Any ): StateOperation = kleisli[TryV, S, S] { s =>
trace.block( s"publishOp($event, $s)" ) {
\/.fromTryCatchNonFatal[S] {
publish( event )
s
} leftMap { NonEmptyList( _ ) }
}
}
}

Expand All @@ -118,7 +115,7 @@ with ActorLogging {
def acceptAndPublish( event: Any ): S = {
acceptAndPublishOp( event ) run state match {
case \/-(s) => s
case -\/(ex) => throw ex.head
case -\/(ex) => throw ex
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/demesne/SagaModule.scala
@@ -1,10 +1,11 @@
package demesne

import scala.reflect.ClassTag
import peds.akka.publish.EventPublisher
import peds.archetype.domain.model.core.Identifying


abstract class SagaModule[I: Identifying] extends AggregateRootModule[I]


abstract class Saga[S] extends AggregateRoot[S] { outer: EventPublisher => }
abstract class Saga[S: ClassTag] extends AggregateRoot[S] { outer: EventPublisher => }

0 comments on commit 8cbab34

Please sign in to comment.