protected void handleConsumerUnreadyRequest(long requestId, Address address) { Owner consumer = new Owner(address, requestId); _consumerLock.lock(); try { _consumersAvailable.remove(consumer); } finally { _consumerLock.unlock(); } sendRemoveConsumerRequest(consumer); }
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(); } }
protected void handleTaskRequest(long requestId, Address address) { final Owner consumer; Owner source = new Owner(address, requestId); _consumerLock.lock(); try { consumer = _consumersAvailable.poll(); // We don't add duplicate run requests - this allows for resubmission // if it is thought the message may have been dropped if (consumer == null && !_runRequests.contains(source)) { _runRequests.add(source); } } finally { _consumerLock.unlock(); } if (consumer != null) { sendRequest( source.getAddress(), Type.CONSUMER_FOUND, consumer.getRequestId(), consumer.getAddress()); sendRemoveConsumerRequest(consumer); } else { sendNewRunRequest(source); } }