Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCServiceException


   * @throws SCServiceException
   *             listener is already started<br />
   */
  public void setCheckRegistrationIntervalSeconds(int checkRegistrationIntervalSeconds) throws SCServiceException {
    if (this.listening == true) {
      throw new SCServiceException("Listener is already started not allowed to set property.");
    }
    this.checkRegistrationIntervalSeconds = checkRegistrationIntervalSeconds;
  }
View Full Code Here


   *             SC port and listener port are the same<br />
   *             bind to interface failed<be>
   */
  public synchronized void startListener() throws SCServiceException, SCMPValidatorException {
    if (this.listening == true) {
      throw new SCServiceException("Listener is already started not allowed to start again.");
    }
    if (this.scHost == null) {
      throw new SCMPValidatorException("Host must be set.");
    }
    if (this.connectionType == null) {
      throw new SCMPValidatorException("ConnectionType must be set.");
    }
    ValidatorUtility.validateInt(Constants.MIN_PORT_VALUE, this.scPort, Constants.MAX_PORT_VALUE, SCMPError.HV_WRONG_PORTNR);
    ValidatorUtility.validateInt(Constants.MIN_PORT_VALUE, this.listenerPort, Constants.MAX_PORT_VALUE,
        SCMPError.HV_WRONG_PORTNR);

    if (this.scPort == this.listenerPort) {
      throw new SCMPValidatorException("SC port and listener port must not be the same.");
    }

    if (this.nics == null || this.nics.size() == 0) {
      nics = new ArrayList<String>();
      try {
        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
        for (NetworkInterface netint : Collections.list(nets)) {
          Enumeration<InetAddress> inetAdresses = netint.getInetAddresses();
          for (InetAddress inetAddress : Collections.list(inetAdresses)) {
            if (inetAddress instanceof Inet6Address) {
              // ignore IPV6 addresses, bind not possible on this NIC
              continue;
            }
            nics.add(inetAddress.getHostAddress());
            LOGGER.debug("SCServer listens on " + inetAddress.getHostAddress());
          }
        }
      } catch (Exception e) {
        LOGGER.fatal("unable to detect network interface", e);
        throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, "Wrong interface.");
      }
    }

    ListenerConfiguration listenerConfig = new ListenerConfiguration(SCSessionServer.class.getSimpleName());
    listenerConfig.setConnectionType(this.connectionType.getValue());
    listenerConfig.setNetworkInterfaces(nics);
    listenerConfig.setPort(this.listenerPort);

    responder = new Responder(listenerConfig);
    try {
      responder.create();
      responder.startListenAsync();
    } catch (Exception ex) {
      this.listening = false;
      LOGGER.error("unable to start listener=" + listenerConfig.getName(), ex);
      throw new SCServiceException("Unable to start listener.", ex);
    }
    this.listening = true;
    RemoteNodeConfiguration remoteNodeConf = new RemoteNodeConfiguration(this.listenerPort + "server", this.scHost,
        this.scPort, this.connectionType.getValue(), this.keepAliveIntervalSeconds, this.checkRegistrationIntervalSeconds,
        1);
View Full Code Here

   * @throws SCMPValidatorException
   *             service name not set<br />
   */
  public SCSessionServer newSessionServer(String serviceName) throws SCServiceException, SCMPValidatorException {
    if (this.listening == false) {
      throw new SCServiceException("NewSessionServer not possible - server not listening.");
    }
    if (serviceName == null) {
      throw new SCMPValidatorException("service name must be set");
    }
    return new SCSessionServer(this, serviceName, requester);
View Full Code Here

   * @throws SCMPValidatorException
   *             service name not set<br />
   */
  public SCPublishServer newPublishServer(String serviceName) throws SCServiceException, SCMPValidatorException {
    if (this.listening == false) {
      throw new SCServiceException("newPublishServer not possible - server not listening.");
    }
    if (serviceName == null) {
      throw new SCMPValidatorException("service name must be set");
    }
    return new SCPublishServer(this, serviceName, requester);
View Full Code Here

      // hand it over to SynchronousCallback
      super.receive(reply);
      return;
    }
    if (reply.isFault()) {
      SCServiceException e = new SCServiceException(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      e.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      e.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      // inform service request is completed
      this.service.setRequestComplete();
      this.messageCallback.receive(e);
      return;
    }
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

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.