/** * Registers the provided key with the provided handler. It is recommended to statically configure the mapping from * keys to handlers as part of the process configuration, rather than calling this method. */ public static void add(BagKey key, BaggageHandler<?> handler) { instance.doAdd(key, handler); }
/** * Look up the {@link BagKey} that the specified {@link BaggageHandler} is registered to */ public static BagKey get(BaggageHandler<?> handler) { return instance.doGet(handler); }
/** * Unregisters the handler for the specified bag key. */ public static void remove(BagKey key) { instance.doRemove(key); }
/** * Create a {@link BaggageHandlerRegistry} instance by parsing the mappings configured in the provided * {@link Config} * * @param config a typesafe config * @return a {@link BaggageHandlerRegistry} instance with handlers loaded for the configured bag keys */ static BaggageHandlerRegistry create(Config config) { Map<BagKey, BaggageHandler<?>> mapping = new TreeMap<>(); for (Entry<String, ConfigValue> x : config.getConfig(BAGS_CONFIGURATION_KEY).entrySet()) { String bagHandlerClassName = x.getValue().unwrapped().toString(); Integer bagNumber = parseBagKey(x.getKey(), bagHandlerClassName); if (bagNumber == null) continue; BagKey key = BagKey.indexed(bagNumber); BaggageHandler<?> handler = resolveHandler(bagHandlerClassName); if (handler == null) continue; mapping.put(key, handler); } if (mapping.size() == 0) { log.warn("No baggage handlers are registered -- if this is unexpected, ensure `bag` is correctly configured"); } else { String handlersString = mapping.entrySet().stream() .map(e -> "\t" + e.getKey().toString() + ": " + e.getValue().getClass().getName().toString()) .collect(Collectors.joining("\n")); log.info(mapping.size() + " baggage handlers registered:\n" + handlersString); } return new BaggageHandlerRegistry(new Registrations(mapping)); }
static synchronized BagKey checkRegistration() { registration = BaggageHandlerRegistry.get(instance); if (registration == null) { _log.error("SimpleBag MUST be registered to a key before it can be propagated. " + "There is currently no registration for SimpleBag and it will not be propagated. " + "To register a bag set the bag.{index} property in your application.conf (eg, for " + "index 10, bag.10 = \"brown.tracingplane.bdl.examples.SimpleBag\") or with -Dbag.{index} flag " + "(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.SimpleBag)"); } return registration; }
/** * Create a {@link BaggageHandlerRegistry} instance by parsing configured values from the default config */ static BaggageHandlerRegistry create() { return create(ConfigFactory.load()); }
@SuppressWarnings("unchecked") static BaggageHandler<?> resolveHandler(String bagClassName) { try { Class<?> cls = Class.forName(bagClassName); if (Bag.class.isAssignableFrom(cls)) { return resolveHandlerForBag((Class<? extends Bag>) cls); } else { log.error("Unable to get BaggageHandler for non-Bag class " + cls); } } catch (ClassNotFoundException e) { log.error("Cannot instantiate Bag handler " + bagClassName + ", class not found", e); } return null; }
/** * Create an empty {@link BaggageHandlerRegistry} */ static BaggageHandlerRegistry empty() { return new BaggageHandlerRegistry(new Registrations(new TreeMap<>())); }
static synchronized BagKey checkRegistration() { registration = BaggageHandlerRegistry.get(instance); if (registration == null) { _log.error("ExampleBag MUST be registered to a key before it can be propagated. " + "There is currently no registration for ExampleBag and it will not be propagated. " + "To register a bag set the bag.{index} property in your application.conf (eg, for " + "index 10, bag.10 = \"brown.tracingplane.bdl.examples.ExampleBag\") or with -Dbag.{index} flag " + "(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.ExampleBag)"); } return registration; }
static synchronized BagKey checkRegistration() { registration = BaggageHandlerRegistry.get(instance); if (registration == null) { _log.error("XTraceBaggage MUST be registered to a key before it can be propagated. " + "There is currently no registration for XTraceBaggage and it will not be propagated. " + "To register a bag set the bag.{index} property in your application.conf (eg, for " + "index 10, bag.10 = \"brown.xtrace.XTraceBaggage\") or with -Dbag.{index} flag " + "(eg, for index 10, -Dbag.10=brown.xtrace.XTraceBaggage)"); } return registration; }
static synchronized BagKey checkRegistration() { registration = BaggageHandlerRegistry.get(instance); if (registration == null) { _log.error("SimpleBag2 MUST be registered to a key before it can be propagated. " + "There is currently no registration for SimpleBag2 and it will not be propagated. " + "To register a bag set the bag.{index} property in your application.conf (eg, for " + "index 10, bag.10 = \"brown.tracingplane.bdl.examples.SimpleBag2\") or with -Dbag.{index} flag " + "(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.SimpleBag2)"); } return registration; }
static synchronized BagKey checkRegistration() { registration = BaggageHandlerRegistry.get(instance); if (registration == null) { _log.error("FonsecaBag MUST be registered to a key before it can be propagated. " + "There is currently no registration for FonsecaBag and it will not be propagated. " + "To register a bag set the bag.{index} property in your application.conf (eg, for " + "index 10, bag.10 = \"brown.tracingplane.bdl.examples.FonsecaBag\") or with -Dbag.{index} flag " + "(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.FonsecaBag)"); } return registration; }