Package org.serviceconnector.api.cln

Examples of org.serviceconnector.api.cln.SCClient


   * Run.
   */
  public void run() {

    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCSessionService service = null;

    try {
      sc.setMaxConnections(20); // can be set before attach, default 100 Connections
      sc.setKeepAliveIntervalSeconds(10); // can be set before attach, default 0 -> inactive
      sc.attach(); // attaching client to SC , communication starts

      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // name of the service to use
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      SCMessage reply = service.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        responseMsg = service.execute(requestMsg); // regular synchronous call
        LOGGER.info("Message sent sync=" + requestMsg.getData());
        LOGGER.info("Message received sync=" + responseMsg.getData());
        Thread.sleep(2000);
      }
      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        service.send(requestMsg); // regular asynchronous call
        LOGGER.info("Message sent async=" + requestMsg.getData());
        Thread.sleep(2000);
      }

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        service.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
  }
View Full Code Here


  /** {@inheritDoc} */
  @Override
  public void run() {
    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);

    try {
      sc.setMaxConnections(20); // can be set before attach, default 100 Connections
      sc.setKeepAliveIntervalSeconds(10); // can be set before attach, default 0 -> inactive
      sc.attach(); // attaching client to SC , communication starts

      SCFileService service = sc.newFileService("file-1"); // name of the service to use

      List<String> fileNameList = service.listFiles();
      for (String fileName : fileNameList) {
        System.out.println(fileName);
      }

      File localFile = new File("src/main/resources/uploadContent.txt");
      InputStream inpStream = new FileInputStream(localFile);
      String targetFileName = "uploadContent.txt";

      service.uploadFile(targetFileName, inpStream); // regular upload

      localFile = new File("src/main/resources/downloadContent.txt");
      FileOutputStream outStream = new FileOutputStream(localFile);
      targetFileName = "uploadContent.txt";
      service.downloadFile(targetFileName, outStream); // regular download
      outStream.close();
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        sc.detach(); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
  }
View Full Code Here

    String status = "successful (copied)";
    if (dstFile.exists()) {
      status = "successful (replaced)";
    }
    FileOutputStream dstStream = null;
    SCClient client = null;
    try {
      // try to connect client
      client = connectClientToService(service);
      SCFileService scFileService = client.newFileService(service.getName());
      dstStream = new FileOutputStream(dstFile);
      scFileService.downloadFile(remoteFile, dstStream);
      writer.writeStartElement("message");
      writer.writeCharacters(dstFile.getName() + "  " + status);
      writer.writeEndElement();
    } catch (Exception e) {
      status = "failed";
      writer.writeStartElement("message");
      writer.writeCharacters(dstFile.getName() + "  " + status);
      writer.writeEndElement();
      throw e;
    } finally {
      if (dstStream != null) {
        try {
          dstStream.close();
        } catch (Exception e) {
        }
      }
      if (client != null) {
        client.detach();
      }
    }
  }
View Full Code Here

   */
  private String uploadLogAndDumpFiles(Service service, String serviceName, Date date) throws Exception {
    if (!(service instanceof FileService || service instanceof CascadedFileService)) {
      throw new WebCommandException("upload current log and dump files, service is not a file or cascaded file service");
    }
    SCClient client = null;
    // try to connect client
    client = connectClientToService(service);
    // client gets destroyed at the end of upload inside the uploadLogFiles method
    // has to be inside because the upload works asynchronous
    if (client == null) {
View Full Code Here

   * Run.
   */
  public void run() {

    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCSessionService sessionSrv = null;

    try {
      sc.setMaxConnections(20); // can be set before attach, default 100 Connections
      sc.setKeepAliveIntervalSeconds(10); // can be set before attach, default 0 -> inactive
      sc.attach(); // attaching client to SC , communication starts

      String serviceName = "session-1";
      sessionSrv = sc.newSessionService(serviceName); // name of the service to use
      sessionSrv.setEchoIntervalSeconds(10); // can be set before create session
      sessionSrv.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(sessionSrv); // callback on service!!
      SCMessage reply = sessionSrv.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();   
     
      String sid = sessionSrv.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());     
     
      SCPublishService publishService = sc.newPublishService("cacheGuardian1"); // name of the service to use

      DemoPublishClientCallback pubCbk = new DemoPublishClientCallback(publishService); // callback on service!!
      // set up subscribe message
      SCSubscribeMessage subMsg = new SCSubscribeMessage();
      String mask = "0000121ABCDEFGHIJKLMNO-----------X-----------";
      subMsg.setSessionInfo("subscription-info"); // optional
      subMsg.setData("certificate or what so ever"); // optional
      subMsg.setMask(mask); // mandatory
      subMsg.setNoDataIntervalSeconds(100); // mandatory
      SCSubscribeMessage subReply = publishService.subscribe(subMsg, pubCbk); // regular subscribe
     
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());   
     
     
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        sessionSrv.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
  }
View Full Code Here

  /** {@inheritDoc} */
  @Override
  public void run() {

    SCClient sc = new SCClient("localhost", 7000); // regular, defaults documented in javadoc
    sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP); // alternative with connection type
    SCSessionService service = null;
    try {
      sc.setMaxConnections(20); // can be set before attach
      sc.setKeepAliveIntervalSeconds(0); // can be set before attach
      sc.attach(); // regular

      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // regular, no other params possible
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      service.createSession(10, msg, cbk); // alternative with operation timeout and message
      // service.createSession(msg); // alternative with message

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      requestMsg.setCacheId("CBCD_SECURITY_MARKET");
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 10; i++) {
        requestMsg.setData("body nr : " + i);
        LOGGER.info("Message sent=" + requestMsg.getData());

        // service.send(cbk, requestMsg); // regular asynchronous call
        // service.send(cbk, requestMsg, 10); // alternative with operation timeout
        // service.receive(cbk); // wait for response
        // cbk.receive(); // wait for response ?
        // responseMsg = cbk.getMessage(); // response message

        // synchronous call encapsulates asynchronous call!
        responseMsg = service.execute(requestMsg); // regular synchronous call
        // responseMsg = service.execute(requestMsg, 10); // alternative with operation timeout

        LOGGER.info("Message received=" + responseMsg.getData());
        Thread.sleep(1000);
      }
      requestMsg.setData("kill server");
      // service.send(cbk, requestMsg);

    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        service.deleteSession(); // regular
        // service.deleteSession(10); // alternative with operation timeout
        // SCMessage msg = new SCMessage();
        // msg.setSessionInfo("session-info"); // optional
        // service.deleteSession(10, msg); // alternative with operation timeout and message
        // service.deleteSession(msg); // alternative with message
        sc.detach();
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
  }
View Full Code Here

  /**
   * Run example.
   */
  public void runExample() {
    SCClient sc = null;
    try {
      sc = new SCClient("localhost", 7000);
      sc.setMaxConnections(100);

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      requestMsg.setData("Hello World");
      requestMsg.setCompressed(false);

      sessionServiceA.send(requestMsg);

      // wait until message received
      waitForMessage(10);
      // deletes the session
      sessionServiceA.deleteSession();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        // disconnects from SC
        sc.detach();
      } catch (Exception e) {
        sc = null;
      }
    }
  }
View Full Code Here

     * @param msg
     *            the msg {@inheritDoc}
     */
    @Override
    public void receive(SCMessage msg) {
      @SuppressWarnings("unused")
      SCClient client = this.getService().getSCClient();
      System.out.println(msg);
      SCAsyncSessionClientExample.messageReceived = true;
    }
View Full Code Here

  /**
   * Run example.
   */
  public static void runExample() {
    SCClient sc = null;
    try {
      sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
      sc.setMaxConnections(100);

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      // set up large buffer
      byte[] buffer = new byte[9000000];
      for (int i = 0; i < buffer.length; i++) {
        buffer[i] = (byte) i;
      }
      requestMsg.setData(buffer);
      requestMsg.setPartSize(65536); // 64KB
      requestMsg.setCompressed(false);
      System.out.println(buffer.length);
      SCMessage responseMsg = sessionServiceA.execute(requestMsg);
      System.out.println(responseMsg.getData().toString());
      // deletes the session
      sessionServiceA.deleteSession();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        // disconnects from SC
        sc.detach();
      } catch (Exception e) {
        sc = null;
      }
    }
  }
View Full Code Here

    }

    /** {@inheritDoc} */
    @Override
    public void receive(SCMessage msg) {
      @SuppressWarnings("unused")
      SCClient client = this.getService().getSCClient();
      System.out.println(msg);
    }
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.cln.SCClient

Copyright © 2018 www.massapicom. 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.