/*
(non-Javadoc)
@see javax.servlet.sip.ProxyBranch#cancel(java.lang.String[], int[], java.lang.String[])
507161
public void cancel(String[] protocol, int[] reasonCode, String[] reasonText) {
		if(proxy.getAckReceived()) throw new IllegalStateException("There has been an ACK received on this branch. Can not cancel.");
		
		try {			
			cancelTimer();
			if(this.isStarted() && !canceled && !timedOut &&
					(outgoingRequest.getMethod().equalsIgnoreCase(Request.INVITE) ||
							// https://code.google.com/p/sipservlets/issues/detail?id=253
							outgoingRequest.getMethod().equalsIgnoreCase(Request.PRACK) ||
							// https://code.google.com/p/sipservlets/issues/detail?id=33
							outgoingRequest.getMethod().equalsIgnoreCase(Request.UPDATE))) {
				if(lastResponse != null) { /* According to SIP RFC we should send cancel only if we receive any response first*/
					if(logger.isDebugEnabled()) {
						logger.debug("Trying to cancel ProxyBranch for outgoing request " + outgoingRequest);
					}
					if(lastResponse.getStatus() > Response.OK && !recursedBranches.isEmpty()) {
						//  Javadoc says it should throw an java.lang.IllegalStateException if the transaction has already been completed and it has no child branches
						if(logger.isDebugEnabled()) {
							logger.debug("lastResponse status for this branch is " + lastResponse.getStatus() + " and it has " + recursedBranches.size() + " to cancel");
						}
						return;
					}
					SipServletRequest cancelRequest = null;
					if(outgoingRequest.getMethod().equalsIgnoreCase(Request.PRACK) || outgoingRequest.getMethod().equalsIgnoreCase(Request.UPDATE)) {
						// https://code.google.com/p/sipservlets/issues/detail?id=253 and https://code.google.com/p/sipservlets/issues/detail?id=33
						// in case of PRACK or UPDATE we need to take the original INVITE
						cancelRequest = originalRequest.getLinkedRequest().createCancel();
					} else {
						cancelRequest = outgoingRequest.createCancel();
					}
					
					//https://code.google.com/p/sipservlets/issues/detail?id=272 Adding reason headers if needed
					if(protocol != null && reasonCode != null && reasonText != null
							&& protocol.length == reasonCode.length && reasonCode.length == reasonText.length) {
						for (int i = 0; i < protocol.length; i++) {
							String reasonHeaderValue = protocol[i] + ";cause=" + reasonCode[i];
							if(reasonText[i] != null && reasonText[i].trim().length() > 0) {
								reasonHeaderValue = reasonHeaderValue.concat(";text=\"" + reasonText[i] + "\"");
							}
							((SipServletRequestImpl)cancelRequest).setHeaderInternal("Reason", reasonHeaderValue, false);
							
						}
					}
					cancelRequest.send();
				} else {
					// We dont send cancel, but we must stop the invite retrans
					SIPClientTransaction tx = (SIPClientTransaction) outgoingRequest.getTransaction();
					
					if(tx != null) {
						StaticServiceHolder.disableRetransmissionTimer.invoke(tx);
						//disableTimeoutTimer.invoke(tx);
					} else {
						logger.warn("Transaction is null. Can not stop retransmission, they are already dead in the branch.");
					}
					/*
					try {
						//tx.terminate();
						// Do not terminate the tx here, because com.bea.sipservlet.tck.agents.spec.ProxyTest.testProxyCancel test is failing. If the tx
						// is terminated 100 Trying is dropped at JSIP.
					} catch(Exception e2) {
						logger.error("Can not terminate transaction", e2);
					}*/

				}
				canceled = true;
			}
			if(!this.isStarted() &&
					(outgoingRequest.getMethod().equalsIgnoreCase(Request.INVITE) ||
							// https://code.google.com/p/sipservlets/issues/detail?id=253
							outgoingRequest.getMethod().equalsIgnoreCase(Request.PRACK))) {
				canceled = true;	
			}
		}
		catch(Exception e) {
			throw new IllegalStateException("Failed canceling proxy branch", e);
		} finally {
			onBranchTerminated();
		}
			
	}
292265
@Deprecated
  public void cancel(com.google.gwt.user.client.Element e) {
    setElement(e);
  }
247019
@Override public final boolean cancel( boolean mayInterruptIfRunning ) {
    boolean did = false;
    synchronized(this) {        // Install the answer under lock
      if( !isCancelled() ) {
        did = true;             // Did cancel (was not cancelled already)
        _target.taskRemove(_tasknum);
        _target = null;         // Flag as canceled
//        UDPTimeOutThread.PENDING.remove(this);
      }
      notifyAll();              // notify in any case
    }
    return did;
  }
1225044
public void cancel() {
        if(actionInBackground != null) {
            if(executorService != null) {
               asyncFutureTask.cancel(true);
            } else {
                asyncThread.interrupt();
            }
        }
    }
1053173
@Override
	public Response cancelReserveRN(String corpNum, String requestNum)
			throws PopbillException {
		return cancelReserveRN(corpNum, requestNum, null);
	}
1206455
private void cancelInvokable(AbstractInvokable invokable) {
		// in case of an exception during execution, we still call "cancel()" on the task
		if (invokable != null && invokableHasBeenCanceled.compareAndSet(false, true)) {
			try {
				invokable.cancel();
			}
			catch (Throwable t) {
				LOG.error("Error while canceling task {}.", taskNameWithSubtask, t);
			}
		}
	}
437055
public boolean cancel(final boolean mayInterruptIfRunning, final long timeout, final TimeUnit unit)
      throws TimeoutException {
    return cancel(mayInterruptIfRunning, Optional.of(timeout), Optional.of(unit));
  }
567209
@Weight(value = Weight.Unit.VARIABLE, comment = "Depends on the current call stack depth")
  public static void cancelDeferredActions() {
    final int stackDepth = ThreadUtils.stackDepth();

    final List<Deferred> list = REGISTRY.get();
    final Iterator<Deferred> iterator = list.iterator();

    while (iterator.hasNext()) {
      final Deferred deferred = iterator.next();
      if (deferred.getStackDepth() >= stackDepth) {
        iterator.remove();
      }
    }
    if (list.isEmpty()) {
      REGISTRY.remove();
    }
  }
946767
@Weight(Weight.Unit.NORMAL)
  public static void cancelAll() {
    final List<TimeData> list = REGISTRY.get();
    list.clear();
    REGISTRY.remove();
  }
882310
@Override
  public final void cancel(final Map<String, Object> pRqVs,
    final CustOrder pCuOr, final EOrdStat pStat) throws Exception {
    Set<String> ndFl = new HashSet<String>();
    String tbn = CustOrderGdLn.class.getSimpleName();
    ndFl.add("itsId");
    ndFl.add("quant");
    ndFl.add("good");
    pRqVs.put(tbn + "neededFields", ndFl);
    pRqVs.put(tbn + "gooddeepLevel", 1);
    List<CustOrderGdLn> gds = this.srvOrm.retrieveListWithConditions(
      pRqVs, CustOrderGdLn.class, "where ITSOWNER=" + pCuOr.getItsId());
    pRqVs.remove(tbn + "neededFields");
    pRqVs.remove(tbn + "gooddeepLevel");
    ColumnsValues cvsIil = new ColumnsValues();
    cvsIil.getFormula().add("availableQuantity");
    for (CustOrderGdLn gl : gds) {
      List<GoodsPlace> gps = getSrvOrm().retrieveListWithConditions(pRqVs,
        GoodsPlace.class, "where ISALWAYS=0 and ITEM="
          + gl.getGood().getItsId());
      if (gps.size() > 0) {
        gps.get(0)
          .setItsQuantity(gps.get(0).getItsQuantity().add(gl.getQuant()));
        getSrvOrm().updateEntity(pRqVs, gps.get(0));
        cvsIil.put("itsVersion", new Date().getTime());
        cvsIil.put("availableQuantity", "AVAILABLEQUANTITY+" + gl.getQuant());
        this.srvDb.executeUpdate("ITEMINLIST", cvsIil,
          "ITSTYPE=0 and ITEMID=" + gps.get(0).getItem().getItsId());
      }
    }
    tbn = CustOrderSrvLn.class.getSimpleName();
    ndFl.remove("good");
    ndFl.add("service");
    ndFl.add("dt1");
    ndFl.add("dt2");
    pRqVs.put(tbn + "neededFields", ndFl);
    pRqVs.put(tbn + "gooddeepLevel", 1);
    List<CustOrderSrvLn> sls = this.srvOrm.retrieveListWithConditions(
      pRqVs, CustOrderSrvLn.class, "where ITSOWNER=" + pCuOr.getItsId());
    pRqVs.remove(tbn + "neededFields");
    pRqVs.remove(tbn + "gooddeepLevel");
    for (CustOrderSrvLn sl : sls) {
      if (sl.getDt1() == null) { //non-bookable:
        List<ServicePlace> sps = getSrvOrm().retrieveListWithConditions(pRqVs,
          ServicePlace.class, "where ISALWAYS=0 and ITEM=" + sl.getService()
            .getItsId());
        if (sps.size() > 0) {
          sps.get(0)
            .setItsQuantity(sps.get(0).getItsQuantity().add(sl.getQuant()));
          getSrvOrm().updateEntity(pRqVs, sps.get(0));
          cvsIil.put("itsVersion", new Date().getTime());
          cvsIil.put("availableQuantity", "AVAILABLEQUANTITY+" + sl.getQuant());
          this.srvDb.executeUpdate("ITEMINLIST", cvsIil,
            "ITSTYPE=1 and ITEMID=" + sps.get(0).getItem().getItsId());
        }
      } else { //bookable:
        List<SerBus> sebs = getSrvOrm().retrieveListWithConditions(pRqVs,
      SerBus.class, "where FRE=0 and SERV=" + sl.getService().getItsId()
+ " and FRTM=" + sl.getDt1().getTime() + " and TITM=" + sl.getDt1().getTime());
        if (sebs.size() == 1) {
          sebs.get(0).setFre(true);
          getSrvOrm().updateEntity(pRqVs, sebs.get(0));
        } else if (sebs.size() > 1) {
          this.log.error(pRqVs, CncOrd.class,
        "Several SERBUS for booked service: " + sl.getService().getItsId()
      + "/"  + sl.getDt1().getTime() + "/" + sl.getDt1().getTime());
          for (SerBus seb : sebs) {
            seb.setFre(true);
            getSrvOrm().updateEntity(pRqVs, seb);
          }
        } else {
          this.log.error(pRqVs, CncOrd.class,
        "There is no SERBUS for booked service: " + sl.getService().getItsId()
      + "/"  + sl.getDt1().getTime() + "/" + sl.getDt1().getTime());
        }
      }
    }
    String[] fieldsNames = new String[] {"itsId", "itsVersion", "stat"};
    pRqVs.put("fieldsNames", fieldsNames);
    pCuOr.setStat(pStat);
    getSrvOrm().updateEntity(pRqVs, pCuOr);
    pRqVs.remove("fieldsNames");
  }
1370564
public synchronized void cancel() // d583637
    {
        ivIsCanceled = true;
        stopAlarm();

        // F743-33394 - Wait for the sweep to finish.
        while (ivIsRunning) {
            try {
                wait();
            } catch (InterruptedException ex) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc, "interrupted", ex);
                Thread.currentThread().interrupt();
            }
        }

        ivActivator = null;
    }
1032160
@Override
  public boolean cancel(final boolean mayInterruptIfRunning) {
    try {
      return cancel(mayInterruptIfRunning, Optional.<Long>empty(), Optional.<TimeUnit>empty());
    } catch (final TimeoutException e) {
      // This should never happen.
      LOG.log(Level.WARNING, "Received a TimeoutException in VortexFuture.cancel(). Should not have occurred.");
      return false;
    }
  }
1372556
@Override
    public boolean cancel(boolean ignored) {
        boolean cancelled = false;
        if (latch.getCount() == 1) {
            latch.countDown();
            output = null;
            cancelled = true;
        }
        return cancelled;
    }
163269
public void cancelTimer() {
		synchronized (cTimerLock) {
			if (proxyTimeoutTask != null && proxyBranchTimerStarted) {
				proxyTimeoutTask.cancel();
				proxyTimeoutTask = null;
				proxyBranchTimerStarted = false;
			}
		}
	}
631524
public void cancelAll(final Object tag) {
        if (tag == null) {
            throw new IllegalArgumentException("Cannot cancelAll with a null tag");
        }
        cancelAll(new RequestFilter() {
            @Override
            public boolean apply(Request<?> request) {
                return request.getTag() == tag;
            }
        });
    }
262681
public void cancelCancellable() {

        if (timeoutMessageCancellable != null) {
            timeoutMessageCancellable.cancel();
        }
        if (getResponseFuture() != null && !getResponseFuture().isDone()) {
            getResponseFuture().cancel(true);
        }
    }
461809
public void cancelJob(CancelJobRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getJobId(), "The parameter jobId should not be null or empty string.");

        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.PUT, JOB, request.getJobId());
        internalRequest.addParameter("cancel", null);

        this.invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }