[reposting linkified version: i hate google-groups]

Hi,
Sorry for the late reply: apparently google decided that I'm not worthy of 
receiving notifications and I've noticed your message just now by chance.
(I've even checked if maybe gmail decided that messages from google are 
spam and verified that I'm subscribed to this thread, yet no notification 
email anywhere...)

there were 2 main points that motivated me:
- to have functionality similar to servlet's REQUEST_SCOPE and 
SESSION_SCOPE available when developing websockets and gRPC services, so 
that I could scope objects related to given websocket/gRPC message properly 
(or to a whole websocket connection / gRPC stream).
- make it easy (ie: automate as much as possible) to keep scopes when 
switching threads, which is very convenient when using asynchronous 
approach in server design.

You can have a look at samples mentioned in the README of each repo. In 
both cases there's an example showing how to scope EntityManager to a given 
message, so that all component performing JPA operations within processing 
of the same message, will automatically do their stuff within the same 
common transaction. Here are the links to the "core" files of each example:
websocket: 
https://github.com/morgwai/guiced-servlet-jpa/blob/master/sample/src/main/java/pl/morgwai/samples/guiced_servlet_jpa/servlets/ChatEndpoint.java
gRPC: 
https://github.com/morgwai/grpc-scopes/blob/master/sample/src/main/java/pl/morgwai/samples/grpc/scopes/grpc/RecordStorageService.java

Using this opportunity to share some news, I've recently added jakarta 
name-space support to websocket scopes: jar is now available with 2 
classifiers: servlet-scopes-5.0-javax and 
servlet-scopes-5.0-jakarta-experimental.
Jakarta flavor is based on repackaged version of Guice from GuicedEE 
project: https://guicedee.com/ . There are some small issues with it (see 
notes: https://github.com/morgwai/servlet-scopes#notes-on-jakarta-support 
), but seems to work ok so far.

Cheers!


On Monday, October 4, 2021 at 4:43:17 PM UTC+7 padhy.d...@gmail.com wrote:

> Interesting :) . Would you please elaborate a sample use case that was 
> your motivation? 
>
> Debasish
> On Saturday, April 17, 2021 at 3:21:22 PM UTC+5:30 mor...@gmail.com wrote:
>
>> Hello all,
>> Recently I've finally found some time to polish and generalize a set of 
>> classes providing Guice scopes for gRPC and websockets, that I was 
>> copy-pasting-tweaking for every java project for last few years: maybe 
>> someone else will find it useful :)
>>
>> https://github.com/morgwai/grpc-scopes
>> Provides `rpcScope` and `listenerCallScope`. Oversimplifying, in case of 
>> a streaming client, `listenerCallScope` spans over processing of a single 
>> message from client's stream, while `rpcScope` spans over a whole given 
>> RPC. Oversimplifying again, in case of a unary client, these 2 scopes have 
>> roughly the same span.
>>
>> https://github.com/morgwai/servlet-scopes
>> Provides
>> `requestScope` spans over HTTP servlet requests and websocket events, 
>> such as connection open/closed or message received (ie, over each of 
>> endpoints' annotated methods or overriding those of Endpoint)
>> `websocketConnectionScope` spans over a whole endpoint connection 
>> (javax.websocket.Session)
>> `httpSessionScope` available both to servlets and websocket endpoints
>>
>> both libs are built on top of 
>> https://github.com/morgwai/guice-context-scopes which automates 
>> transferring scopes when dispatching work to new threads (useful for async 
>> processing).
>>
>> answering in advance why websocket scopes are not built on top of the 
>> official servlet scopes:
>> - this implementation is thread-safe: a single request can be handled by 
>> multiple threads (as long as accessed scoped objects are thread-safe)
>> - guice-context-scopes lib was first developed for gRPC scopes. After 
>> that, it felt more natural to use it also for websocket scopes, rather than 
>> pretend that everything is an HttpServletRequest. I may be biased here 
>> however ;-)
>>
>>
>> Feedback is welcome :)
>>
>> Cheers!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/d7fb73da-72a9-445b-a533-f10c724150f9n%40googlegroups.com.

Reply via email to