-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trace Stapler request processing #148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,13 @@ | |
|
||
package org.kohsuke.stapler; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.io.PrintWriter; | ||
import java.util.ServiceLoader; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import static org.kohsuke.stapler.Stapler.escape; | ||
|
||
|
@@ -38,6 +42,8 @@ | |
public class EvaluationTrace { | ||
private final List<String> traces = new ArrayList<String>(); | ||
|
||
private static final Logger LOGGER = Logger.getLogger(EvaluationTrace.class.getName()); | ||
|
||
public void trace(StaplerResponse rsp, String msg) { | ||
traces.add(msg); | ||
// Firefox Live HTTP header plugin cannot nicely render multiple headers | ||
|
@@ -61,4 +67,38 @@ public static EvaluationTrace get(StaplerRequest req) { | |
* Used for counting trace header. | ||
*/ | ||
private static final String KEY = EvaluationTrace.class.getName(); | ||
|
||
public abstract static class ApplicationTracer { | ||
protected abstract void record(StaplerRequest req, String message); | ||
|
||
public static void trace(StaplerRequest req, String message) { | ||
List<ApplicationTracer> tracers = getTracers(); | ||
for (ApplicationTracer tracer : tracers) { | ||
tracer.record(req, message); | ||
} | ||
} | ||
|
||
private static volatile List<ApplicationTracer> tracers; | ||
|
||
@Nonnull | ||
private static List<ApplicationTracer> getTracers() { | ||
synchronized (ApplicationTracer.class) { | ||
if (tracers == null) { | ||
List<ApplicationTracer> t = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not need a separate variable. You can initialize |
||
for (ApplicationTracer tracer : ServiceLoader.load(EvaluationTrace.ApplicationTracer.class, Stapler.getCurrent().getWebApp().getClassLoader())) { | ||
try { | ||
t.add(tracer); | ||
} catch (Exception e) { | ||
// robustness | ||
if (LOGGER.isLoggable(Level.FINE)) { | ||
LOGGER.log(Level.FINE, "Exception thrown when notifying tracer", e); | ||
} | ||
} | ||
} | ||
tracers = t; | ||
} | ||
} | ||
return tracers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be inside the |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointless for this to be
volatile
, since you have thesynchronized
block.