class DeclarativeSampler implements SamplerFunction<M> {

  @Override public @Nullable Boolean trySample(@Nullable M method) {
    if (method == null) return null;
    Sampler sampler = methodToSamplers.get(method);
    if (sampler == NULL_SENTINEL) return null;
    if (sampler != null) return sampler.isSampled(0L); // counting sampler ignores the input

    sampler = samplerOfMethod(method);
    if (sampler == null) {
      methodToSamplers.put(method, NULL_SENTINEL);
      return null;
    }

    Sampler previousSampler = methodToSamplers.putIfAbsent(method, sampler);
    if (previousSampler != null) sampler = previousSampler; // lost race, use the existing counter
    return sampler.isSampled(0L); // counting sampler ignores the input
  }

    DeclarativeSampler();

}