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

com.yahoo.container.logging.AccessLogEntry Maven / Gradle / Ivy

There is a newer version: 8.458.13
Show newest version
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.logging;

import com.yahoo.collections.ListMap;
import com.yahoo.yolean.trace.TraceNode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import static java.util.stream.Collectors.toMap;

/**
 * 

Information to be logged in the access log.

* *

This class contains the union of all information that can be * logged with all the supported access log formats.

* *

The add methods can be called multiple times, * but the parameters should be different for each * invocation of the same method.

* * This class is thread-safe. * * @author Tony Vaagenes * @author bakksjo * @author bjorncs */ public class AccessLogEntry { private final Object monitor = new Object(); private HitCounts hitCounts; private TraceNode traceNode; private ListMap keyValues=null; public void setHitCounts(final HitCounts hitCounts) { synchronized (monitor) { requireNull(this.hitCounts); this.hitCounts = hitCounts; } } public HitCounts getHitCounts() { synchronized (monitor) { return hitCounts; } } public void addKeyValue(String key,String value) { synchronized (monitor) { if (keyValues == null) { keyValues = new ListMap<>(); } keyValues.put(key,value); } } public Map> getKeyValues() { synchronized (monitor) { if (keyValues == null) { return null; } final Map> newMapWithImmutableValues = mapValues( keyValues.entrySet(), valueList -> Collections.unmodifiableList(new ArrayList<>(valueList))); return Collections.unmodifiableMap(newMapWithImmutableValues); } } private static Map mapValues( final Set> entrySet, final Function valueConverter) { return entrySet.stream() .collect(toMap( entry -> entry.getKey(), entry -> valueConverter.apply(entry.getValue()))); } public void setTrace(TraceNode traceNode) { synchronized (monitor) { requireNull(this.traceNode); this.traceNode = traceNode; } } public TraceNode getTrace() { synchronized (monitor) { return traceNode; } } @Override public String toString() { return "AccessLogEntry{" + "hitCounts=" + hitCounts + ", traceNode=" + traceNode + ", keyValues=" + keyValues + '}'; } private static void requireNull(final Object value) { if (value != null) { throw new IllegalStateException("Attempt to overwrite field that has been assigned. Value: " + value); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy