org.graylog2.plugin.lookup.LookupResult Maven / Gradle / Ivy
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* .
*/
package org.graylog2.plugin.lookup;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.auto.value.AutoValue;
import org.graylog2.lookup.LookupDefaultMultiValue;
import org.graylog2.lookup.LookupDefaultSingleValue;
import javax.annotation.Nullable;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* The result of looking up a key in a lookup table (i. e. lookup data adapter or lookup cache).
*
* For convenience, this class can be serialized and deserialized with Jackson (see
* {@link com.fasterxml.jackson.databind.ObjectMapper}, but we strongly recommend implementing your own
* serialization and deserialization logic if you're implementing a lookup cache.
*
* There are no guarantees about binary compatibility of this class across Graylog releases!
*
* @see LookupDataAdapter#get(Object)
* @see LookupCache#get(LookupCacheKey, java.util.concurrent.Callable)
* @see LookupCacheKey
*/
@AutoValue
public abstract class LookupResult {
private static final long NO_TTL = Long.MAX_VALUE;
// Cache erroneous results with a shorter TTL
private static final long ERROR_CACHE_TTL = Duration.ofSeconds(5).toMillis();
private static final LookupResult EMPTY_LOOKUP_RESULT = builder()
.cacheTTL(NO_TTL)
.build();
private static final LookupResult DEFAULT_ERROR_LOOKUP_RESULT = builder()
.cacheTTL(ERROR_CACHE_TTL)
.hasError(true)
.build();
public static final String SINGLE_VALUE_KEY = "value";
@JsonProperty("single_value")
@Nullable
public abstract Object singleValue();
@JsonProperty("multi_value")
@Nullable
public abstract Map