class KeyValueLocator implements Locator {

  @Override
  public void dispatch(final Request<? extends Response> request, final List<Node> nodes,
                       final ClusterConfig config, final CoreContext ctx) {
    if (request instanceof TargetedRequest) {
      dispatchTargeted((TargetedRequest) request, nodes, ctx);
    } else {
      KeyValueRequest r = (KeyValueRequest) request;
      String bucket = r.bucket();
      BucketConfig bucketConfig = config.bucketConfig(bucket);

      if (bucketConfig == null) {
        // Since a bucket is opened lazily, it might not be available yet (or for some
        // other reason the config is gone) - send it into retry!
        RetryOrchestrator.maybeRetry(ctx, request, ctx.core().configurationProvider().bucketConfigLoadInProgress()
          ? RetryReason.BUCKET_OPEN_IN_PROGRESS
          : RetryReason.BUCKET_NOT_AVAILABLE);
        return;
      }

      if (bucketConfig instanceof CouchbaseBucketConfig) {
        couchbaseBucket(r, nodes, (CouchbaseBucketConfig) bucketConfig, ctx);
      } else if (bucketConfig instanceof MemcachedBucketConfig) {
        memcacheBucket(r, nodes, (MemcachedBucketConfig) bucketConfig, ctx);
      } else {
        throw new IllegalStateException("Unsupported Bucket Type: " + bucketConfig
          + " for request " + request);
      }
    }
  }

}