Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCServiceException


   * @throws SCServiceException
   *             called method after attach
   */
  public void setMaxConnections(int maxConnections) throws SCServiceException, SCMPValidatorException {
    if (this.attached == true) {
      throw new SCServiceException("Can not set property, client is already attached.");
    }
    // maxConnections must be at least 2 - echo call and execute/send might be parallel
    ValidatorUtility.validateInt(2, maxConnections, SCMPError.HV_WRONG_MAX_CONNECTIONS);
    this.maxConnections = maxConnections;
  }
View Full Code Here


   *             error message received from SC <br />
   */
  public synchronized void attach(int operationTimeoutSeconds) throws SCServiceException, SCMPValidatorException {
    // 1. checking preconditions and validate
    if (this.attached) {
      throw new SCServiceException("SCClient already attached.");
    }
    if (host == null) {
      throw new SCMPValidatorException("Host is missing.");
    }
    ValidatorUtility.validateInt(Constants.MIN_PORT_VALUE, this.port, Constants.MAX_PORT_VALUE, SCMPError.HV_WRONG_PORTNR);
    // 2. initialize call & invoke
    synchronized (AppContext.communicatorsLock) {
      AppContext.init();
      RemoteNodeConfiguration remoteNodeConf = new RemoteNodeConfiguration(this.port + "client", this.host, this.port,
          this.connectionType.getValue(), this.keepAliveIntervalSeconds, 0, this.maxConnections);
      this.requester = new SCRequester(remoteNodeConf, this.keepAliveTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      SCServiceCallback callback = new SCServiceCallback(true);
      SCMPAttachCall attachCall = new SCMPAttachCall(this.requester);
      try {
        attachCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        this.requester.destroy();
        // release resources
        AppContext.destroy();
        throw new SCServiceException("Attach to " + host + ":" + port + " failed. ", e);
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        this.requester.destroy();
        // release resources
        AppContext.destroy();
        SCServiceException ex = new SCServiceException("Attach to " + host + ":" + port + " failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
      // 4. post process, reply to client
      this.attached = true;
      AppContext.attachedCommunicators.incrementAndGet();
View Full Code Here

      SCServiceCallback callback = new SCServiceCallback(true);
      SCMPDetachCall detachCall = new SCMPDetachCall(this.requester);
      try {
        detachCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Detach client failed. ", e);
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException ex = new SCServiceException("Detach client failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    } finally {
      // 4. post process, reply to client
      this.attached = false;
View Full Code Here

   *             called method after attach
   * @return the file service
   */
  public SCFileService newFileService(String serviceName) throws SCServiceException, SCMPValidatorException {
    if (this.attached == false) {
      throw new SCServiceException("Creating a new file service not possible - client not attached.");
    }
    if (serviceName == null) {
      throw new SCMPValidatorException("Service name must be set.");
    }
    ValidatorUtility
View Full Code Here

   *             called method after attach
   * @return the session service
   */
  public SCSessionService newSessionService(String serviceName) throws SCServiceException, SCMPValidatorException {
    if (this.attached == false) {
      throw new SCServiceException("Creating a new session service not possible - client not attached.");
    }
    if (serviceName == null) {
      throw new SCMPValidatorException("Service name must be set.");
    }
    ValidatorUtility
View Full Code Here

   *             called method after attach
   * @return the publish service
   */
  public SCPublishService newPublishService(String serviceName) throws SCServiceException, SCMPValidatorException {
    if (this.attached == false) {
      throw new SCServiceException("Creating a new publish service not possible - client not attached.");
    }
    if (serviceName == null) {
      throw new SCMPValidatorException("Service name must be set.");
    }
    ValidatorUtility
View Full Code Here

   * @throws UnsupportedEncodingException
   *             the unsupported encoding exception
   */
  public String getSCVersion() throws SCServiceException, UnsupportedEncodingException {
    if (this.attached == false) {
      throw new SCServiceException("Client not attached - getStateOfServices not possible.");
    }
    String urlString = URLString.toURLRequestString(Constants.CC_CMD_SC_VERSION);
    String body = this.inspectCall(Constants.DEFAULT_OPERATION_TIMEOUT_SECONDS, urlString);
    URLString urlResponse = new URLString();
    urlResponse.parseResponseURLString(body);
View Full Code Here

   *             encoding of request URL failed<br />
   */
  public boolean isServiceEnabled(int operationTimeout, String serviceName) throws SCServiceException,
      UnsupportedEncodingException {
    if (this.attached == false) {
      throw new SCServiceException("Client not attached - isServiceEnabled not possible.");
    }
    String urlString = URLString.toURLRequestString(Constants.CC_CMD_STATE, Constants.SERVICE_NAME, serviceName);
    try {
      String body = this.inspectCall(operationTimeout, urlString);
      URLString urlResponse = new URLString();
      urlResponse.parseResponseURLString(body);
      String value = urlResponse.getParamValue(serviceName);
      if (value != null && value.equals(Constants.STATE_ENABLED)) {
        return true;
      }
      return false;
    } catch (SCServiceException e) {
      if (e.getSCErrorCode() == SCMPError.SERVICE_NOT_FOUND.getErrorCode()) {
        return false;
      }
      throw e;
    } catch (UnsupportedEncodingException e) {
      throw new SCServiceException(e.toString());
    }
  }
View Full Code Here

   *             encoding of request URL failed<br />
   */
  public Map<String, String> getStateOfServices(int operationTimeout, String serviceNamePattern) throws SCServiceException,
      UnsupportedEncodingException {
    if (this.attached == false) {
      throw new SCServiceException("Client not attached - getStateOfServices not possible.");
    }
    String urlString = URLString.toURLRequestString(Constants.CC_CMD_STATE, Constants.SERVICE_NAME, serviceNamePattern);
    try {
      String body = this.inspectCall(operationTimeout, urlString);
      URLString urlResponse = new URLString();
      urlResponse.parseResponseURLString(body);
      return urlResponse.getParameterMap();
    } catch (SCServiceException serviceEx) {
      return new HashMap<String, String>();
    } catch (UnsupportedEncodingException e) {
      throw new SCServiceException(e.toString());
    }
  }
View Full Code Here

   *             encoding of request URL failed<br />
   */
  public Map<String, String> getServiceConfiguration(int operationTimeout, String serviceName) throws SCServiceException,
      UnsupportedEncodingException {
    if (this.attached == false) {
      throw new SCServiceException("Client not attached - getServiceConfiguration not possible.");
    }
    String urlString = URLString.toURLRequestString(Constants.CC_CMD_SERVICE_CONF, Constants.SERVICE_NAME, serviceName);
    try {
      String body = this.inspectCall(operationTimeout, urlString);
      URLString urlResponse = new URLString();
      urlResponse.parseResponseURLString(body);
      return urlResponse.getParameterMap();
    } catch (UnsupportedEncodingException e) {
      throw new SCServiceException(e.toString());
    }
  }
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCServiceException

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.