Friday, November 27, 2009

Servlet Container & Request processing

Why we need Container for Servlets?

    Servlets don't have main() method,They run under
    control of another java application called container.
    Ex: Tomcat

When Server gets request for servlet the server handovers
the request to container in which Servlet is deployed.

In simple "Container manages and runs the Servlet".

Advantages of using Container:

Communication
The container provides easy way of communication between servlets and web server.

Life-cycle Management:
The container controls the life cycle of servlet.
    Loading classes.
    Instantiating and initializing the servlet.
    Invoking servet methods ie  like init service & destroy .
    Destroying servlets for garbage collection ( Resource management ).

Threading support:
Container automatically creates a new java thread for every
request it receives.The thread dies when servlet completes
running the HTTP service method.
  
Security:   
    Container provides XML based configuration for security configuration and
modification of servlet with out changing the java code of servlet.
  
JSP support:
    Container takes care of converting JSP code into java.      

Handling the request:

When user request for Dynamic content
1)Container gets request  for servlet.
2)Container creates HTTPServletResponse and HTTPResponse objects.
3)Based on the requested URL Container maps the request to a  sevlet
and creates a thread for the request  and  passes the references of
HTTPServletResponse and HTTPResponse objects.
4)Container calls the service(),Which in-turn calls the doXXX()
methods based on the request type.
5)the doXXX() method constructs the dynamic page into HTTPResponse object.
6)When response is sent to client container deletes the objects and thread.

Thursday, November 19, 2009

Creating jasper reports in 4 simple steps


Download the jasper reports Lib and Source from here.
Intro:

    JasperReports is an open-source Java class library
    designed to aid developers with the task of adding
    reporting capabilities to Java applications.
    JasperReports is licensed under the Lesser GNU Public License (LGPL).
Features:
    It has flexible report layout.
    It is capable of presenting data textually or graphically.
    It allows developers to supply data in multiple ways.
    It can accept data from multiple datasources.
    It can generate watermarks.
    It can generate subreports.
    It is capable of exporting reports to a variety of formats.
Flow chart of Jasper Reports Creation
    We can Create Jasper report in Following four steps.


Create JRXML files:
    The first step is to create a report template
    as an XML file.Even though JasperReports'
    report templates are XML files,template filenames
    are given an extension of .jrxml.
    JasperReports XML templates are commonly referred to as JRXML files
Compile JRXML files to create Jasper File :
    JRXML files are compiled into a JasperReports
    native binary template.The resulting compiled
    template is commonly known as the Jasper
    file, and is typically saved to disk with a .jasper extension.
Fill The report:
    The Jasper file is then used to generate the final report,
    by providing it with its required data.
    This process is known as filling the report.
Display the report:
    Filled reports can be saved to disk in a JasperReports 

    native format. Reports saved in this format are known
    as JasperPrint files.
    JasperPrint file names have a .jrprint extension.
    JasperPrint files can be exported to other
    formats so that they can be opened with commonly
    available tools like PDF viewers and word processors.

Wednesday, November 11, 2009

MySQL monitoring Using ' mycheckpoint '

Download the packge from here .
Dependencies
    yum install MySQL-python.
Installation   
  untar the file and run follwoing commands
          tar xzfv mycheckpoint-XXX.tar.gz
          cd mycheckpoint-XXX
          sudo python setup.py install


Run follwing commads on mysql prompt
     CREATE DATABASE mycheckpoint;   
     GRANT ALL PRIVILEGES ON mycheckpoint.* TO                        
                     'monitoring_user'@'localhost' IDENTIFIED BY '_password';
    GRANT SUPER ON *.* TO 'monitoring_user'@'localhost';
    GRANT REPLICATION CLIENT ON *.* TO 'monitoring_user'@'localhost';


Run following command on command prompt
  
           mycheckpoint --user=monitoring_user --password=_password
           --host=localhost --socket=/tmp/mysql.sock -v --chart-width=500
           --chart-height=300 deploy


Creating defaults-file:

[client]
user=monitoring_user
password=_password
socket=/tmp/mysql.sock
port=3306
host=localhost
Create a file with above contents and save it as /root/.my-checkpoint.cnf
make follwing crontab entry

      */5 * * * *     mycheckpoint --defaults-file=/root/.my-checkpoint.cnf

Detecting parameters change:
   
    SELECT * FROM sv_param_change;
   
Generating Google charts:
    DESC sv_report_chart_sample;

    SELECT DML FROM sv_report_chart_hour \G
     we can create google charts for all the values in sv_report_chart_sample.

Generating HTML reports:

        mysql --user=monitoring_user --password=_password
                   --host=localhost   mycheckpoint 
                    -e "SELECT html FROM sv_report_html" --silent --raw >
                       /tmp/mycheckpoint_report.htm
l

Generating human Readable reports:

Previous hour’s report by:

    SELECT report FROM sv_report_human_hour ORDER BY id DESC LIMIT 1,1 \G

Last week’s report by:

    SELECT report FROM sv_report_human_day WHERE ts = DATE(NOW()) - INTERVAL 7 DAY\G

And all 24 of yesterday’s hourly reports by:

    SELECT report FROM sv_report_human_hour WHERE ts >= DATE(NOW()) - INTERVAL 1 DAY AND ts < DATE(NOW())\G
   
Replication Monitoring:
   
    SELECT seconds_behind_master FROM sv_report_chart_hour\G

Estimating slave catchup time   

    SELECT ts, estimated_slave_catchup_seconds FROM sv_report_hour;