Archive for April, 2007

120 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Recall (Adelphia web hosting)

Friday, April 20th, 2007

120 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Recall from the previous example that the XML library employed to build XML documents is JDOM, which is available at www.jdom.org. The jdom.jar and xerces.jarfiles need to be packaged in the WAR file in the WEB-INF/lib folder. You can access the instrumentation command interface through the following URL: http://localhost:8080/instrument/instrument Note The URL http://localhost:8080/instrument/instrument is valid for Apache Tomcat and JBoss. If you are using another application server or if you changed the listening ports, then you will need to adjust that accordingly. WebLogic listens by default on port 7001, and WebSphere listens by default on port 9080. Start the instrumentation by clicking the Start Instrumentation link. Then you can exercise the test application through the following URL: http://localhost:8080/instrument/test When you are finished, click the Stop Instrumentation link and then select Get Report. In my example, doing so yielded the following output:
Note: If you are looking for reliable webhost to maintain and run your java application check Vision java hosting services

Web server extensions - CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing 4-15.

Thursday, April 19th, 2007

CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing 4-15. web.xml InstrumentorServlet com.javasrc.instrument.web.InstrumentorServlet TestServlet com.javasrc.instrument.test.TestServlet InstrumentorServlet /instrument/* TestServlet /test/* And finally, to deploy the instrumentor application to your application server, you need to construct a WAR file with the following files: instrument.jsp WEB-INF/classes/com/javasrc/instrument/Instrumentor.class WEB-INF/classes/com/javasrc/instrument/MethodInfo.class WEB-INF/classes/com/javasrc/instrument/RequestInfo.class WEB-INF/classes/com/javasrc/instrument/test/Controller.class WEB-INF/classes/com/javasrc/instrument/test/authentication/Authentication.class WEB-INF/classes/com/javasrc/instrument/test/handlers/ WEB-INF/classes/com/javasrc/instrument/test/handlers/BusinessProcess.class WEB-INF/classes/com/javasrc/instrument/test/TestServlet.class WEB-INF/classes/com/javasrc/instrument/web/InstrumentorServlet.class WEB-INF/lib/jdom.jar WEB-INF/lib/xerces.jar WEB-INF/web.xml
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

118 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS This (Web site design)

Thursday, April 19th, 2007

118 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS

This interface allows you to control the embedded instrumentation engine
Options:
Start Instrumentation
Stop Instrumentation
Get Report

<%String instrumentationStatus = ( String )request.getAttribute( "instrumentation-status" );%>

Instrumentation: <%=instrumentationStatus%>

Status

  <%String status = ( String )request.getAttribute( "status" );%>  <%=status%>  

The InstrumentorServlet presents three commands: start: Start instrumentation. stop: Stop instrumentation. report: Generate a report in XML that shows all requests, response times, and call traces. The start command calls the Instrumentor s start() method, the stop command calls the Instrumentor s stop()method, and the report command calls the Instrumentor s toXML() method. The Instrumentor s toXML() method extracts all RequestInfo instances from its request map and asks them to generate an XML report containing all method traces. To enable these servlets, you need to build a Web deployment descriptor, as shown in Listing 4-15.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services

Hosting web - CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS else {

Thursday, April 19th, 2007

CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS else { req.setAttribute( “instrumentation-status”, instrumentationStatus ); req.setAttribute( “status”, status ); RequestDispatcher rd = req.getRequestDispatcher( “instrument.jsp” ); rd.forward( req, res ); } } catch( Exception e ) { e.printStackTrace(); throw new ServletException( e ); } } private String xmlToHtml( String xml ) { StringBuffer sb = new StringBuffer( xml ); int index = sb.indexOf( “<" ); while( index != -1 ) { sb.replace( index, index+1, "<" ); index = sb.indexOf( "<", index + 3 ); } index = sb.indexOf( ">” ); while( index != -1 ) { sb.replace( index, index+1, “>” ); index = sb.indexOf( “>”, index + 3 ); } return sb.toString(); } } The code for the instrument.jsp file is shown in Listing 4-14. Listing 4-14. instrument.jsp <%@page import="java.io.*" %>

Instrumentation Management Interface

Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services

Best web design - 116 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS else

Wednesday, April 18th, 2007

116 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS else { // Convert the output of the report to an XML string XMLOutputter outputter = new XMLOutputter( “t”, true ); status = outputter.outputString( Instrumentor.toXML() ); if( !xml ) { status = xmlToHtml( status ); } } } else if( command.equalsIgnoreCase( “start” ) ) { Instrumentor.start(); status = “Instrumentor started”; if( xml ) { status = “” + status + ““; } } else if( command.equalsIgnoreCase( “stop” ) ) { Instrumentor.stop(); status = “Instrumentor stopped”; if( xml ) { status = “” + status + ““; } } // Update the instrumentation status String instrumentationStatus = “Not Running”; if( Instrumentor.isInstrumenting() ) { instrumentationStatus = “Running”; } if( xml ) { PrintWriter out = res.getWriter(); out.println( status ); out.flush(); }
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision make web site services

Free web servers - CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing 4-13.

Wednesday, April 18th, 2007

CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing 4-13. InstrumentorServlet.java package com.javasrc.instrument.web; // Import servlet classes import javax.servlet.*; import javax.servlet.http.*; // Import Java classes import java.util.*; import java.io.*; // Import JDOM classes import org.jdom.*; import org.jdom.output.*; // Import instrument class import com.javasrc.instrument.Instrumentor; public class InstrumentorServlet extends HttpServlet { public void service( HttpServletRequest req, HttpServletResponse res ) throws ServletException { try { // The command controls the action of this servlet String command = req.getParameter( “cmd” ); if( command == null ) command = “none”; // The format controls the return format: HTML or XML String format = req.getParameter( “format” ); if( format == null ) format = “html”; boolean xml = format.equalsIgnoreCase( “xml” ); String status = “Please make a selection”; if( command.equalsIgnoreCase( “report” ) ) { if( Instrumentor.isInstrumenting() ) { status = “Instrumentation is running, cannot generate a report. until you stop instrumentation”; }
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Apache web server for windows - 114 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Figure

Tuesday, April 17th, 2007

114 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Figure 4-6 illustrates the architecture of this simple Web application. Figure 4-6. The browser sends a request to the TestServlet that calls internal methods and forwards them to the Controller for processing. This test application is simple, but it demonstrates how the instrumentation engine works. Observe the sequence of events in the TestServlet: it generates a unique identifier, starts the request, and starts the service() method. And note how each instrumented method must provide an additional attribute to support the unique identifier and invoke startMethod() and endMethod() at the beginning and end of the method, respectively. It is intrusive to the development process, but it is capable of tracing requests within a single JVM. As soon as you leave a single JVM, you need to define a central repository for the instrumentor and re-create the request across the network, which presents an additional level of complexity to the instrumentation task. Instrumentation Command Interface The final task we need to perform to complete this example is build a command interface to start and stop instrumentation and generate a report. In this implementation, we build an instrumentation servlet and a JSP to present the command interface. The code for the InstrumentorServlet is shown in Listing 4-13.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

CHAPTER 4 (Yahoo web space) IMPLEMENTING PERFORMANCE MEASUREMENTS public boolean

Tuesday, April 17th, 2007

CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS public boolean isValidUser( String iid, String username ) { Instrumentor.startMethod( iid, “com.javasrc.instrument.test. authentication.Authentication.isValidUser()” ); try { // Business logic try { Thread.sleep( 200 ); } catch( Exception e ) { } return true; } finally { Instrumentor.endMethod( iid ); } } } Listing 4-12. BusinessProcess.java package com.javasrc.instrument.test.handlers; import com.javasrc.instrument.Instrumentor; public class BusinessProcess { public void execute( String iid ) { Instrumentor.startMethod( iid, “com.javasrc.instrument.test.. handlers.BusinessProcess.execute()” ); // Business logic try { Thread.sleep( 300 ); } catch( Exception e ) { } Instrumentor.endMethod( iid ); } }
Note: If you are looking for high quality webhost to host and run your jsp application check Vision christian web host services

112 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing (Best web design)

Monday, April 16th, 2007

112 CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS Listing 4-10. Controller.java package com.javasrc.instrument.test; import com.javasrc.instrument.Instrumentor; import com.javasrc.instrument.test.handlers.*; import com.javasrc.instrument.test.authentication.*; public class Controller { private BusinessProcess bp = new BusinessProcess(); private Authentication auth = new Authentication(); public void handle( String iid, String command ) { Instrumentor.startMethod( iid, “com.javasrc.instrument.test.Controller.handle( String )” ); try { // Business logic try { Thread.sleep( 100 ); } catch( Exception e ) { } if( auth.isValidUser( iid, “me” ) ) { bp.execute(iid); } } finally { Instrumentor.endMethod( iid ); } } } Listing 4-11. Authentication.java package com.javasrc.instrument.test.authentication; import com.javasrc.instrument.Instrumentor; public class Authentication {
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Web hosting companies - CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS catch( Exception

Monday, April 16th, 2007

CHAPTER 4 IMPLEMENTING PERFORMANCE MEASUREMENTS catch( Exception e ) { e.printStackTrace(); } // End the request Instrumentor.endMethod( iid ); Instrumentor.endRequest( iid ); } private void doNothing( String iid ) { Instrumentor.startMethod( iid, “com.javasrc.instrument.test.TestServlet.doNothing()” ); // Business logic try { Thread.sleep( 1000 ); } catch( Exception e ) { e.printStackTrace(); } Instrumentor.endMethod( iid ); } private void doLessThanNothing( String iid ) { Instrumentor.startMethod( iid, “com.javasrc.instrument.test. _ TestServlet.doLessThanNothing()” ); // Business logic try { Thread.sleep( 1000 ); } catch( Exception e ) { e.printStackTrace(); } Instrumentor.endMethod( iid ); } }
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision mysql hosting services