Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aorwall committed Jan 14, 2013
1 parent 4c8a08f commit 273104e
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import akka.actor.{Actor, ActorRef, ActorLogging}
import akka.util.duration._
import se.callista.loganalyzer.{AccessLog, ConfirmationMessage, LogMessage, HandleUnprocessedLogs}

class LogAgent(hostname: String, server: ActorRef) extends Actor with ActorLogging {
class LogAgent(
val hostname: String, // hostname of the agent
val server: ActorRef // actor reference to the log service
) extends Actor with ActorLogging {

def receive = {
case None => // replace this row
Expand Down
18 changes: 18 additions & 0 deletions common/src/main/scala/se/callista/loganalyzer/AccessLog.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package se.callista.loganalyzer

import java.text.SimpleDateFormat
import java.util.Date

case class AccessLog(
ip: String,
timestamp: Date,
method: String,
path: String,
statusCode: Int,
size: Int) {

override def toString = {
val formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z")
ip + " - - [" + formatter.format(timestamp) + "] " + method + " " + path + " " + statusCode + " " + size
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package se.callista.loganalyzer

case class ConfirmationMessage(id: Int)
16 changes: 1 addition & 15 deletions common/src/main/scala/se/callista/loganalyzer/Count.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
package se.callista.loganalyzer

case class Count(
status: HttpStatus,
status: HttpStatus, // Success, ClientError or ServerError
count: Int) {

def toJson = "{ \"status\":\"%s\", \"count\": %s }".format(status, count)

}

abstract class HttpStatus

case object Success extends HttpStatus {
override def toString = "success"
}

case object ClientError extends HttpStatus{
override def toString = "clientError"
}

case object ServerError extends HttpStatus{
override def toString = "serverError"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package se.callista.loganalyzer

/**
* Use this object to trigger LogAgent to handle unprocessed logs
*/
case object HandleUnprocessedLogs
15 changes: 15 additions & 0 deletions common/src/main/scala/se/callista/loganalyzer/HttpStatus.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package se.callista.loganalyzer

abstract class HttpStatus

case object Success extends HttpStatus {
override def toString = "success"
}

case object ClientError extends HttpStatus{
override def toString = "clientError"
}

case object ServerError extends HttpStatus{
override def toString = "serverError"
}
21 changes: 1 addition & 20 deletions common/src/main/scala/se/callista/loganalyzer/LogMessage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,4 @@ package se.callista.loganalyzer
import java.util.Date
import java.text.SimpleDateFormat

case class AccessLog(
ip: String,
timestamp: Date,
method: String,
path: String,
statusCode: Int,
size: Int) {


override def toString = {
val formatter = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z")
ip + " - - [" + formatter.format(timestamp) + "] " + method + " " + path + " " + statusCode + " " + size
}
}

case class LogMessage(host: String, id: Int, log: AccessLog)

case class ConfirmationMessage(id: Int)

case object HandleUnprocessedLogs
case class LogMessage(host: String, id: Int, log: AccessLog)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class Database {
def latestTwenty: Seq[AccessLog] = {
(for( (_,keys) <- timeline.takeRight(20); key <- keys) yield logs(key) ).toList.take(20)
}
}
}

object StableDatabase extends Database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import akka.actor._
import akka.actor.SupervisorStrategy.Restart
import se.callista.loganalyzer._

class LogServer(presenter: ActorRef) extends Actor with ActorLogging {
class LogServer(
val presenter: ActorRef // actor reference to the presenter
) extends Actor with ActorLogging {

def receive = {
case None => // replace this row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import scala.collection.mutable.HashSet
import akka.actor.{Actor, ActorLogging, ActorRef}
import se.callista.loganalyzer.{Count, HttpStatus, LogMessage}

class StatusCounter(status: HttpStatus, presenter: ActorRef) extends Actor with ActorLogging {
class StatusCounter(
val status: HttpStatus, // HTTP Status (Success, ClientError or ServerError)
val presenter: ActorRef // actor reference to the presenter
) extends Actor with ActorLogging {

def receive = {
case None => // replace this row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package se.callista.loganalyzer.server

import scala.collection.mutable.Map
import akka.actor.Actor
import se.callista.loganalyzer.Count
import se.callista.loganalyzer.HttpStatus
import se.callista.loganalyzer.{Count, HttpStatus}
import unfiltered.netty.websockets.WebSocket

/**
Expand Down

0 comments on commit 273104e

Please sign in to comment.