<%@ page import = "com.cyscape.browserhawk.*" %>
<%

	 // This sample is provided under the terms of the BrowserHawk End User
	 // License Agreement.  Copyright (c) 2003-2011 cyScape, Inc. All rights
	 // reserved.

   // This sample builds on speed.jsp and adds Page Load Time (PLT) detection.
   // For more information on PLT see http://cyscape.com/plt

   // The important parts of the file are the PLTOptions construction and
   // the pltHead() call in the page's head block that uses the PLTOptions
   // instance.  Also the PLTOptions instance is passed to the 
   // getExtendedBrowserInfo() call to instrument the test page.

   // Also there are <span> elements in the page with special id values
   // into which the timing results are dynamically placed after the
   // page finishes loading, in case you want to show times somewhere
   // in the page in addition to recording them in the BRWS system.

   // To avoid an exception, we check that the system executing this
   // example has a Professional or Enterprise Edition license as required
   // for this test.
   // Note: This is NOT needed in your pages, only for this sample.
   if (BrowserHawk.getVersion().indexOf("Pro") == -1 &&
       BrowserHawk.getVersion().indexOf("Ent") == -1) {
     out.println("Professional or Enterprise License Required.  ");
    out.println("You are using " + BrowserHawk.getVersion() + ".  ");
     out.println("See <a href='http://www.cyscape.com/order/'>http://www.cyscape.com/order/</a> for upgrade information.");
     return;
   }

   // Let's control how we want PLT to behave
   PLTOptions pltOptions = new PLTOptions();
   // There are many settings to control, here's a note on the session cookie
   pltOptions.setSessionIDCookieName("JSESSIONID");
   // You need to change this to point at your own BRWS service
   pltOptions.setBrwsURL("/reports/brws");

   ExtendedOptions options = new ExtendedOptions();
   options.setPageTitle("Please wait...");
   options.setPageMessage("Please wait while your connection speed is detected...");
   options.addProperties("ConnectionSpeed");

   // Note the passing of pltOptions here!
   ExtendedBrowserInfo extBrowser =
     BrowserHawk.getExtendedBrowserInfo(request, response, options, pltOptions);

   if (extBrowser == null) return;
%>

<html>
	<head>
		<title>BrowserHawk Sample - Detect Connection Speed (Java)</title>
    <%=
      // This call must go in the head block for PLT to function
      BrowserHawk.pltHead(request, pltOptions)
    %>
	</head>
	<body><font face="arial">
	<blockquote>

  PLT says your request type was <b><span id="plt_hittype">hittype here</span></b>.
  It took <b><span id="plt_total">total here</span></b> seconds total to load this
  page of which <b><span id="plt_intra">intra here</span></b> seconds was spend 
  rendering the page.

  <p>

	Your connection speed is: 
  <%= extBrowser.getConnectionSpeed() %> <P>

	Connection speed for display purposes: 
  <%=
    // The Translate method is a convenient way to display the speed in
    // bits/sec and kbytes per seocnd to end users so we demonstrate that here.
    extBrowser.translate("ConnectionSpeed")
   %> <P>

	<% if (extBrowser.getConnectionSpeed() == 0) { %>
		Why is the result 0? The connection speed test is designed to detect 
    speeds generally T3 and lower.  Therefore if testing on a local machine,
    LAN, or WAN you may receive a return result of 0 which indicates that a
    valid reading was not available. The best way to test this sample is 
    over an internet connection such as cable modem, DSL, other broadband
    connections, or dial up.
	<% } %>

<%

// Although this script does not demonstrate it, below is an example of 
// how you would get the result and do something with it.  For example, 
// assume you wanted to handle dial up and broadband users differently.
// To get the speed in bits per second just check the connectionspeed 
// property like this:
//    speed = extBrowser.getConnectionSpeed();
// If you want to calculate kbytes per second use this formula:
//    kbytesPerSec = speed / 8 / 1024;

// If you wanted to redirect users with slow connections here's how you can
// do it - in this example we redirect anyone slower than 128 kbits per 
// second to a more basic page
//   if (speed > 0 && speed < 131000) {
//      response.sendRedirect("/basicpage.jsp");
//   else if (speed < 1)
//      response.sendRedirect("/detection_na.jsp");
//   else
//      response.sendRedirect("/highspeed.jsp");
//   }
// (The speed may be equal to 0 in the event that you are testing over a 
// local LAN/WAN since the speed is too fast to measure accurately in that 
// case.)
%>
<p>
Note: The ConnectionSpeed property should be used when you want to know the
vistor's actual connection speed, such as the case if you are estimating a
download time.  If you mainly just want to detect broadband vs. dial-up users,
the Broadband property is better suited for that purpose.  See the topic
"Detecting Connection Speeds and Dialup Users" in the BrowserHawk
documentation for more information. Also see the 
<a href="broadband.jsp">broadband sample</a>.

<P>
<HR>
<P>
<b><a href="plt-speed.jsp">Retry this test</a></b><P>
<b><a href="index.html">Return to list of other JSP samples</a></b><P>
<b><a href="http://www.cyscape.com/order/">BrowserHawk Pricing and Ordering</a></b><P>
<b><a href="http://www.cyscape.com/">cyScape home page</a></b><P>
</font></blockquote>
</body>
</html>
