package io.scalecube.gateway.websocket;

import io.scalecube.services.Microservices;
import io.scalecube.services.ServiceCall;
import io.scalecube.services.api.ServiceMessage;
import io.scalecube.services.codec.ServiceMessageDataCodec;
import io.scalecube.services.exceptions.ExceptionProcessor;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.time.Duration;

public class RemoteWebSocketServerEchoRunner {

  public static final Logger LOGGER = LoggerFactory.getLogger(RemoteWebSocketServerEchoRunner.class);

  /**
   * Run test runner of Websocket server.
   * @param args - program arguments if any.
   * @throws InterruptedException - in case the program was interrupted.
   */
  public static void main(String[] args) throws InterruptedException {

    GreetingService serviceInstance = new GreetingServiceImpl();

    Microservices gateway = Microservices.builder()
        .build().startAwait();

    
    Microservices services = Microservices.builder()
        .seeds(gateway.cluster().address())
        .services(serviceInstance).build().startAwait();

    ServiceCall.Call call = gateway.call();
    LOGGER.info("Started services at address: {}", services.serviceAddress());

    ServiceMessageDataCodec dataCodec = new ServiceMessageDataCodec();

    WebSocketAcceptor acceptor = new WebSocketAcceptor() {

      @Override
      public Mono<Void> onConnect(WebSocketSession session) {
        return session.send(
            call.invoke(session.receive()
                .log("recv"))
            .log("send")
            .map(dataCodec::encode)).then();
      }

      @Override
      public Mono<Void> onDisconnect(WebSocketSession session) {
        return Mono.never();
      }
    };

    WebSocketServer server = new WebSocketServer(acceptor);
    server.start(new InetSocketAddress(8080));
    Thread.currentThread().join();
  }

}

@@ -883,74 +883,8 @@
  %7B%0A%0A
-    GreetingService serviceInstance = new GreetingServiceImpl();%0A%0A
     
@@ -966,42 +966,15 @@
 ();%0A
-%0A 
    %0A   
- Microservices services =
  Mic
@@ -1060,23 +1060,33 @@
 ces(
-serviceInstance
+new GreetingServiceImpl()
 ).bu
@@ -1121,707 +1121,87 @@
 vice
-Call.Call call = gateway.call();%0A    LOGGER.info(%22Started services at address: %7B%7D%22, services.serviceAddress());%0A%0A    ServiceMessageDataCodec dataCodec = new ServiceMessageDataCodec();%0A%0A    WebSocketAcceptor acceptor = new WebSocketAcceptor() %7B%0A%0A      @Override%0A      public Mono%3CVoid%3E onConnect(WebSocketSession session) %7B%0A        return session.send(%0A            call.invoke(session.receive()%0A                .log(%22recv%22))%0A            .log(%22send%22)%0A            .map(dataCodec::encode)).then();%0A      %7D%0A%0A      @Override%0A      public Mono%3CVoid%3E onDisconnect(WebSocketSession session) %7B%0A        return Mono.never();%0A      %7D%0A    %7D;%0A%0A    WebSocketServer server = new WebSocketServer(acceptor);%0A    server
+Gateway%0A      .builder(gateway.call()).ws().build()%0A      // on instance%0A      
 .sta
@@ -1233,16 +1233,21 @@
 8080));%0A
+    %0A
     Thre

improve example