MCPcopy Create free account
hub / github.com/OpenTSDB/asynchbase / shutdown

Method shutdown

src/RegionClient.java:479–566  ·  view source on GitHub ↗

Attempts to gracefully terminate the connection to this RegionServer.

()

Source from the content-addressed store, hash-verified

477 * Attempts to gracefully terminate the connection to this RegionServer.
478 */
479 public Deferred<Object> shutdown() {
480 final class RetryShutdown<T> implements Callback<Deferred<Object>, T> {
481 private final int nrpcs;
482 RetryShutdown(final int nrpcs) {
483 this.nrpcs = nrpcs;
484 }
485 public Deferred<Object> call(final T ignored) {
486 return shutdown();
487 }
488 public String toString() {
489 return "wait until " + nrpcs + " RPCs complete";
490 }
491 };
492
493 // First, check whether we have RPCs in flight. If we do, we need to wait
494 // until they complete.
495 {
496 final ArrayList<Deferred<Object>> inflight = getInflightRpcs();
497 final int size = inflight.size();
498 if (size > 0) {
499 return Deferred.group(inflight)
500 .addCallbackDeferring(new RetryShutdown<ArrayList<Object>>(size));
501 }
502 // Then check whether have batched RPCs. If we do, flush them.
503 // Copy the batch to a local variable and null it out.
504 final MultiAction batched_rpcs;
505 synchronized (this) {
506 batched_rpcs = this.batched_rpcs;
507 this.batched_rpcs = null;
508 }
509 if (batched_rpcs != null && batched_rpcs.size() != 0) {
510 final Deferred<Object> d = batched_rpcs.getDeferred();
511 sendRpc(batched_rpcs);
512 return d.addCallbackDeferring(new RetryShutdown<Object>(1));
513 }
514 }
515
516 {
517 final ArrayList<Deferred<Object>> pending = getPendingRpcs();
518 if (pending != null) {
519 return Deferred.group(pending).addCallbackDeferring(
520 new RetryShutdown<ArrayList<Object>>(pending.size()));
521 }
522 }
523
524 final Channel chancopy = chan; // Make a copy as ...
525 if (chancopy == null) {
526 return Deferred.fromResult(null);
527 }
528 LOG.debug("Shutdown requested, chan={}", chancopy);
529 if (chancopy.isConnected()) {
530 Channels.disconnect(chancopy); // ... this is going to set it to null.
531 // At this point, all in-flight RPCs are going to be failed.
532 }
533 if (chancopy.isBound()) {
534 Channels.unbind(chancopy);
535 }
536 // It's OK to call close() on a Channel if it's already closed.

Callers 1

callMethod · 0.45

Calls 8

getInflightRpcsMethod · 0.95
sizeMethod · 0.95
sendRpcMethod · 0.95
getPendingRpcsMethod · 0.95
closeMethod · 0.80
sizeMethod · 0.45
getDeferredMethod · 0.45
callbackMethod · 0.45

Tested by

no test coverage detected