fdimuccio / play2-sockjs

A SockJS server implementation for Play Framework.
Apache License 2.0
62 stars 11 forks source link

Support Java 8 Lambda Expression syntax #4

Closed arielscarpinelli closed 10 years ago

arielscarpinelli commented 10 years ago

With this change you can use this slick syntax:

public static SockJSRouter hello = SockJSRouter.whenReady((in, out) -> {

    // Log each event received on the socket to the console
    in.onMessage(System.out::println);

    // When SockJS connection is closed.
    in.onClose(() -> System.out.println("Disconnected"));

    // Send a single 'Hello!' message
    out.write("Hello!");

});
fdimuccio commented 10 years ago

Nice, thank you

fdimuccio commented 10 years ago

Now it's possible to configure the router with the new Java API. New jars have been released, more in README.

arielscarpinelli commented 10 years ago

Cool.

I was working on implementing something similar myself yesterday, but felt lazy to implement the Builder that implemented SockJS.Settings :-p

Now I'm working on updating to play 2.3, but I don't want to overlap with you. I saw that you added "0.3 coming soon"; are you working on that right now?

2014-06-16 19:35 GMT-03:00 Francesco Di Muccio notifications@github.com:

Now it's possible to configure the router with the new Java API. New jars have been released, more in README.

Reply to this email directly or view it on GitHub https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46246863.

fdimuccio commented 10 years ago

2014-06-17 0:59 GMT+02:00 Ariel Scarpinelli notifications@github.com:

Cool.

I was working on implementing something similar myself yesterday, but felt lazy to implement the Builder that implemented SockJS.Settings :-p

Now I'm working on updating to play 2.3, but I don't want to overlap with you. I saw that you added "0.3 coming soon"; are you working on that right now?

Yes, and the new version could break actual scala api. In Play 2.3 they added more ways to handle WebSocket (see tryAccept and actors api) and switched to two different types to handle input and output messages. My intention is to offer the same api also in play2-sockjs.

2014-06-16 19:35 GMT-03:00 Francesco Di Muccio notifications@github.com:

Now it's possible to configure the router with the new Java API. New jars have been released, more in README.

Reply to this email directly or view it on GitHub <https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46246863 .

— Reply to this email directly or view it on GitHub https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46248688.

arielscarpinelli commented 10 years ago

I've just got it working with 2.3 using the same websocket interfaces that 2.2 had. Definitely much less work than providing a new api :-p. I can send you a pull request if you would like to although I don't think you would need it. Anyhow the commit is pushed on my fork.

With the new eventsource interface change on Play 2.3, the sockjs protocl tests break because they assume that end of line must be \r\n however play is sending just \n. I've checked with the eventsource spec ( http://www.w3.org/TR/eventsource/#parsing-an-event-stream) and this is valid, so I will send a pull request to sockjs-protocol.

Let me know if there is anything I can help you with.

Best!

2014-06-17 6:09 GMT-03:00 Francesco Di Muccio notifications@github.com:

2014-06-17 0:59 GMT+02:00 Ariel Scarpinelli notifications@github.com:

Cool.

I was working on implementing something similar myself yesterday, but felt lazy to implement the Builder that implemented SockJS.Settings :-p

Now I'm working on updating to play 2.3, but I don't want to overlap with you. I saw that you added "0.3 coming soon"; are you working on that right now?

Yes, and the new version could break actual scala api. In Play 2.3 they added more ways to handle WebSocket (see tryAccept and actors api) and switched to two different types to handle input and output messages. My intention is to offer the same api also in play2-sockjs.

2014-06-16 19:35 GMT-03:00 Francesco Di Muccio notifications@github.com:

Now it's possible to configure the router with the new Java API. New jars have been released, more in README.

Reply to this email directly or view it on GitHub < https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46246863 .

Reply to this email directly or view it on GitHub https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46248688.

Reply to this email directly or view it on GitHub https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46283962.

fdimuccio commented 10 years ago

2014-06-17 14:36 GMT+02:00 Ariel Scarpinelli notifications@github.com:

I've just got it working with 2.3 using the same websocket interfaces that 2.2 had. Definitely much less work than providing a new api :-p. I can send you a pull request if you would like to although I don't think you would need it. Anyhow the commit is pushed on my fork.

I just pushed into master a 0.3.0-SNAPSHOT that fully support Play 2.3 scala side with new methods as SockJS.tryAccept. Actors api will come soon and then I will start working on Java api.

With the new eventsource interface change on Play 2.3, the sockjs protocl tests break because they assume that end of line must be \r\n however play is sending just \n. I've checked with the eventsource spec ( http://www.w3.org/TR/eventsource/#parsing-an-event-stream) and this is valid, so I will send a pull request to sockjs-protocol.

Thank you for the hint and for reporting that to sockjs-protocol authors. I saw that you used the EventSource interface in your branch, I preferred to stay compatible with sockjs-protocol-testd as much as possible, so I implemented a custom Enumeratee that prints \r\n instead of \n. When (and if) SockJS will be updated I will switch to the new EventSource interface :)

Let me know if there is anything I can help you with.

Well, apart few scaladocs missing, the Java api for 2.3 is completely broken, and the next thing I will work on will be actors api for scala. Any help on java side is really appreciated, what's missing is the right implementation of play.sockjs.core.j.JavaSockJS that is the java-to-scala bridge.

Best!

2014-06-17 6:09 GMT-03:00 Francesco Di Muccio notifications@github.com:

2014-06-17 0:59 GMT+02:00 Ariel Scarpinelli notifications@github.com:

Cool.

I was working on implementing something similar myself yesterday, but felt lazy to implement the Builder that implemented SockJS.Settings :-p

Now I'm working on updating to play 2.3, but I don't want to overlap with you. I saw that you added "0.3 coming soon"; are you working on that right now?

Yes, and the new version could break actual scala api. In Play 2.3 they added more ways to handle WebSocket (see tryAccept and actors api) and switched to two different types to handle input and output messages. My intention is to offer the same api also in play2-sockjs.

2014-06-16 19:35 GMT-03:00 Francesco Di Muccio < notifications@github.com>:

Now it's possible to configure the router with the new Java API. New jars have been released, more in README.

Reply to this email directly or view it on GitHub < https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46246863 .

Reply to this email directly or view it on GitHub < https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46248688>.

Reply to this email directly or view it on GitHub <https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46283962 .

— Reply to this email directly or view it on GitHub https://github.com/fdimuccio/play2-sockjs/pull/4#issuecomment-46300706.