2010-08-19 07:01:09 +02:00
|
|
|
/**
|
2010-12-22 15:35:50 +01:00
|
|
|
* Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
|
2010-08-19 07:01:09 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-10-26 12:49:25 +02:00
|
|
|
package akka
|
2010-08-19 07:01:09 +02:00
|
|
|
|
2010-10-26 12:49:25 +02:00
|
|
|
import akka.actor.newUuid
|
2010-08-19 07:01:09 +02:00
|
|
|
|
|
|
|
|
import java.io.{StringWriter, PrintWriter}
|
|
|
|
|
import java.net.{InetAddress, UnknownHostException}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Akka base Exception. Each Exception gets:
|
|
|
|
|
* <ul>
|
|
|
|
|
* <li>a UUID for tracking purposes</li>
|
|
|
|
|
* <li>a message including exception name, uuid, original message and the stacktrace</li>
|
|
|
|
|
* <li>a method 'log' that will log the exception once and only once</li>
|
|
|
|
|
* </ul>
|
2010-08-21 16:13:16 +02:00
|
|
|
*
|
2010-08-19 07:01:09 +02:00
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2011-03-26 20:02:33 +01:00
|
|
|
@serializable abstract class AkkaException(message: String = "") extends {
|
2010-08-19 07:01:09 +02:00
|
|
|
val exceptionName = getClass.getName
|
2011-03-22 14:21:03 +01:00
|
|
|
val uuid = "%s_%s".format(AkkaException.hostname, newUuid)
|
|
|
|
|
} with RuntimeException(message) {
|
2011-04-05 19:07:27 +12:00
|
|
|
override lazy val toString = "%s\n\t[%s]\n\t%s".format(exceptionName, uuid, message)
|
2010-08-19 07:01:09 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-28 22:54:32 +01:00
|
|
|
object AkkaException {
|
2010-08-21 16:13:16 +02:00
|
|
|
val hostname = try {
|
2010-08-19 07:01:09 +02:00
|
|
|
InetAddress.getLocalHost.getHostName
|
|
|
|
|
} catch {
|
|
|
|
|
case e: UnknownHostException => "unknown"
|
|
|
|
|
}
|
|
|
|
|
}
|