/** * Put to MDC / threadContext request IDs. */ private void putRequestIDs( HttpServletRequest hsr, ThreadContext threadContext, MDCManager mdcManager ) { /* We would always generate internalID and provide that in the MDC. * If the calling service supplies an externalID, we'd map that under its own key. * PreferredID should try to use externalID if it's available, and default over to using internalID if it's not. * What this gives us is a single key we can use to reference an ID for the request, * and whenever possible it'll reflect the externally supplied ID. */ String internalID = UUID.randomUUID().toString(); String externalID = hsr.getHeader( EXTERNAL_ID ); String preferredID = externalID != null ? externalID : internalID; mdcManager.putRequestIDs( internalID, externalID, preferredID ); /* * We should also put the same values in the ThreadContext map, so we can reference them from code without * having to go through the logging framework */ threadContext.put( INTERNAL_ID, internalID ); if ( externalID != null ) { threadContext.put( EXTERNAL_ID, externalID ); } threadContext.put( PREFERRED_ID, preferredID ); }
public static String getLockReservationName() { ThreadContext ctx = ThreadContext.getContext( true ); String ownerName = (String) ctx.get( PARTYLINE_LOCK_OWNER ); if ( ownerName == null ) { ownerName = "Context of: " + Thread.currentThread().getName(); ctx.put( PARTYLINE_LOCK_OWNER, ownerName ); } return ownerName; }
public void clearMergedPath( ArtifactStore originatingStore, Set<Group> groups, String path ) { Logger logger = LoggerFactory.getLogger( getClass() ); logger.debug( "Clearing merged path: {} from indexes of: {} (triggered by: {})", path, groups, originatingStore ); StoreKey key = originatingStore.getKey(); ThreadContext context = ThreadContext.getContext( true ); context.put( ORIGIN_KEY, key ); try { // the only time a group will have local storage of the path is when it has been merged // ...in which case we should try to delete it. indexManager.clearIndexedPathFrom( path, groups, null ); } finally { context.remove( ORIGIN_KEY ); } }