-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6216fe9
commit aef99b8
Showing
3 changed files
with
38 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
thread-context/src/main/java/io/opentracing/threadcontext/ContextSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.opentracing.threadcontext; | ||
|
||
import com.github.threadcontext.Context; | ||
import com.github.threadcontext.MutableContextSupplier; | ||
import com.github.threadcontext.ThreadLocalContextSupplier; | ||
import com.github.threadcontext.control.TryFinallyContext; | ||
import io.opentracing.NoopSpan; | ||
import io.opentracing.Span; | ||
|
||
public class ContextSpan { | ||
|
||
public static final ContextSpan DEFAULT = new ContextSpan(Context.DEFAULT); | ||
|
||
private final ThreadLocal<Span> span; | ||
|
||
public ContextSpan(MutableContextSupplier contextSupplier) { | ||
span = new ThreadLocal<Span>() { | ||
protected Span initialValue() { | ||
return NoopSpan.INSTANCE; | ||
} | ||
}; | ||
contextSupplier.suppliers.add(new ThreadLocalContextSupplier<>(span)); | ||
} | ||
|
||
public Span get() { | ||
return span.get(); | ||
} | ||
|
||
public Context set(Span span) { | ||
return new TryFinallyContext(() -> { | ||
Span oldValue = this.span.get(); | ||
this.span.set(span); | ||
return () -> this.span.set(oldValue); | ||
}); | ||
} | ||
|
||
} |
53 changes: 0 additions & 53 deletions
53
thread-context/src/main/java/io/opentracing/threadcontext/ThreadContextSpan.java
This file was deleted.
Oops, something went wrong.