Search code examples
grizzlyserver-push

can grizzly do a server-push, while connection is maintained to a client?


I am developing an agent that connects a client to a platform (server). the agent is based on grizzly-framework. My agent gets a request from my client to register him to platform. So my agent will perform this operation. Then my Agent will wait for operations coming from platform and will notify the client of these operations. So the connection between my agent and the client will be maintained. If a new operation comes from the platform, I will make a server-push to the client, since my client stays connected to me. I do not want that the client sends requests for new operations coming from platform ( polling). I want that my agent pushes the operation (POST-request) to my client. I know that this server-push is different from client-server-model but I have heard that it is possible using grizzly.

till now, I did find something helpful for the implementation of this idea in Java . This link https://grizzly.java.net/spdy.html from grizzly describes a server-push but this server-push is not applicable for my case, since push-server is executed, when a http-request comes from client.

Is it possible to implement this idea using grizzly?

if yes, how to do it?

Edit1: I noticed another problem when using http-server of grizzly-framework. My agent consists in my case of two sides: server-side which get requests from client and client-side, which connects to platform. My Agent will get a request from a client. The grizzly-based-agent will launch a http-handler (my client-side-agent) which analyses this request. After analysing the request, this handler will connect to platform. After finishing the operation, he will send to the client http/1.1 200 OK. If the same client decided to send me a new operation on the plaform, I should start a new connection to platform, which means for me to instantiate a new client-side-agent (http-handler) for the same client. I mean that I do not have access to the old instance (old client-side-agent) and I am obliged to make a new instance, which implies a lot of traffic that I need to avoid it. In thisSituation, if a handler executes its non blocking operation, then this handler is lost, so that I cannot access him, which implies that I cannot get operations from platform and make a server-push. If I suspend the handler for period of time, all the coming requests from other clients will be blocked, so the clients cannot be serviced.


Solution

  • IMO SPDY or HTTP/2 doesn't fit well into what you need, because as you fairly noted the push they send must be always associated with the initial client-to-server request. I'd suggest to take a look at WebSocket [1], [2].

    [1] https://grizzly.java.net/websockets.html [2] https://tyrus.java.net/