コード例 #1
0
ファイル: JCSyncCore.java プロジェクト: anwajler/p2pm
  private boolean checkIfAlreadyReceived(PublishRequest req) {
    boolean retVal = false;
    Integer tid = req.getTransactionID();
    if (this.alreadyDeliveredRequests.containsKey(tid)) {
      PublishRequest oldReq = this.alreadyDeliveredRequests.get(tid);
      if (oldReq.getPublisher().compareTo(req.getPublisher()) == 0
          && Arrays.equals(oldReq.getMessage(), req.getMessage())) {
        retVal = true;
      }
      retVal = true;
      JCsyncAbstractOperation op = JCsyncAbstractOperation.encode(req.getMessage());
      JCsyncAbstractOperation op_ = JCsyncAbstractOperation.encode(oldReq.getMessage());
      log.warn("request already received: " + req + ", with operation:" + op);
      log.warn("\toldReq in buffer: " + oldReq + ", with operation:" + op_);
    } else {
      retVal = false;
      log.debug("request added to received requests buffer: " + req);
      this.alreadyDeliveredRequests.put(new Key(req.getTopicID(), tid), req);

      // log.trace(retVal);
    }
    PublishRequest req_;
    if (this.alreadyDeliveredRequests.size() > 200) {
      List<Key> list = new ArrayList<Key>();
      list.addAll(this.alreadyDeliveredRequests.keySet());
      log.trace(
          "Clrearing received request buffer, actual size:" + this.alreadyDeliveredRequests.size());
      Collections.sort(list);
      for (int i = 0; i < list.size() - 100; i++) {
        req_ = this.alreadyDeliveredRequests.remove(list.get(i));
        req_ = null;
      }
      list = null;
      System.gc();
    }
    return retVal;
  }
コード例 #2
0
ファイル: JCSyncCore.java プロジェクト: anwajler/p2pm
  @Override
  public void onDeliverRequest(PublishRequest req) {
    try {
      //        // TODO remove 4 lines below - just for debug
      //        byte[] details = req.getMessage();
      //        if (req.getEventType() == 1413) {
      //            System.out.println("zzz");
      //        }
      JCsyncAbstractOperation op = JCsyncAbstractOperation.encode(req.getMessage());
      op.setReqestID(req.getTransactionID());

      log.trace(
          this.pubsubLayer.getNodeInfo().getName()
              + " (onDeliverRequest) - [publisher]:"
              + req.getPublisher()
              + ", [node relay]:"
              + req.getSourceInfo()
              + ": "
              + op);
      if (this.checkIfAlreadyReceived(req)) {
        log.trace(
            this.pubsubLayer.getNodeInfo().getName()
                + " (onDeliverRequest): - received request that was aready received, skipping ... : "
                + op);
        return;
      }
      // check that this node can hold this request
      JCSyncAbstractSharedObject so = this.sharedObjects.get(op.getObjectID());
      if (so != null) {
        if ((op.getOperationType() & OP_REQ_GENERIC) == OP_REQ_GENERIC) {
          if (op.getOperationType() == OP_REQ_TRANSFER_OBJECT) {
            // there is no need to inform consistency manager about this kind of request, just send
            // response and indication
            sendResponse(req, PubSubConstants.RESP_SUCCESS);
            synchronized (so.operationIdIncrementLocker) {
              log.trace(
                  getNodeInfo().getName()
                      + ": transferring shared object with current operation id: "
                      + so.getCurrentOperationID()
                      + ", to node: "
                      + req.getPublisher());
              JCsyncAbstractOperation op_ =
                  JCsyncAbstractOperation.get_OP_IND_TRANSFER_OBJECT(
                      op.getObjectID(), so.encode(), req.getPublisher());
              op_.setReqestID(op.getReqestID());
              sendMessage(req, op_, false);
            }

          } else {
            // if this node is a root
            if (getAssignedTopic(req.getTopicID())
                .isTopicRoot(this.pubsubLayer.getNodeInfo().getID())) {
              AbstractConsistencyManager acm = getConsistencyManager(req.getTopicID());
              if (acm != null) {
                log.trace(
                    "(onDeliverRequest) - passing operation to consistency model: "
                        + op.toString());
                acm.requestReceived(req, op);
              } else {
                log.fatal(
                    "(onDeliverRequest) - there is no registered consistency manager for this operation: "
                        + op.toString());
              }
            } else {
              log.trace(
                  "(onDeliverRequest) - forwarding operation request to the parent node: "
                      + op.toString());
              this.pubsubLayer.forwardToParent(req, getAssignedTopic(req.getTopicID()));
            }
          }
        } else {
          log.fatal("(onDeliverRequest) - unhandled operation type: " + op.toString());
        }
      } else {
        if (op.getOperationType() == OP_REQ_TRANSFER_OBJECT) {
          log.trace(
              getNodeInfo().getName()
                  + ": (onDeliverRequest) - shared object not found!: "
                  + op.toString()
                  + ", forwarding request to the topic owner: "
                  + op.toString());
          this.pubsubLayer.forwardToOtherNode(
              req, this.pubsubLayer.getTopic(op.getObjectID()).getOwner().getNodeInfo());
        } else {
          log.fatal(
              getNodeInfo().getName()
                  + ": (onDeliverRequest) - shared object not found!: "
                  + op.toString());
          sendResponse(req, PubSubConstants.RESP_DOESNOTEXIST);
        }
      }
    } catch (Exception e) {
      log.error("An error occurred:", e);
    }
  }