Skip to content
This repository was archived by the owner on Aug 17, 2018. It is now read-only.

Commit da828fc

Browse files
author
Jan Luehe
committed
Incremental fix for https://glassfish.dev.java.net/issues/show_bug.cgi?id=10629 ("some monitoring statistics in v2 are not in v3"): Added probes for jsp error and reload events
Tests run: QL svn path=/trunk/; revision=1192
1 parent 8b39f3c commit da828fc

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

impl/src/main/java/org/apache/jasper/compiler/JspRuntimeContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import java.util.Iterator;
7474
import java.util.Map;
7575
import java.util.concurrent.ConcurrentHashMap;
76+
import java.util.concurrent.atomic.*;
7677
import java.util.logging.Logger;
7778
import java.util.logging.Level;
7879

@@ -110,7 +111,7 @@ public final class JspRuntimeContext implements Runnable {
110111
/*
111112
* Counts how many times the webapp's JSPs have been reloaded.
112113
*/
113-
private int jspReloadCount;
114+
private AtomicInteger jspReloadCount = new AtomicInteger(0);
114115

115116
/**
116117
* Preload classes required at runtime by a JSP servlet so that
@@ -353,17 +354,17 @@ public void destroy() {
353354
/**
354355
* Increments the JSP reload counter.
355356
*/
356-
public synchronized void incrementJspReloadCount() {
357-
jspReloadCount++;
357+
public void incrementJspReloadCount() {
358+
jspReloadCount.incrementAndGet();
358359
}
359360

360361
/**
361362
* Resets the JSP reload counter.
362363
*
363364
* @param count Value to which to reset the JSP reload counter
364365
*/
365-
public synchronized void setJspReloadCount(int count) {
366-
this.jspReloadCount = count;
366+
public void setJspReloadCount(int count) {
367+
jspReloadCount.set(count);
367368
}
368369

369370
/**
@@ -372,7 +373,7 @@ public synchronized void setJspReloadCount(int count) {
372373
* @return The current value of the JSP reload counter
373374
*/
374375
public int getJspReloadCount() {
375-
return jspReloadCount;
376+
return jspReloadCount.get();
376377
}
377378

378379
/**

impl/src/main/java/org/apache/jasper/servlet/JspServlet.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.net.URL;
6767
import java.util.concurrent.ConcurrentHashMap;
6868
// END GlassFish 750
69+
import java.util.concurrent.atomic.*;
6970
// START SJSWS 6232180
7071
import java.util.HashSet;
7172
import java.util.StringTokenizer;
@@ -93,6 +94,7 @@
9394
import org.apache.jasper.compiler.JspUtil;
9495
import org.apache.jasper.compiler.Localizer;
9596
import org.apache.jasper.runtime.JspApplicationContextImpl;
97+
import org.glassfish.jsp.api.JspProbeEmitter;
9698
import org.glassfish.jsp.api.ResourceInjector;
9799

98100
/**
@@ -123,8 +125,7 @@ public class JspServlet extends HttpServlet {
123125

124126
// START S1AS
125127
// jsp error count
126-
private int countErrors;
127-
private Object errorCountLk = new Object();
128+
private AtomicInteger countErrors = new AtomicInteger(0);
128129
// END S1AS
129130

130131
// START SJSWS 6232180
@@ -137,6 +138,8 @@ public class JspServlet extends HttpServlet {
137138
private ConcurrentHashMap<String, URL> tagFileJarUrls;
138139
// END GlassFish 750
139140

141+
private JspProbeEmitter jspProbeEmitter;
142+
140143
/*
141144
* Initializes this JspServlet.
142145
*/
@@ -178,6 +181,10 @@ public void init(ServletConfig config) throws ServletException {
178181
options.getScratchDir().toString()));
179182
log.finest(Localizer.getMessage("jsp.message.dont.modify.servlets"));
180183
}
184+
185+
this.jspProbeEmitter = (JspProbeEmitter)
186+
config.getServletContext().getAttribute(
187+
"org.glassfish.jsp.monitor.probeEmitter");
181188
}
182189

183190

@@ -226,7 +233,7 @@ public int getJspReloadCount() {
226233
* @return The number of errors triggered by JSP invocations
227234
*/
228235
public int getJspErrorCount() {
229-
return this.countErrors;
236+
return countErrors.get();
230237
}
231238
// END S1AS
232239

@@ -289,8 +296,8 @@ boolean preCompile(HttpServletRequest request) throws ServletException {
289296
}
290297

291298

292-
public void service (HttpServletRequest request,
293-
HttpServletResponse response)
299+
public void service(HttpServletRequest request,
300+
HttpServletResponse response)
294301
throws ServletException, IOException {
295302

296303
// START SJSWS 6232180
@@ -480,8 +487,10 @@ private void serviceJspFile(HttpServletRequest request,
480487

481488
// STARTS S1AS
482489
private void incrementErrorCount() {
483-
synchronized (errorCountLk) {
484-
countErrors++;
490+
countErrors.incrementAndGet();
491+
// Fire the jspErrorEvent probe event
492+
if (jspProbeEmitter != null) {
493+
jspProbeEmitter.jspErrorEvent();
485494
}
486495
}
487496
// END S1AS

impl/src/main/java/org/apache/jasper/servlet/JspServletWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ public Servlet getServlet()
209209

210210
if (!firstTime) {
211211
ctxt.getRuntimeContext().incrementJspReloadCount();
212+
// Fire the jspReloadedEvent probe event
213+
if (jspProbeEmitter != null) {
214+
jspProbeEmitter.jspReloadedEvent(theServlet);
215+
}
212216
}
213217

214218
reload = false;
@@ -218,7 +222,7 @@ public Servlet getServlet()
218222
jspProbeEmitter.jspLoadedEvent(theServlet);
219223
}
220224
}
221-
}
225+
}
222226
}
223227
return theServlet;
224228
}

impl/src/main/java/org/glassfish/jsp/api/JspProbeEmitter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public interface JspProbeEmitter {
4949

5050
public void jspLoadedEvent(Servlet jspServlet);
5151

52+
public void jspReloadedEvent(Servlet jspServlet);
53+
5254
public void jspDestroyedEvent(Servlet jspServlet);
55+
56+
public void jspErrorEvent();
5357
}
5458

0 commit comments

Comments
 (0)