Examples of SCClient


Examples of org.serviceconnector.api.cln.SCClient

    }

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

Examples of org.serviceconnector.api.cln.SCClient

  /** {@inheritDoc} */
  @Override
  public void run() {
    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCPublishService 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 = "publish-1";
      service = sc.newPublishService(serviceName); // name of the service to use

      DemoPublishClientCallback cbk = new DemoPublishClientCallback(service); // callback on service!!
      // set up subscribe message
      SCSubscribeMessage msg = new SCSubscribeMessage();
      String mask = "0000121ABCDEFGHIJKLMNO-----------X-----------";
      msg.setSessionInfo("subscription-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      msg.setMask(mask); // mandatory
      msg.setNoDataIntervalSeconds(100); // mandatory
      SCSubscribeMessage reply = service.subscribe(msg, cbk); // regular subscribe

      String sid = service.getSessionId();

      // wait to receive messages
      while (cbk.receivedMsg < 5) {
        Thread.sleep(1500);
      }
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCSubscribeMessage msg = new SCSubscribeMessage();
        msg.setSessionInfo("kill server");
        service.unsubscribe(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.info("cleanup " + e.toString());
      }
    }
  }
View Full Code Here

Examples of org.serviceconnector.api.cln.SCClient

  /**
   * Run example.
   */
  public static 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);
      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

Examples of org.serviceconnector.api.cln.SCClient

    }

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

Examples of org.serviceconnector.api.cln.SCClient

        List<String> networkInterfaces = myLocalListenerConfiguration.getNetworkInterfaces();
        for (String networkInterface : networkInterfaces) {
          String host = networkInterface;
          int port = myLocalListenerConfiguration.getPort();
          try {
            SCClient localClient = new SCClient(host, port, ConnectionType.NETTY_TCP);
            localClient.attach();
            return localClient;
          } catch (Exception e) {
            LOGGER.warn("upload current log files, connect to network interface " + host + " failed. " + e.toString());
          }
        }
      }
      responder = responderRegistry.getFirstResponderForConnectionType(ConnectionType.NETTY_HTTP);
      if (responder != null) {
        ListenerConfiguration myLocalListenerConfiguration = responder.getListenerConfig();
        List<String> networkInterfaces = myLocalListenerConfiguration.getNetworkInterfaces();
        // no netty tcp endpoint is available, try to get netty http
        for (String networkInterface : networkInterfaces) {
          String host = networkInterface;
          int port = myLocalListenerConfiguration.getPort();
          try {
            SCClient localClient = new SCClient(host, port, ConnectionType.NETTY_HTTP);
            localClient.attach();
            return localClient;
          } catch (Exception e) {
            LOGGER.warn("upload current log files, connect to network interface " + host + " and port " + port
                + " failed. " + e.toString());
          }
        }
      }
      return null;
    }
    if (service instanceof CascadedFileService) {
      CascadedFileService cascadedFileService = (CascadedFileService) service;
      CascadedSC cascadedSC = cascadedFileService.getCascadedSC();
      String host = cascadedSC.getHost();
      int port = cascadedSC.getPortNr();
      String connectionType = cascadedSC.getConnectionType();
      try {
        SCClient localClient = new SCClient(host, port, ConnectionType.getType(connectionType));
        localClient.attach();
        return localClient;
      } catch (Exception e) {
        LOGGER.warn("upload current log files, connect to network interface " + host + " and port " + port + " failed. "
            + e.toString());
      }
View Full Code Here

Examples of org.serviceconnector.api.cln.SCClient

    ServiceRegistry serviceRegistry = AppContext.getServiceRegistry();
    writer.writeStartElement("service");
    Service service = serviceRegistry.getService(serviceName);
    this.writeBean(writer, service);
    if (service instanceof FileService || service instanceof CascadedFileService) {
      SCClient client = null;
      // try to connect client
      client = connectClientToService(service);
      SCFileService scFileService = client.newFileService(serviceName);
      List<String> fileList = scFileService.listFiles();
      writer.writeStartElement("files");
      for (String fileName : fileList) {
        writer.writeStartElement("file");
        writer.writeCData(fileName);
        writer.writeEndElement();
      }
      writer.writeEndElement();
      if (client != null) {
        client.detach();
      }
    }
    writer.writeEndElement(); // close service tag
    // load current configuration directory
    String configFileName = SystemInfo.getConfigFileName();
View Full Code Here

Examples of org.serviceconnector.api.cln.SCClient

    ServiceRegistry serviceRegistry = AppContext.getServiceRegistry();
    writer.writeStartElement("service");
    Service service = serviceRegistry.getService(serviceName);
    this.writeBean(writer, service);
    if (service instanceof FileService || service instanceof CascadedFileService) {
      SCClient client = null;
      // try to connect client
      client = connectClientToService(service);
      SCFileService scFileService = client.newFileService(serviceName);
      List<String> fileList = scFileService.listFiles();
      writer.writeStartElement("files");
      for (String fileName : fileList) {
        if (fileName.startsWith(Constants.LOGS_FILE_NAME)) {
          writer.writeStartElement("file");
          writer.writeCData(fileName);
          writer.writeEndElement();
        }
      }
      writer.writeEndElement();
      if (client != null) {
        client.detach();
      }
    }
    writer.writeEndElement(); // close service tag
    // get logs xml loader from factory
    LogsXMLLoader logsXMLLoader = (LogsXMLLoader) XMLLoaderFactory.getXMLLoader("/logs");
View Full Code Here

Examples of org.serviceconnector.api.cln.SCClient

  }

  public void setUpClientToSC() throws Exception {
    if (cascadingLevel == 0) {
      mgmtClient = new SCMgmtClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
      guardianClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
      sessionClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
    } else if (cascadingLevel == 1) {
      mgmtClient = new SCMgmtClient(TestConstants.HOST, TestConstants.PORT_SC1_TCP, ConnectionType.NETTY_TCP);
      guardianClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC1_TCP, ConnectionType.NETTY_TCP);
      sessionClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC1_TCP, ConnectionType.NETTY_TCP);
    } else if (cascadingLevel == 2) {
      mgmtClient = new SCMgmtClient(TestConstants.HOST, TestConstants.PORT_SC2_TCP, ConnectionType.NETTY_TCP);
      guardianClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC2_TCP, ConnectionType.NETTY_TCP);
      sessionClient = new SCClient(TestConstants.HOST, TestConstants.PORT_SC2_TCP, ConnectionType.NETTY_TCP);
    }
    mgmtClient.attach();
    guardianClient.attach();
    sessionClient.attach();
    cacheGuardianCbk = new GuardianCbk();
View Full Code Here

Examples of org.serviceconnector.api.cln.SCClient

    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

Examples of org.serviceconnector.api.cln.SCClient

   */
  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
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.