Commit 546931b1 authored by Liuhaoyang's avatar Liuhaoyang

Add ListenerManager

parent b6ef70c8
...@@ -16,13 +16,12 @@ ...@@ -16,13 +16,12 @@
* *
*/ */
using System; using SkyWalking.Context.Trace;
using System.Collections.Generic;
using System.Text;
namespace SkyWalking.Context namespace SkyWalking.Context
{ {
interface ITracingContextListener public interface ITracingContextListener
{ {
void AfterFinished(ITraceSegment traceSegment);
} }
} }
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using SkyWalking.Context.Trace;
namespace SkyWalking.Context
{
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
...@@ -16,16 +16,28 @@ ...@@ -16,16 +16,28 @@
* *
*/ */
using System.Collections;
using System.Collections.Generic;
using SkyWalking.Context.Trace; using SkyWalking.Context.Trace;
using SkyWalking.Sampling;
namespace SkyWalking.Context namespace SkyWalking.Context
{ {
public class TracingContext: ITracerContext public class TracingContext: ITracerContext
{ {
private long _lastWarningTimestamp = 0; private long _lastWarningTimestamp = 0;
private ISampler _sampler;
private ITraceSegment _segment;
private Stack<ISpan> _activeSpanStacks;
private int _spanIdGenerator;
public TracingContext()
{
_sampler = new SamplingService();
_segment = new TraceSegment();
_activeSpanStacks = new Stack<ISpan>();
}
public void Inject(IContextCarrier carrier) public void Inject(IContextCarrier carrier)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
......
using System.Threading.Tasks; /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Threading.Tasks;
namespace SkyWalking.Sampling namespace SkyWalking.Sampling
{ {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System.Collections.Generic;
namespace SkyWalking.Utils
{
public static class StackExtensions
{
public static bool TryPeek<T>(this Stack<T> stack, out T value)
{
if (stack == null || stack.Count == 0)
{
value = default(T);
return false;
}
value = stack.Peek();
return true;
}
public static bool TryPop<T>(this Stack<T> stack, out T value)
{
if (stack == null || stack.Count == 0)
{
value = default(T);
return false;
}
value = stack.Pop();
return true;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment