Exemple #1
0
  @Override
  public synchronized Topic subscribeSharedObject(String name, boolean blocking)
      throws ObjectNotExistsException, OperationForbiddenException, Exception {
    // preparing locker to wait for response
    try {
      JCsyncAbstractOperation operation =
          JCsyncAbstractOperation.get_OP_REQ_SUBSCRIBE(name, this.getNodeInfo().getName());
      // inform Consistency Manager before sending request
      this.dcManager.inititBuffer(name);
      this.dcManager.beforeRequestSend(operation, blocking);
      this.pubsubLayer.getCustomAlgorith().registerSharedObjectName(name);
      this.pubsubLayer.getCustomAlgorith().networkSubscribe(name);
      Short respCode = (Short) this.dcManager.afterRequestSend(operation, blocking);
      if (respCode != null) {
        // if the topic was created
        if (respCode == JCSyncConstans.J_RESP_GENERAL_SUCCESS) {
          return this.pubsubLayer.getTopic(name);
          // if node can't subscribe to this topic
        } else if (respCode == JCSyncConstans.J_ERR_COLLECTION_AUTH_ERROR) {
          throw OperationForbiddenException.instance();
          // if the topic not exists
        } else if (respCode == JCSyncConstans.J_ERR_OBJECT_NOT_EXISTS) {
          throw ObjectNotExistsException.instance();
        } else {
          log.fatal(
              "received UNHANLED respCode for operation: "
                  + operation.getOperationType()
                  + ", objectID:"
                  + operation.getObjectID());
        }
      } else {
        log.fatal(
            "received [null] respCode for operation: "
                + operation.getOperationType()
                + ", objectID:"
                + operation.getObjectID());
      }

    } catch (InterruptedException e) {
      throw new Exception("An error on (subscribeSharedObject)");
    }
    log.error("(subscribeSharedObject) returns Topic = null from unknow reason!");
    return null;
  }
Exemple #2
0
  @Override
  public void onDeliverPubSubResponse(
      String name, short operationType, short respCode, long reqID) {

    log.trace(
        this.pubsubLayer.getNodeInfo().getName()
            + ": (onDeliverPubSubResponse) , topicName: "
            + name
            + ", operationType: "
            + operationType
            + ", respCode: "
            + respCode
            + ",reqID: "
            + reqID);

    short rCode = respCode;
    // mapping respCode - in the PubSub sometimes calls respCodes from PubSUbConstants and sometimes
    // from NodeError
    if (respCode == NodeError.AUTHERR) {
      rCode = PubSubConstants.RESP_FORBIDDEN;
    } else if (respCode == NodeError.NOSUCHTOPICERR) {
      rCode = PubSubConstants.RESP_DOESNOTEXIST;
    }
    respCode = rCode;
    // mapping pubsub respCodes to jcsync resp codes
    if (respCode == PubSubConstants.RESP_SUCCESS) {
      rCode = JCSyncConstans.J_RESP_GENERAL_SUCCESS;
    } else if (respCode == PubSubConstants.RESP_ALREADYEXISTS) {
      rCode = JCSyncConstans.J_ERR_COLLECTION_EXISTS;
    } else if (respCode == PubSubConstants.RESP_DOESNOTEXIST) {
      rCode = JCSyncConstans.J_ERR_OBJECT_NOT_EXISTS;
    } else if (respCode == PubSubConstants.RESP_FORBIDDEN) {
      rCode = JCSyncConstans.J_ERR_COLLECTION_AUTH_ERROR;
    }
    respCode = rCode;
    try {
      /* sometimes response is already received, but the locker is not
       * properly initialized in the consistency manager - if
       * the request is sending then wait for the end of it.             *
       */
      this.request_response_locker.readLock().lock();
      if ((operationType & OP_GENERIC_JCSYNC_OPERATION) == OP_GENERIC_JCSYNC_OPERATION) {
        JCsyncAbstractOperation o = null; // JCsyncAbstractOperation.getByType(operationType, name);
        o = JCsyncAbstractOperation.getByType(operationType, name, this.getNodeInfo().getName());
        o.setReqestID(reqID);
        if (getConsistencyManager(name) != null) {
          getConsistencyManager(name).responseReceived(o, respCode);
        } else {
          this.dcManager.responseReceived(o, respCode);
        }
        return;
      }
      switch (operationType) {
        case PubSubConstants.MSG_CREATETOPIC:
          {
            JCsyncAbstractOperation o = null;
            o =
                JCsyncAbstractOperation.get_OP_REQ_CREATE_SHARED_OBJECT(
                    name, this.getNodeInfo().getName());
            this.dcManager.responseReceived(o, respCode);
            return;
          }
        case PubSubConstants.MSG_SUBSCRIBE:
          {
            JCsyncAbstractOperation o = null;
            o = JCsyncAbstractOperation.get_OP_REQ_SUBSCRIBE(name, this.getNodeInfo().getName());
            this.dcManager.responseReceived(o, respCode);
            return;
          }
        case PubSubConstants.MSG_UNSUBSCRIBE:
          {
            JCsyncAbstractOperation o = null;
            o = JCsyncAbstractOperation.get_OP_REQ_UNSUBSCRIBE(name, this.getNodeInfo().getName());
            this.dcManager.responseReceived(o, respCode);
            return;
          }
        case PubSubConstants.EVENT_REMOVETOPIC:
          {
            JCsyncAbstractOperation o = null;
            o = JCsyncAbstractOperation.get_OP_REQ_REMOVE(name, this.getNodeInfo().getName());
            this.dcManager.responseReceived(o, respCode);
            return;
          }
        default:
          {
            log.fatal(
                "Received unsuported response code: "
                    + respCode
                    + ", for operation: "
                    + operationType
                    + ", for shared object name: "
                    + name);
          }
      }
    } catch (Exception ex) {
      log.error("An error while processing (onDeliverPubSubResponse)", ex);
    } finally {
      this.request_response_locker.readLock().unlock();
    }
  }