Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat(request context): clear context after request is completed" #855

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2024 Expedia Inc.
Copyright (C) 2013-2021 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,11 +74,6 @@ default <T> Optional<T> getIfAvailable(String key, Class<T> clazz) {
* @return returns the netty executor which started handling the current request
*/
Executor executor();

/**
* Removes all the stored items from this context.
*/
void clear();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,4 @@ public Optional<InetSocketAddress> clientAddress() {
public Executor executor() {
return Runnable::run;
}

@Override
public void clear() {
// no-op
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2024 Expedia Inc.
Copyright (C) 2013-2023 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,26 +25,16 @@ import java.util.concurrent.Executor
* (because the call was not made within an interceptor chain).
*/
object DummyContext : HttpInterceptor.Context {
override fun add(
key: String,
value: Any,
) {
override fun add(key: String, value: Any) {
// Empty by design
}

@Deprecated("Deprecated in Java", ReplaceWith("getIfAvailable"))
override fun <T : Any> get(
key: String,
clazz: Class<T>,
): T? = null
override fun <T : Any> get(key: String, clazz: Class<T>): T? = null

override fun isSecure(): Boolean = false

override fun clientAddress(): Optional<InetSocketAddress> = Optional.empty()

override fun executor(): Executor = Executor { it.run() }

override fun clear() {
// no-op
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2024 Expedia Inc.
Copyright (C) 2013-2023 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@ import java.util.Optional
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executor


/**
* ConcurrentHashMap backed implementation of HttpInterceptor.Context.
*
Expand All @@ -33,34 +34,26 @@ class HttpInterceptorContext(
private val secure: Boolean,
private val clientAddress: InetSocketAddress?,
private val executor: Executor?,
override val timers: ContextualTimers? = null,
override val timers: ContextualTimers? = null
) : HttpInterceptor.Context, TimeMeasurable {
// This may seem redundant but it allows Executor to be a lambda without needing to set `timers`.
constructor(secure: Boolean, clientAddress: InetSocketAddress?, executor: Executor?) : this(secure, clientAddress, executor, null)

private val context = ConcurrentHashMap<String, Any>()

override fun add(
key: String,
value: Any,
) {
override fun add(key: String, value: Any) {
context[key] = value
}

@Deprecated("Deprecated in Java")
override fun <T> get(
key: String,
clazz: Class<T>,
): T = context[key] as T
override fun <T> get(key: String, clazz: Class<T>): T = context[key] as T

override fun isSecure() = secure

override fun clientAddress() = Optional.ofNullable(clientAddress)

override fun executor(): Executor? = executor

override fun clear() = context.clear()

companion object {
// Visible for testing
@Deprecated("use the constructor instead")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2024 Expedia Inc.
Copyright (C) 2013-2023 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -278,8 +278,6 @@ protected void hookOnCancel() {
protected void hookFinally(SignalType type) {
timers.stopTiming(RESPONSE_PROCESSING);
timers.stopTiming(REQUEST_PROCESSING);

context.clear();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2024 Expedia Inc.
Copyright (C) 2013-2021 Expedia Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -81,11 +81,6 @@ public Optional<InetSocketAddress> clientAddress() {
public Executor executor() {
return this.executor;
}

@Override
public void clear() {
context.clear();
}
}

}
Loading