Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
b4484e5d
Commit
b4484e5d
authored
Apr 11, 2018
by
Liuhaoyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ContextManager
parent
5af0ec2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
31 deletions
+70
-31
IIgnoreTracerContextListener.cs
...king.Abstractions/Context/IIgnoreTracerContextListener.cs
+2
-27
ContextManager.cs
src/SkyWalking.Core/Context/ContextManager.cs
+13
-4
IgnoredTracerContext.cs
src/SkyWalking.Core/Context/IgnoredTracerContext.cs
+27
-0
TracingContext.cs
src/SkyWalking.Core/Context/TracingContext.cs
+28
-0
No files found.
src/SkyWalking.
Core/Context/ListenerManag
er.cs
→
src/SkyWalking.
Abstractions/Context/IIgnoreTracerContextListen
er.cs
View file @
b4484e5d
...
...
@@ -16,35 +16,10 @@
*
*/
using
System.Collections.Generic
;
using
System.Runtime.CompilerServices
;
using
SkyWalking.Context.Trace
;
namespace
SkyWalking.Context
{
public
static
class
ListenerManag
er
public
interface
IIgnoreTracerContextListen
er
{
private
static
readonly
IList
<
ITracingContextListener
>
_listeners
=
new
List
<
ITracingContextListener
>();
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Add
(
ITracingContextListener
listener
)
{
_listeners
.
Add
(
listener
);
}
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Remove
(
ITracingContextListener
listener
)
{
_listeners
.
Remove
(
listener
);
}
public
static
void
NotifyFinish
(
ITraceSegment
traceSegment
)
{
foreach
(
var
listener
in
_listeners
)
{
listener
.
AfterFinished
(
traceSegment
);
}
}
void
AfterFinish
(
ITracerContext
tracerContext
);
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/ContextManager.cs
View file @
b4484e5d
...
...
@@ -31,13 +31,14 @@ namespace SkyWalking.Context
/// We also provide the CONTEXT propagation based on ThreadLocal mechanism.
/// Meaning, each segment also related to singe thread.
/// </summary>
public
class
ContextManager
:
ITracingContextListener
,
IBootService
public
class
ContextManager
:
ITracingContextListener
,
IBootService
,
IIgnoreTracerContextListener
{
private
static
readonly
ThreadLocal
<
ITracerContext
>
_context
=
new
ThreadLocal
<
ITracerContext
>();
private
static
ITracerContext
GetOrCreateContext
(
String
operationName
,
bool
forceSampling
)
{
if
(!
_context
.
IsValueCreated
)
var
context
=
_context
.
Value
;
if
(
context
==
null
)
{
if
(
string
.
IsNullOrEmpty
(
operationName
))
{
...
...
@@ -84,7 +85,7 @@ namespace SkyWalking.Context
{
get
{
if
(
_context
.
IsValueCreated
)
if
(
_context
.
Value
!=
null
)
{
return
_context
.
Value
.
GetReadableGlobalTraceId
();
}
...
...
@@ -98,11 +99,13 @@ namespace SkyWalking.Context
public
static
ISpan
CreateEntrySpan
(
string
operationName
,
IContextCarrier
carrier
)
{
//todo samplingService
return
null
;
}
public
void
AfterFinished
(
ITraceSegment
traceSegment
)
{
_context
.
Value
=
null
;
}
public
void
Dispose
()
...
...
@@ -111,7 +114,13 @@ namespace SkyWalking.Context
public
void
Init
()
{
throw
new
NotImplementedException
();
TracingContext
.
ListenerManager
.
Add
(
this
);
IgnoredTracerContext
.
ListenerManager
.
Add
(
this
);
}
public
void
AfterFinish
(
ITracerContext
tracerContext
)
{
_context
.
Value
=
null
;
}
}
}
src/SkyWalking.Core/Context/IgnoredTracerContext.cs
View file @
b4484e5d
...
...
@@ -17,6 +17,8 @@
*/
using
System.Collections.Generic
;
using
System.Runtime.CompilerServices
;
using
SkyWalking.Context.Trace
;
namespace
SkyWalking.Context
...
...
@@ -71,5 +73,30 @@ namespace SkyWalking.Context
{
_stackDepth
--;
}
public
static
class
ListenerManager
{
private
static
readonly
List
<
IIgnoreTracerContextListener
>
_listeners
=
new
List
<
IIgnoreTracerContextListener
>();
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Add
(
IIgnoreTracerContextListener
listener
)
{
_listeners
.
Add
(
listener
);
}
public
static
void
NotifyFinish
(
ITracerContext
tracerContext
)
{
foreach
(
var
listener
in
_listeners
)
{
listener
.
AfterFinish
(
tracerContext
);
}
}
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Remove
(
IIgnoreTracerContextListener
listener
)
{
_listeners
.
Remove
(
listener
);
}
}
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/TracingContext.cs
View file @
b4484e5d
...
...
@@ -19,6 +19,7 @@
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Runtime.CompilerServices
;
using
SkyWalking.Boot
;
using
SkyWalking.Context.Trace
;
using
SkyWalking.Dictionarys
;
...
...
@@ -380,5 +381,32 @@ namespace SkyWalking.Context
return
true
;
}
public
static
class
ListenerManager
{
private
static
readonly
IList
<
ITracingContextListener
>
_listeners
=
new
List
<
ITracingContextListener
>();
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Add
(
ITracingContextListener
listener
)
{
_listeners
.
Add
(
listener
);
}
[
MethodImpl
(
MethodImplOptions
.
Synchronized
)]
public
static
void
Remove
(
ITracingContextListener
listener
)
{
_listeners
.
Remove
(
listener
);
}
public
static
void
NotifyFinish
(
ITraceSegment
traceSegment
)
{
foreach
(
var
listener
in
_listeners
)
{
listener
.
AfterFinished
(
traceSegment
);
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment