Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Server extend Action<ServerTransport> #68

Closed
flowersinthesand opened this issue Jan 6, 2015 · 3 comments
Closed

Make Server extend Action<ServerTransport> #68

flowersinthesand opened this issue Jan 6, 2015 · 3 comments
Milestone

Comments

@flowersinthesand
Copy link
Contributor

// Server's input: ServerHttpExchange, ServerWebSocket
// Server's output: Socket (Transport is by-product)

// 1
// To consume user-defined transport, it will be processed into socket
// similar to server.httpAction()
server.transportAction().on(netServerTransport);

// 2
// When transport is opened 
// similar to server.socketAction(Action<Socket> action)
server.transportAction((ServerTransport transport) -> System.out.println(transport));

In fact, 1 can replace server.httpAction and server.wsAction then 2 is not needed. See the following snippet:

// HttpServerTransportForge's input: ServerHttpExchange
// WebSocketServerTransportForge's input: ServerWebSocket
// Server's input: Transport
// Server's output: Socket

// HttpServerTransportForge consumes ServerHttpExchange and produces transport
Action<ServerHttpExchange> forge = new HttpServerTransportForge();
// To consume ServerHttpExchange
// similar to server.httpAction
forge.on(http);
// When transport is opened
// similar to server.socketAction
forge.transportAction(server.transportAction());

// WebSocketServerTransportForge consumes ServerWebSocket and produces transport
Action<ServerWebSocket> forge = new WebSocketServerTransportForge();
// To consume ServerWebSocket
// similar to server.wsAction
forge.on(ws);
// When transport is opened
// similar to server.socketAction
forge.transportAction((Transport transport) -> {
  // Intercepts transport to do something
  System.out.println(transport);
  server.transportAction().on(transport);
});

Although the second one shows what input and output of each component are more clearly than the first one, since user doesn't need to know about Transport, it would be better to provide httpAction and wsAction (so to hide transport) as is for convenience. But I'm not sure. Anyway, internally it already works like the second one.

@flowersinthesand
Copy link
Contributor Author

If server implementation is provided per layer, it would solve the above problem. That is, AServer which consumes ServerTransport and BServer extending AServer which consumes ServerHttpExchange and ServerWebSocket and internally creates and consumes ServerTransport. If user uses customized transport instead of provided ones, AServer is more simple though BServer does work. If user uses provided transports only and doesn't care what transport is, BServer is more convenient which corresponds to the current DefaultServer.

However, since ClusteredServer extends DefaultServer, more work is required to cluster AServer. But I think ClusteredServer should be rewritten e.g. not extending Server. It may decorates Server or need new interface to intercept method calls.

Discussion

  • What name would you suggest as AServer and BServer?
  • Which way is easy to achieve requirements to cluster without extending Server? Or is it better to extend it?

This issue will focus on the first question.

@flowersinthesand
Copy link
Contributor Author

On second thought after reviewing ClusteredServer, it's right that ClusteredServer should be Server and BServer is not necessary. Accordingly Aserver should be DefaultServer and the following should change:

  • Make Server extend Action<ServerTransport>
    • Server consumes ServerTransport and produces ServerSocket
    • Vibe protocol is configured only though Server
  • Create TransportServer extending Action<ServerHttpExchange or ServerWebSocket>
    • TransportServer consumes platform resource such as ServerHttpExchange or ServerWebSocket and produces ServerTransport
    • Vibe transport protocol is configured only though TransportServer
  • Make transport implementations private
    • Since they are accessible through TransportServer

Then, a bootstrap code will look like:

// consumes transport and produces socket
Server server = new DefaultServer();
server.socketAction(socket -> {});

// consumes http and produces transport
HttpTransportServer httpTransportServer = new HttpTransportServer();
httpTransportServer.transportAction(server);
// consumes ws and produces transport
WebSocketTransportServer wsTransportServer = new WebSocketTransportServer();
wsTransportServer.transportAction(server);

// How to integrate with user-defined transport
server.on((NetServerTransport) transport);

// Atmosphere 2
ServletContext context = event.getServletContext();
ServletRegistration.Dynamic reg = context.addServlet(VibeAtmosphereServlet.class.getName(), new VibeAtmosphereServlet() {
    @Override
    protected Action<ServerHttpExchange> httpAction() {
        return httpTransportServer;
    }

    @Override
    protected Action<ServerWebSocket> wsAction() {
        return wsTransportServer;
    }
});
reg.setAsyncSupported(true);
reg.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.TRUE.toString());
reg.addMapping("/vibe");

@flowersinthesand
Copy link
Contributor Author

Some tasks are moved to #71

@flowersinthesand flowersinthesand changed the title Provide transportAction Make Server extend Action<ServerTransport> Jan 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant