forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#7654] Async support SDK
- Loading branch information
1 parent
b8279cb
commit 1dbaf31
Showing
22 changed files
with
1,074 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>pinpoint</artifactId> | ||
<groupId>com.navercorp.pinpoint</groupId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>pinpoint-java-sdk</artifactId> | ||
|
||
<name>pinpoint-java-sdk</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
pinpoint-java-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/concurrent/TraceCallable.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,40 @@ | ||
/* | ||
* Copyright 2021 NAVER Corp. | ||
* | ||
* Licensed 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.navercorp.pinpoint.sdk.v1.concurrent; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
public class TraceCallable<V> implements Callable<V> { | ||
|
||
public static <V> Callable<V> wrap(Callable<V> delegate) { | ||
return new TraceCallable<V>(delegate); | ||
} | ||
|
||
private final Callable<V> delegate; | ||
|
||
public TraceCallable(Callable<V> callable) { | ||
if (callable == null) { | ||
throw new NullPointerException("callable"); | ||
} | ||
this.delegate = callable; | ||
} | ||
|
||
@Override | ||
public V call() throws Exception { | ||
return delegate.call(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
pinpoint-java-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/concurrent/TraceExecutor.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,44 @@ | ||
/* | ||
* Copyright 2021 NAVER Corp. | ||
* | ||
* Licensed 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.navercorp.pinpoint.sdk.v1.concurrent; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
public class TraceExecutor implements Executor { | ||
private final Executor delegate; | ||
|
||
public TraceExecutor(Executor delegate) { | ||
if (delegate == null) { | ||
throw new NullPointerException("delegate"); | ||
} | ||
this.delegate = delegate; | ||
} | ||
|
||
protected Runnable wrap(Runnable command) { | ||
if (command instanceof TraceRunnable) { | ||
return command; | ||
} | ||
return new TraceRunnable(command); | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
Runnable wrapCommand = wrap(command); | ||
delegate.execute(wrapCommand); | ||
} | ||
|
||
} |
135 changes: 135 additions & 0 deletions
135
...java-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/concurrent/TraceExecutorService.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,135 @@ | ||
/* | ||
* Copyright 2021 NAVER Corp. | ||
* | ||
* Licensed 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.navercorp.pinpoint.sdk.v1.concurrent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class TraceExecutorService implements ExecutorService { | ||
private final ExecutorService delegate; | ||
|
||
public TraceExecutorService(ExecutorService delegate) { | ||
if (delegate == null) { | ||
throw new NullPointerException("delegate"); | ||
} | ||
this.delegate = delegate; | ||
} | ||
|
||
protected Runnable wrap(Runnable command) { | ||
if (command instanceof TraceRunnable) { | ||
return command; | ||
} | ||
return new TraceRunnable(command); | ||
} | ||
|
||
protected <T> Callable<T> wrap(Callable<T> callable) { | ||
if (callable instanceof TraceCallable) { | ||
return callable; | ||
} | ||
return new TraceCallable<T>(callable); | ||
} | ||
|
||
protected <T> Collection<? extends Callable<T>> wrap(Collection<? extends Callable<T>> tasks) { | ||
final List<Callable<T>> wrapList = new ArrayList<>(); | ||
for (Callable<T> task : tasks) { | ||
Callable<T> wrapTask = wrap(task); | ||
wrapList.add(wrapTask); | ||
} | ||
return wrapList; | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
delegate.shutdown(); | ||
} | ||
|
||
@Override | ||
public List<Runnable> shutdownNow() { | ||
return delegate.shutdownNow(); | ||
} | ||
|
||
@Override | ||
public boolean isShutdown() { | ||
return delegate.isShutdown(); | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
return delegate.isTerminated(); | ||
} | ||
|
||
@Override | ||
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { | ||
return delegate.awaitTermination(timeout, unit); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Callable<T> task) { | ||
Callable<T> wrapCallable = wrap(task); | ||
return delegate.submit(wrapCallable); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Runnable task, T result) { | ||
Runnable wrapTask = wrap(task); | ||
return delegate.submit(wrapTask, result); | ||
} | ||
|
||
@Override | ||
public Future<?> submit(Runnable task) { | ||
Runnable wrap = wrap(task); | ||
return delegate.submit(wrap); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { | ||
Collection<? extends Callable<T>> wrap = wrap(tasks); | ||
return delegate.invokeAll(wrap); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException { | ||
Collection<? extends Callable<T>> wrap = wrap(tasks); | ||
return delegate.invokeAll(wrap, timeout, unit); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { | ||
Collection<? extends Callable<T>> wrap = wrap(tasks); | ||
return delegate.invokeAny(wrap); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | ||
Collection<? extends Callable<T>> wrap = wrap(tasks); | ||
return delegate.invokeAny(wrap, timeout, unit); | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
Runnable wrap = wrap(command); | ||
delegate.execute(wrap); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
pinpoint-java-sdk/src/main/java/com/navercorp/pinpoint/sdk/v1/concurrent/TraceExecutors.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,39 @@ | ||
/* | ||
* Copyright 2021 NAVER Corp. | ||
* | ||
* Licensed 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.navercorp.pinpoint.sdk.v1.concurrent; | ||
|
||
import java.util.concurrent.Executor; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
public class TraceExecutors { | ||
|
||
public static Executor wrapExecutor(Executor executor) { | ||
return new TraceExecutor(executor); | ||
} | ||
|
||
public static ExecutorService wrapExecutorService(ExecutorService executorService) { | ||
return new TraceExecutorService(executorService); | ||
} | ||
|
||
|
||
public static ScheduledExecutorService wrapScheduledExecutorService(ScheduledExecutorService executorService) { | ||
return new TraceScheduledExecutorService(executorService); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.