<%-----------------------------------------------------------
   Copyright © 1999, Oracle Corporation. All rights reserved.
------------------------------------------------------------%>

<event:application_OnStart>
	<%-- Initializes counts to zero --%>
	<jsp:useBean id="pageCount" class="oracle.jsp.jml.JmlNumber" scope = "application" />
	<jsp:useBean id="sessionCount" class="oracle.jsp.jml.JmlNumber" scope = "application" />
	<jsp:useBean id="activeSessions" class="oracle.jsp.jml.JmlNumber" scope = "application" />

	<%-- Consider storing pageCount persistently -- If you do read it here --%>
</event:application_OnStart>

<event:application_OnEnd>
	<%-- Acquire beans --%>
	<jsp:useBean id="pageCount" class="oracle.jsp.jml.JmlNumber" scope = "application" />
	<jsp:useBean id="sessionCount" class="oracle.jsp.jml.JmlNumber" scope = "application" />

	<% application.log("The number of page hits were: " + pageCount.getValue() ); %>
	<% application.log("The number of client sessions were: " + sessionCount.getValue() ); %>

	<%-- Consider storing pageCount persistently -- If you do write it here --%>
</event:application_OnEnd>

<event:session_OnStart>
	<%-- Acquire beans --%>
	<jsp:useBean id="sessionCount" class="oracle.jsp.jml.JmlNumber" scope = "application" />
	<jsp:useBean id="activeSessions" class="oracle.jsp.jml.JmlNumber" scope = "application" />


	<%
	synchronized (sessionCount) {
		sessionCount.setValue(sessionCount.getValue() + 1);
      %>

		<br>
		Starting session #: <%= sessionCount.getValue() %> <br>

	<%
	}
	%>

	<% 
	synchronized (activeSessions) {
		activeSessions.setValue(activeSessions.getValue() + 1);
	%>
		There are currently <b> <%= activeSessions.getValue() %> </b> active sessions <p>
	<%
	}
	%>
</event:session_OnStart>


<event:session_OnEnd>
	<%-- Acquire beans --%>
	<jsp:useBean id="activeSessions" class="oracle.jsp.jml.JmlNumber" scope = "application" />

	<%
	 synchronized (activeSessions) {
		activeSessions.setValue(activeSessions.getValue() - 1);
	}
	%>
</event:session_OnEnd>
