<commit_before>/* Copyright 2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package almhirt.eventsourcing.impl

import java.util.UUID
import scalaz.syntax.validation._
import akka.actor.{ ActorRefFactory, Actor, Props }
import akka.pattern._
import akka.util.Timeout
import almhirt.almakka.AlmAkkaContext
import almhirt.messaging.Message
import almhirt._
import almhirt.almfuture.all._
import almhirt.domain.DomainEvent
import almhirt.eventsourcing._

class InefficientSerialziedInMemoryDomainEventLog(implicit almhirtContext: AlmhirtContext) extends DomainEventLog {
  implicit def timeout = Timeout(almhirtContext.mediumDuration)
  implicit def executionContext = almhirtContext.futureDispatcher
  var loggedEvents: List[DomainEvent] = Nil

  private case class LogEvents(events: List[DomainEvent])
  private case class LogEventsAsync(events: List[DomainEvent], ticket: Option[java.util.UUID])
  private case object GetAllEvents
  private case class GetEvents(entityId: UUID)
  private case class GetEventsFrom(entityId: UUID, from: Long)
  private case class GetEventsFromTo(entityId: UUID, from: Long, to: Long)

  private val coordinator = almhirtContext.actorSystem.actorOf(Props(new Coordinator()), "InefficientInMemoryEventLog")

  private class Coordinator() extends Actor with almakka.AlmActorLogging {
    def receive = {
      case LogEvents(events) =>
        loggedEvents = loggedEvents ++ events
        sender ! CommittedDomainEvents(events).success
      case LogEventsAsync(events, ticket) =>
        loggedEvents = loggedEvents ++ events
        ticket match {
          case Some(t) => almhirtContext.operationStateChannel.post(Message.createWithUuid(Ok(t)))
          case None => ()
        }
      case GetAllEvents =>
        sender ! loggedEvents.toIterable.success
      case GetEvents(entityId) =>
        val pinnedSender = sender
        AlmFuture { loggedEvents.view.filter(_.aggRootId == entityId).toIterable.success }.onComplete(pinnedSender ! _)
      case GetEventsFrom(entityId, from) =>
        val pinnedSender = sender
        AlmFuture { loggedEvents.view.filter(x =>x.aggRootId == entityId && x.aggRootVersion >= from).toIterable.success }.onComplete(pinnedSender ! _)<commit_msg>made field private"<commit_after>/* Copyright 2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package almhirt.eventsourcing.impl

import java.util.UUID
import scalaz.syntax.validation._
import akka.actor.{ ActorRefFactory, Actor, Props }
import akka.pattern._
import akka.util.Timeout
import almhirt.almakka.AlmAkkaContext
import almhirt.messaging.Message
import almhirt._
import almhirt.almfuture.all._
import almhirt.domain.DomainEvent
import almhirt.eventsourcing._

class InefficientSerialziedInMemoryDomainEventLog(implicit almhirtContext: AlmhirtContext) extends DomainEventLog {
  implicit def timeout = Timeout(almhirtContext.mediumDuration)
  implicit def executionContext = almhirtContext.futureDispatcher
  private var loggedEvents: List[DomainEvent] = Nil

  private case class LogEvents(events: List[DomainEvent])
  private case class LogEventsAsync(events: List[DomainEvent], ticket: Option[java.util.UUID])
  private case object GetAllEvents
  private case class GetEvents(entityId: UUID)
  private case class GetEventsFrom(entityId: UUID, from: Long)
  private case class GetEventsFromTo(entityId: UUID, from: Long, to: Long)

  private val coordinator = almhirtContext.actorSystem.actorOf(Props(new Coordinator()), "InefficientInMemoryEventLog")

  private class Coordinator() extends Actor with almakka.AlmActorLogging {
    def receive = {
      case LogEvents(events) =>
        loggedEvents = loggedEvents ++ events
        sender ! CommittedDomainEvents(events).success
      case LogEventsAsync(events, ticket) =>
        loggedEvents = loggedEvents ++ events
        ticket match {
          case Some(t) => almhirtContext.operationStateChannel.post(Message.createWithUuid(Ok(t)))
          case None => ()
        }
      case GetAllEvents =>
        sender ! loggedEvents.toIterable.success
      case GetEvents(entityId) =>
        val pinnedSender = sender
        AlmFuture { loggedEvents.view.filter(_.aggRootId == entityId).toIterable.success }.onComplete(pinnedSender ! _)
      case GetEventsFrom(entityId, from) =>
        val pinnedSender = sender
        AlmFuture { loggedEvents.view.filter(x =>x.aggRootId == entityId && x.aggRootVersion >= from).toIterable.success }.onComplete(pinnedSender ! _)
{'fraction_non_alphanumeric': 0.07884195193008012, 'fraction_numerical': 0.0029133284777858705, 'mean_word_length': 4.241412213740458, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '836339', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1491, 'n_words': 453}