Examples of HPIServerProtocol


Examples of org.hpi.dialogue.protocol.service.HPIServerProtocol

    this.socket = socket;
  }
 
  @Override
  public void run() {
    HPIServerProtocol serverProtocol = null;
    try {
      serverProtocol = new HPIServerProtocol(this.socket);
      Request clientRequest = serverProtocol.readRequest();
      Response response = null;

      // deciding the correct request
      if (clientRequest instanceof LoginRequest) { // login request
        response = this.doLogin((LoginRequest) clientRequest);
      } else if (clientRequest instanceof ListInvokersRequest) { // list invokers request
        response = this.retrieveListInvokers((ListInvokersRequest) clientRequest);
      } else if (clientRequest instanceof DescribeInvokerRequest) { // describe invoker request
        response = this.describeInvoker((DescribeInvokerRequest) clientRequest);
      } else if (clientRequest instanceof ExecuteInvokerRequest) { // execute invoker request
        response = this.executeInvoker((ExecuteInvokerRequest) clientRequest);
      } else if (clientRequest instanceof LogoffRequest) { // logoff request
        response = this.doLogoff((LogoffRequest) clientRequest);
      } else if (clientRequest instanceof ServerShutdownRequest) { // shutdown request
        new Thread() {
          @Override
          public void run() {
            try {
              Thread.sleep(ServerBridge.TIME_CHECK_SHUTDOWN);
              ServerBridge.SHUTDOWN = true;
            } catch (InterruptedException e) {
              throw new RuntimeException(e);
            }
          }
        }.start();
        response = new ServerShutdownResponse("Request to shutdown server received successfully and schedulled to execute in 5 seconds.", Response.Status.SUCCESS);
      } else throw new IllegalStateException("Request type unknown.");
     
      // writing the serialized response
      serverProtocol.writeResponse(response);
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      if (serverProtocol != null) {
        serverProtocol.closeSocket();
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.