All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.context.SharedContextMapUtils Maven / Gradle / Ivy

package com.undefinedlabs.scope.context;

import com.undefinedlabs.scope.logger.ScopeLogger;
import com.undefinedlabs.scope.logger.ScopeLoggerResolver;

public class SharedContextMapUtils {

  private static final ScopeLogger LOGGER = ScopeLoggerResolver.INSTANCE.get();

  public static ImmutableContext attachSharedContextMap(final ImmutableContext context) {
    return context
        .withValue(SharedContextMap.SHARED_CONTEXT_MAP_KEY, new SharedContextMap())
        .attach();
  }

  public static SharedContextMap getSharedContextMap(final ImmutableContext context) {
    final SharedContextMap sharedContextMap = SharedContextMap.SHARED_CONTEXT_MAP_KEY.get(context);
    if (sharedContextMap == null) {
      attachSharedContextMap(ImmutableContext.current());
      final SharedContextMap newMap =
          SharedContextMap.SHARED_CONTEXT_MAP_KEY.get(ImmutableContext.current());
      LOGGER.trace("--- Created new map: " + newMap);
      return newMap;
    }

    return sharedContextMap;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy