Skip to content

Commit

Permalink
use json4s instead of lift-json
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Jun 16, 2013
1 parent 1bbfdff commit d60e355
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object HookupBuild extends Build {
libraryDependencies ++= Seq(
"io.netty" % "netty" % "3.6.6.Final",
"com.github.nscala-time" %% "nscala-time" % "0.4.2",
"net.liftweb" %% "lift-json" % "2.5" % "compile",
"org.json4s" %% "json4s-jackson" % "3.2.4" % "compile",
"commons-io" % "commons-io" % "2.4",
"com.typesafe.akka" %% "akka-actor" % "2.1.4" % "compile",
"com.typesafe.akka" %% "akka-testkit" % "2.1.4" % "test",
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/io/backchat/hookup/buffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.io._
import java.util.concurrent.ConcurrentLinkedQueue
import collection.mutable
import scala.concurrent.{ Promise, ExecutionContext, Future }
import net.liftweb.json.Formats
import org.json4s._
import collection.JavaConverters._
import java.util.Queue
import collection.mutable.{ Queue ScalaQueue }
Expand Down Expand Up @@ -143,10 +143,10 @@ class FileBuffer private[hookup] (file: File, writeToFile: Boolean, memoryBuffer

/**
* Drain the buffer using the `readLine` function to process each message in the buffer.
* This method works with [[scala.concurrent.Future]] objects and needs an [[akka.dispatch.ExecutionContext]] in scope
* This method works with [[scala.concurrent.Future]] objects and needs an [[scala.concurrent.ExecutionContext]] in scope
*
* @param readLine A function that takes a [[io.backchat.hookup.OutboundMessage]] and produces a [[scala.concurrent.Future]] of [[io.backchat.hookup.OperationResult]]
* @param executionContext An [[akka.dispatch.ExecutionContext]]
* @param executionContext An [[scala.concurrent.ExecutionContext]]
* @return A [[scala.concurrent.Future]] of [[io.backchat.hookup.OperationResult]]
*/
def drain(readLine: (OutboundMessage Future[OperationResult]))(implicit executionContext: ExecutionContext, wireFormat: WireFormat): Future[OperationResult] = synchronized {
Expand Down
28 changes: 14 additions & 14 deletions src/main/scala/io/backchat/hookup/client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import org.jboss.netty.util.{ Timeout ⇒ NettyTimeout, TimerTask, HashedWheelTi
import scala.concurrent.duration.Duration
import java.net.{ ConnectException, InetSocketAddress, URI }
import java.nio.channels.ClosedChannelException
import net.liftweb.json.JsonAST.JValue
import net.liftweb.json.{JsonParser, DefaultFormats, Formats, parse, render, compact}
import org.json4s._
import org.json4s.jackson.JsonMethods._
import java.io.{Closeable, File}
import java.util.concurrent.{ConcurrentSkipListSet, TimeUnit, Executors}
import beans.BeanProperty
Expand Down Expand Up @@ -601,13 +601,13 @@ trait HookupClient extends HookupClientLike with Connectable with Reconnectable

/**
* The execution context for futures within this client.
* @return The [[akka.dispatch.ExecutionContext]]
* @return The [[scala.concurrent.ExecutionContext]]
*/
implicit protected lazy val executionContext: ExecutionContext = settings.executionContext

// /**
// * The lift-json formats to use when serializing json values.
// * @return The [[net.liftweb.json.Formats]]
// * The json4s formats to use when serializing json values.
// * @return The [[org.json4s.Formats]]
// */
// implicit protected def jsonFormats: Formats = DefaultFormats
//
Expand Down Expand Up @@ -736,7 +736,7 @@ trait WebSocketListener {
* The callback method for when an error has occured
*
* @param client The client that received the message
* @param error The message it received the throwable if any, otherwise null
* @param reason The message it received the throwable if any, otherwise null
*/
def onError(client: HookupClient, reason: Throwable): Unit = ()

Expand All @@ -752,7 +752,7 @@ trait WebSocketListener {
* The callback method for when a json message has failed to be acknowledged.
*
* @param client The client that received the message
* @param text The message it received
* @param json The message it received
*/
def onJsonAckFailed(client: HookupClient, json: String): Unit = ()
}
Expand All @@ -774,19 +774,19 @@ trait JavaHelpers extends WebSocketListener { self: HookupClient =>

/**
* Send a json message.
*
* @param message The message to send.
json
* @param json The message to send.
* @return A [[scala.concurrent.Future]] with the [[io.backchat.hookup.OperationResult]]
*/
def send(json: JValue): Future[OperationResult] = channel.send(json)

/**
* Send a json message. If the message isn't a json string it will throw a [[net.liftweb.json.JsonParser.ParseException]]
* Send a json message. If the message isn't a json string it will throw a [[org.json4s.ParserUtil.ParseException]]
*
* @param message The message to send.
* @param json The message to send.
* @return A [[scala.concurrent.Future]] with the [[io.backchat.hookup.OperationResult]]
*/
def sendJson(json: String): Future[OperationResult] = channel.send(JsonParser.parse(json))
def sendJson(json: String): Future[OperationResult] = channel.send(parse(json))

/**
* Send a text message which expects an Ack. If the message is a json string it will still be turned into a json message
Expand All @@ -801,7 +801,7 @@ trait JavaHelpers extends WebSocketListener { self: HookupClient =>
}
// channel.send(message.needsAck(timeout))
/**
* Send a json message which expects an Ack. If the message isn't a json string it will throw a [[net.liftweb.json.JsonParser.ParseException]]
* Send a json message which expects an Ack. If the message isn't a json string it will throw a [[org.json4s.ParserUtil.ParseException]]
*
* @param message The message to send.
* @param timeout the [[scala.concurrent.duration.Duration]] as timeout for the ack operation
Expand All @@ -812,7 +812,7 @@ trait JavaHelpers extends WebSocketListener { self: HookupClient =>
/**
* Send a text message which expects an Ack. If the message is a json string it will still be turned into a json message
*
* @param message The message to send.
* @param json The message to send.
* @param timeout the [[scala.concurrent.duration.Duration]] as timeout for the ack operation
* @return A [[scala.concurrent.Future]] with the [[io.backchat.hookup.OperationResult]]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.backchat.hookup
package examples

import java.net.URI
import net.liftweb.json.{ DefaultFormats, Formats }
import org.json4s.{ DefaultFormats, Formats }
import akka.actor.ActorSystem
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicInteger
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/io/backchat/hookup/examples/ChatServer.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.backchat.hookup
package examples

import net.liftweb.json._
import org.json4s._
import org.json4s.jackson.JsonMethods._

object ChatServer {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.backchat.hookup
package examples

import net.liftweb.json._
import org.json4s._
import java.util.concurrent.atomic.AtomicInteger
import java.net.URI
import scala.concurrent.duration._
import akka.actor.{ Cancellable, ActorSystem }
import JsonDSL._
import java.io.File
import org.json4s.jackson.JsonMethods._

object PrintAllEventsClient {
import DefaultConversions._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.backchat.hookup
package examples

import net.liftweb.json._
import org.json4s._
import org.json4s.jackson.JsonMethods._

object PrintAllEventsServer {
import DefaultConversions._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.backchat.hookup
package examples

import java.net.URI
import net.liftweb.json.{ DefaultFormats, Formats }
import org.json4s.{ DefaultFormats, Formats }
import akka.actor.ActorSystem
import scala.concurrent.duration._
import java.util.concurrent.atomic.AtomicInteger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.backchat.hookup
package examples

import net.liftweb.json._
import org.json4s._

object PrintingEchoServer {
import DefaultConversions._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package examples

import java.net.URI
import scala.concurrent.duration._
import net.liftweb.json._
import org.json4s._
import JsonDSL._
import org.json4s.jackson.JsonMethods._
import java.util.concurrent.atomic.AtomicInteger
import akka.actor.ActorSystem

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.backchat.hookup
package examples


import net.liftweb.json._
import org.json4s._
import java.util.concurrent.{ConcurrentSkipListSet, ConcurrentHashMap}
import collection.JavaConverters._

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/io/backchat/hookup/messages.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.backchat.hookup

import scala.concurrent.duration._
import net.liftweb.json.JsonAST.JValue
import org.json4s._
import scala.concurrent.duration.Duration

/**
Expand Down Expand Up @@ -58,7 +58,7 @@ case object Reconnecting extends InboundMessage
/**
* A message representing a json object sent to/received from a remote party.
*
* @param content A [[net.liftweb.json.JValue]] object
* @param content A [[org.json4s.JValue]] object
*/
case class JsonMessage(content: JValue) extends ProtocolMessage[JValue]

Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/backchat/hookup/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package io.backchat

import scala.concurrent.{ ExecutionContext, Promise, Future }
import org.jboss.netty.channel.{ Channel, ChannelFutureListener, ChannelFuture }
import net.liftweb.json.JsonAST.JValue
import org.json4s._
import scala.concurrent.duration.Duration
import java.util.concurrent.TimeUnit
import org.jboss.netty.logging.{Slf4JLoggerFactory, InternalLoggerFactory}
import net.liftweb.json.DefaultFormats
import beans.BeanProperty
import org.joda.time.DateTimeZone
import org.joda.time.format.DateTimeFormat
Expand Down Expand Up @@ -99,7 +98,7 @@ package object hookup {
}

/**
* Implicit conversion from a lift-json jvalue to a [[io.backchat.hookup.JsonMessage]]
* Implicit conversion from a json4s jvalue to a [[io.backchat.hookup.JsonMessage]]
*
* @param content The string content of the message
* @return A [[io.backchat.hookup.JsonMessage]]
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/io/backchat/hookup/server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import java.net.{ SocketAddress, InetSocketAddress }
import scala.collection.JavaConverters._
import collection.mutable.ListBuffer
import org.jboss.netty.handler.timeout.IdleStateHandler
import net.liftweb.json._
import org.json4s._
import JsonDSL._
import org.json4s.jackson.JsonMethods._
import java.util.concurrent.{ ConcurrentHashMap, ConcurrentLinkedQueue, TimeUnit, Executors }
import akka.util.Timeout
import org.jboss.netty.buffer.ChannelBuffers
Expand Down Expand Up @@ -703,7 +704,7 @@ object HookupServer {
while (expectedAcks.put(id, exp) != null) { // spin until we've updated

}
ctx.getChannel.write(new TextWebSocketFrame(compact(render(msg))))
ctx.getChannel.write(new TextWebSocketFrame(compact(msg)))
id
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/io/backchat/hookup/wire_formats.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.backchat.hookup

import net.liftweb.json._
import org.json4s._
import jackson.JsonMethods._
import scala.concurrent.duration._

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ trait WireFormat {
* It looks at the first character in the message and if it thinks it's JSON it will try to parse it as JSON
* otherwise it creates a text message
*
* @param formats the [[net.liftweb.json.Formats]] for lift-json
* @param formats the [[org.json4s.Formats]] for json4s
*/
class SimpleJsonWireFormat(implicit formats: Formats) extends WireFormat {

Expand All @@ -71,7 +72,7 @@ class SimpleJsonWireFormat(implicit formats: Formats) extends WireFormat {

def render(message: OutboundMessage) = message match {
case TextMessage(text) => text
case JsonMessage(json) => compact(JsonAST.render(json))
case JsonMessage(json) => compact(json)
case _ => ""
}
}
Expand Down Expand Up @@ -188,7 +189,7 @@ object JsonProtocolWireFormat {
* This wireformat knows about acking and the related protocol messages.
* it uses a json object to transfer meaning everything has a property name.
*
* @param formats the [[net.liftweb.json.Formats]] for lift-json
* @param formats the [[org.json4s.Formats]] for json4s
*/
class JsonProtocolWireFormat(implicit formats: Formats) extends WireFormat {
val name = "jsonProtocol"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.specs2.Specification
import org.specs2.time.NoTimeConversions
import scala.concurrent.duration._
import akka.testkit._
import net.liftweb.json.{Formats, DefaultFormats}
import org.json4s.{Formats, DefaultFormats}
import akka.util.Timeout
import java.net.{InetSocketAddress, SocketAddress, ServerSocket, Socket}
import java.io.{BufferedReader, PrintWriter, InputStreamReader}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.specs2.time.NoTimeConversions
import org.specs2.Specification
import java.io.File
import org.apache.commons.io.{FilenameUtils, FileUtils}
import net.liftweb.json.DefaultFormats
import org.json4s._
import scala.io.Source
import collection.JavaConverters._
import org.specs2.specification.{Fragments, Step}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package tests

import org.specs2.Specification
import org.specs2.time.NoTimeConversions
import net.liftweb.json.DefaultFormats
import org.json4s._
import org.specs2.execute.Result
import org.specs2.execute.AsResult
import java.net.{ServerSocket, URI}
import akka.testkit._
import akka.actor.ActorSystem
import net.liftweb.json.JsonAST.{JField, JString, JObject}
import scala.concurrent.duration._
import org.specs2.specification.{Around, Step, Fragments}
import scala.concurrent.{ExecutionContext, Await}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.specs2.time.NoTimeConversions
import org.specs2.execute.Result
import java.net.{URI, ServerSocket}
import akka.util.Timeout
import net.liftweb.json._
import org.json4s._
import JsonDSL._
import java.io.File
import akka.testkit._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.backchat.hookup
package tests

import org.specs2.Specification
import net.liftweb.json._
import org.json4s._
import JsonDSL._
import scala.concurrent.duration._
import org.specs2.time.NoTimeConversions
Expand Down

0 comments on commit d60e355

Please sign in to comment.