-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support auto transform SOFATracer Span in SOFA ThreadPool (#190)
Co-authored-by: “HzjNeverStop” <“441627022@qq.com”>
- Loading branch information
1 parent
e0ff800
commit 7841cae
Showing
14 changed files
with
416 additions
and
8 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
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
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
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
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
89 changes: 89 additions & 0 deletions
89
src/main/java/com/alipay/sofa/common/thread/SofaTracerCommandFactory.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,89 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package com.alipay.sofa.common.thread; | ||
|
||
import com.alipay.common.tracer.core.async.SofaTracerCallable; | ||
import com.alipay.common.tracer.core.async.SofaTracerRunnable; | ||
import com.alipay.sofa.common.utils.ClassUtil; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Factory to create SOFA-Tracer work command. | ||
* @author huzijie | ||
* @version SofaTracerCommandFactory.java, v 0.1 2023年09月26日 2:53 PM huzijie Exp $ | ||
*/ | ||
public class SofaTracerCommandFactory { | ||
|
||
private static final String SOFA_TRACER_RUNNABLE_CLASS_NAME = "com.alipay.common.tracer.core.async.SofaTracerRunnable"; | ||
private static final boolean SOFA_TRACER_CLASS_PRESENT = ClassUtil | ||
.isPresent( | ||
SOFA_TRACER_RUNNABLE_CLASS_NAME, | ||
SofaTracerCommandFactory.class | ||
.getClassLoader()); | ||
|
||
static ExecutingRunnable ofExecutingRunnable(Runnable runnable) { | ||
if (!SOFA_TRACER_CLASS_PRESENT) { | ||
return new ExecutingRunnable(runnable); | ||
} | ||
return new SofaTracerCommandFactory.SofaTracerExecutingRunnable(runnable); | ||
} | ||
|
||
static Runnable ofRunnable(Runnable runnable) { | ||
if (!SOFA_TRACER_CLASS_PRESENT) { | ||
return runnable; | ||
} | ||
if (runnable instanceof SofaTracerRunnable) { | ||
return runnable; | ||
} | ||
return new SofaTracerRunnable(runnable); | ||
} | ||
|
||
static <V> Callable<V> ofCallable(Callable<V> callable) { | ||
if (!SOFA_TRACER_CLASS_PRESENT) { | ||
return callable; | ||
} | ||
if (callable instanceof SofaTracerCallable) { | ||
return callable; | ||
} | ||
return new SofaTracerCallable<>(callable); | ||
} | ||
|
||
/** | ||
* The wrapper to the {@link ExecutingRunnable} to transmit SofaTracerSpan. | ||
* @author huzijie | ||
* @version SofaTracerExecutingRunnable.java, v 0.1 2023年09月26日 11:45 AM huzijie Exp $ | ||
*/ | ||
public static class SofaTracerExecutingRunnable extends ExecutingRunnable { | ||
|
||
private final SofaTracerRunnable sofaTracerRunnable; | ||
|
||
public SofaTracerExecutingRunnable(Runnable originRunnable) { | ||
super(originRunnable); | ||
if (originRunnable instanceof SofaTracerRunnable) { | ||
this.sofaTracerRunnable = (SofaTracerRunnable) originRunnable; | ||
} else { | ||
this.sofaTracerRunnable = new SofaTracerRunnable(originRunnable); | ||
} | ||
} | ||
|
||
@Override | ||
public void run() { | ||
sofaTracerRunnable.run(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.