Exemple #1
0
  protected void handleView(View view) {
    this.view = view;
    if (log.isDebugEnabled()) log.debug("view=" + view);
    List<Address> members = view.getMembers();

    _consumerLock.lock();
    try {
      // This removes the consumers that were registered that are now gone
      Iterator<Owner> iterator = _consumersAvailable.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveConsumerRequest(owner);
        }
      }

      // This removes the tasks that those requestors are gone
      iterator = _runRequests.iterator();
      while (iterator.hasNext()) {
        Owner owner = iterator.next();
        if (!members.contains(owner.getAddress())) {
          iterator.remove();
          sendRemoveRunRequest(owner);
        }
      }

      synchronized (_awaitingReturn) {
        for (Entry<Owner, Runnable> entry : _awaitingReturn.entrySet()) {
          // The person currently servicing our request has gone down
          // without completing so we have to keep our request alive by
          // sending ours back to the coordinator
          Owner owner = entry.getKey();
          if (!members.contains(owner.getAddress())) {
            Runnable runnable = entry.getValue();
            // We need to register the request id before sending the request back to the coordinator
            // in case if our task gets picked up since another was removed
            _requestId.put(runnable, owner.getRequestId());
            _awaitingConsumer.add(runnable);
            sendToCoordinator(RUN_REQUEST, owner.getRequestId(), local_addr);
          }
        }
      }
    } finally {
      _consumerLock.unlock();
    }
  }
Exemple #2
0
  protected void handleConsumerReadyRequest(long requestId, Address address) {
    Owner requestor;
    final Owner source = new Owner(address, requestId);
    _consumerLock.lock();
    try {
      requestor = _runRequests.poll();
      // We don't add duplicate consumers - this allows for resubmission
      // if it is thought the message may have been dropped
      if (requestor == null && !_consumersAvailable.contains(source)) {
        _consumersAvailable.add(source);
      }
    } finally {
      _consumerLock.unlock();
    }

    if (requestor != null) {
      sendRequest(
          requestor.getAddress(), Type.CONSUMER_FOUND, source.getRequestId(), source.getAddress());
      sendRemoveRunRequest(requestor);
    } else {
      sendNewConsumerRequest(source);
    }
  }