Loading ...
Sorry, an error occurred while loading the content.

Streaming responses and automatic case class serialisation

Expand Messages
  • Noel Welsh
    Hi all, I did a session on BlueEyes at last weeks ScalaLOL conference in London. I had two questions I didn t have a good answer to: 1. Does BlueEyes support
    Message 1 of 3 , Oct 17, 2011
    • 0 Attachment
      Hi all,

      I did a session on BlueEyes at last weeks' ScalaLOL conference in
      London. I had two questions I didn't have a good answer to:

      1. Does BlueEyes support streaming requests and responses (think
      comet/socket.io). I'm fairly sure it doesn't and I'm more interested
      in how one would go about adding it. Requests are read lazily, so that
      shouldn't be a problem. What about responses?

      2. Lift-json supports automatic serialisation of case classes. I don't
      think BlueEye's implementation does, or did I overlook something?

      Thanks,
      N.
    • mlagutko
      Hi, Noel. BlueEyes supports both streaming requests and responses. If you like to use a file as source for a streaming response then you can use
      Message 2 of 3 , Oct 17, 2011
      • 0 Attachment
        Hi, Noel.

        BlueEyes supports both streaming requests and responses.

        If you like to use a file as source for a streaming response then you can use blueeyes.core.data.FileSource like

        path("/file/read"){
        compress{
        produce(image / jpeg){
        get { request: HttpRequest[ByteChunk] =>
        val response = HttpResponse[ByteChunk](status = HttpStatus(HttpStatusCodes.OK), content = FileSource(new File("/Users/mlagutko/Downloads/victoria-parkside-resort.jpg")), headers = HttpHeaders.Empty + ("Content-Encoding", "gzip"))
        Future.sync[HttpResponse[ByteChunk]](response)
        }
        }
        }
        }

        If you like to use another streaming source then you can use FileSource implementation as an example.


        If you like to store a streaming request to a file you can use blueeyes.core.data.FileSink like

        path("/file/read"){
        post { request: HttpRequest[ByteChunk] =>
        val response = HttpResponse[ByteChunk](status = HttpStatus(HttpStatusCodes.OK))
        request.content.map(content => FileSink("foo", content).map(v => response)).getOrElse(Future.sync(response))
        }
        }

        If you like to handle a streaming request by another way then you can use FileSink as an example.

        Hope the answer will help you.

        Bye, Misha.


        --- In blueeyes-web@yahoogroups.com, Noel Welsh <noelwelsh@...> wrote:
        >
        > Hi all,
        >
        > I did a session on BlueEyes at last weeks' ScalaLOL conference in
        > London. I had two questions I didn't have a good answer to:
        >
        > 1. Does BlueEyes support streaming requests and responses (think
        > comet/socket.io). I'm fairly sure it doesn't and I'm more interested
        > in how one would go about adding it. Requests are read lazily, so that
        > shouldn't be a problem. What about responses?
        >
        > 2. Lift-json supports automatic serialisation of case classes. I don't
        > think BlueEye's implementation does, or did I overlook something?
        >
        > Thanks,
        > N.
        >
      • John A. De Goes
        Hi Noel, Thanks for introducing London to BlueEyes! :-) Misha answered the first question. As for the second, BlueEyes used to support case class serialization
        Message 3 of 3 , Oct 17, 2011
        • 0 Attachment

          Hi Noel,

          Thanks for introducing London to BlueEyes! :-)

          Misha answered the first question. As for the second, BlueEyes used to support case class serialization based on Lift Json. However, the feature is extremely brittle and painful to use in production, so we removed the functionality entirely.

          We have begun development of an alternative, which can be used not just for Json serialization, but for any other storage format. It's type-safe, supports versioning, and allows you to manually validate data on entry.

          It requires more work than case class serialization, but not much more:

          case class Person(name: String, age: Int, persons: List[Person]) extends Record3[String, Int, List[Person]] {
            def companion = Person
          }

          object Person extends Record3Companion[RecordNothing.type, Person, String, Int, List[Person]]{
            val _1, name = Field[Person, String]("name", _.name, (person, name) => person.copy(name = name), Failure("No name specified!"))

            val _2, age = Field[Person, Int]("age", _.age, (person, age) => person.copy(age = age), -1)

            val _3, persons  = Field[Person, List[Person]]("persons", _.persons, (person, persons) => person.copy(persons = persons), Failure("No name specified!"))

            def _example: Person = Person("John Doe", 123, Nil)
          }

          Given something similar to the above, you get automatic serialization / deserialization (for any format, not just Json), type-safe versioning (with automatic upgrades/downgrades), validation, and documentation.

          This approach will also allow you to produce patches quite easily, e.g.:

          val patch = (Person.name := "John Doe") |+| (Person.age += 2)

          Patches can be quite useful for performing atomic modifications in databases which support them.
          -- 
          John A. De Goes
          Chief Technology Officer
          303-921-5784 - @jdegoes

          ReportGrid, Inc - http://reportgrid.com

          On Oct 17, 2011, at 4:32 AM, Noel Welsh wrote:

           

          Hi all,

          I did a session on BlueEyes at last weeks' ScalaLOL conference in
          London. I had two questions I didn't have a good answer to:

          1. Does BlueEyes support streaming requests and responses (think
          comet/socket.io). I'm fairly sure it doesn't and I'm more interested
          in how one would go about adding it. Requests are read lazily, so that
          shouldn't be a problem. What about responses?

          2. Lift-json supports automatic serialisation of case classes. I don't
          think BlueEye's implementation does, or did I overlook something?

          Thanks,
          N.


        Your message has been successfully submitted and would be delivered to recipients shortly.