-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9575] Refactor DefaultTrace.close()
- Loading branch information
Showing
7 changed files
with
84 additions
and
66 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
12 changes: 12 additions & 0 deletions
12
profiler/src/main/java/com/navercorp/pinpoint/profiler/context/CloseListener.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,12 @@ | ||
package com.navercorp.pinpoint.profiler.context; | ||
|
||
public interface CloseListener { | ||
void close(Span span); | ||
|
||
CloseListener EMPTY = new CloseListener() { | ||
@Override | ||
public void close(Span span) { | ||
} | ||
}; | ||
|
||
} |
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
57 changes: 57 additions & 0 deletions
57
profiler/src/main/java/com/navercorp/pinpoint/profiler/context/DefaultCloseListener.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,57 @@ | ||
package com.navercorp.pinpoint.profiler.context; | ||
|
||
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle; | ||
import com.navercorp.pinpoint.profiler.context.id.Shared; | ||
import com.navercorp.pinpoint.profiler.context.id.TraceRoot; | ||
import com.navercorp.pinpoint.profiler.context.storage.UriStatStorage; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class DefaultCloseListener implements CloseListener { | ||
|
||
@Nullable | ||
private final ActiveTraceHandle activeTraceHandle; | ||
@Nullable | ||
private final UriStatStorage uriStatStorage; | ||
|
||
public DefaultCloseListener(ActiveTraceHandle activeTraceHandle, UriStatStorage uriStatStorage) { | ||
this.activeTraceHandle = activeTraceHandle; | ||
this.uriStatStorage = uriStatStorage; | ||
} | ||
|
||
@Override | ||
public void close(Span span) { | ||
final long end = span.getStartTime() + span.getElapsedTime(); | ||
recordUriTemplate(span, end); | ||
purgeActiveTrace(end); | ||
} | ||
|
||
|
||
private void recordUriTemplate(Span span, long afterTime) { | ||
if (uriStatStorage == null) { | ||
return; | ||
} | ||
|
||
TraceRoot traceRoot = span.getTraceRoot(); | ||
Shared shared = traceRoot.getShared(); | ||
String uriTemplate = shared.getUriTemplate(); | ||
long traceStartTime = traceRoot.getTraceStartTime(); | ||
|
||
boolean status = getStatus(shared.getErrorCode()); | ||
uriStatStorage.store(uriTemplate, status, traceStartTime, afterTime); | ||
} | ||
|
||
private boolean getStatus(int errorCode) { | ||
if (errorCode == 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private void purgeActiveTrace(long currentTime) { | ||
final ActiveTraceHandle copy = this.activeTraceHandle; | ||
if (copy != null) { | ||
copy.purge(currentTime); | ||
} | ||
} | ||
} |
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