Jumat, 19 November 2010

Tomcat 6.x Clustering

A short guide of tomcat 6.x clustering.

Tomcat is a widely used Web Server, many J2EE applications using tomcat. In this article, we will discuss about tomcat 6.x clustering step by step.

In a large application (application that has many users), application performance will be an issue. To reduce server load in one machine, cluster is a solution.

Let us begin the tomcat cluster and load balancer steps :

1. Download tomcat 6.x, then unzip it to your destination folder. After unzip it, copy to three copies. (e.g : apache-tomcat-   6.0.29, apache-tomcat-6.0.29 – B, apache-tomcat-6.0.29 – C). see screenshot for detail :

2.Open first tomcat, go to “conf → server.xml” open with editor.
  • Change “AJP 1.3 Connector Port” from 8009 to 8109.
    <Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />
  • Change “jvmRoute” to “tomcatA”
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatA">



Do the same thing to tomcat B and C.
Tomcat B : AJP Connector Port = 8209 and jvmRoute= tomcatB
Tomcat C : AJP Connector Port = 8309 and jvmRoute= tomcatC

3. Download apache http server and mod_jk. Unzip it to your destination folder. Put mod_jk.so to apache http server → modules, and mod_jk.conf to http server/conf.


4. Open httpd.conf (Apache http server → conf → httpd.conf). Add “LoadModule jk_module modules/mod_jk.so” at the LoadModule section.

5. Create workers.properties file at Apache http server/conf (same place with httpd.conf). Put this content below to workers.properties.



6. Add this configuration statement to read workers.properties to httpd.conf.

7. Try to start http server. Open your browser go to : http://localhost. If the browser say : “It Works!”. It mean your http server work fine.

8. Now, deploy your application to webapps in every tomcat server. Before deployment, don't f orget to add your application url link to httpd.conf file. (In my example, my application context root/ link is “HRMS”).

9. After running all the tomcat server, my url link will be : http://localhost/HRMS . See your tomcat running console which tomcat server your application actived.


10. Check the failover by killing the server where the application active. Then see if your application still alive or not. It should be active to another server. Try to monitor your tomcat running console.


Thanks for readers, may this article can help you to cluster your tomcat servers.

Selasa, 16 November 2010

Kismiss Report @By Kisman Hong (Dynamic Grouping, Dynamic Field)

Kismiss reports is designed for simpify both development and report design. Although kismiss cannot cover the complex report design, it can be used to solve most wanted design report. For complex report, Ireport is the best solution to use.
The first thing we need is including the kismiss required libraries in application, shown like below :
.
+ lib
commons-beanutils.jar
commons-collections.jar (3.1 above)
commons-deigester.jar
commons-lang.jar (2.3 above)
commons-logging.jar
itext.jar (2.0.2 above)
jasperreports.jar (3.0.0 above)
jdt-compiler.jar
log4j.jar
poi.jar
slf4j-api.jar
slf4j-log4j.jar
velocity.jar














The application that using kismiss need to include minimum libraries required shown above. Include all that libraries to your application. (Actually, Log4j is not required but preferred by many developers.)


Simple Kismiss Reports

First Kismiss Report

This section, we will create our first kismiss report. First, we need to create JavaBean class and define properties there. In this example, we will create a “Employee.java” class, then generate it's report by informations and data given. Let's see “Employee.java” as shown below :
package com.softtech.kismiss.main;

import com.softtech.kismiss.enumer.CalculationPrintType;
import com.softtech.kismiss.enumer.HorizontalAlignment;
import com.softtech.kismiss.enumer.PaperType;
import com.softtech.kismiss.enumer.VerticalAlignment;
import com.softtech.kismiss.property.Detail;
import com.softtech.kismiss.property.FieldGroup;
import com.softtech.kismiss.property.Group;
import com.softtech.kismiss.property.Header;
import com.softtech.kismiss.property.Kismiss;
import com.softtech.kismiss.property.Property;

/**
 * @author Kisman Hong
 * test Kismiss Reports
 */
@Kismiss(name = "Employee", columnAutoSize = true, paperType = PaperType.A4, isTitleEveryPage=false)
@Header(columnHeaderHeight=25, isColumnHeaderBold=true, columnHeaderColor="#CCCCCC", lineWidth=0.5)
@Group(calculation = {"salary : Sum", "capacity : Average"}, groupBy="division", calculationPrintType=CalculationPrintType.Complete, horizontalAlignment = HorizontalAlignment.Right)
@Detail(lineWidth=0.5)
public class Employee {
   
    private Integer id;

    @FieldGroup
    private String lastName;

    @FieldGroup
    private String firstName;

    @FieldGroup(label="ALAMAK")
    private String address;

    @FieldGroup
    private String phoneNumber;

    @FieldGroup
    private String postCode;

    private String division;

    private Double salary;
   
    private Integer capacity;
   
    private Person person;

    @Property( width = 45,  position = 5, verticalAlignment=VerticalAlignment.Top, isShowInDetail=false)
    public String getDivision() {
        return division;
    }
    public void setDivision(String division) {
        this.division = division;
    }

    @Property(width = 45,  position = 6, horizontalAlignment = HorizontalAlignment.Right, fontSize=6, verticalAlignment= VerticalAlignment.Middle)
    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Property(name = "Post Code", width = 50,  position = 7)
    public String getPostCode() {
        return postCode;
    }
    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    @Property(name = "Address", width = 100,  position = 3, fontSize=6)
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Property(name = "First Name", width = 100,  position = 1, columnHierarchy="Name info", heightPortion=15)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    @Property(name = "Last Name", width = 100,  position = 2, columnHierarchy="Name info", heightPortion=15)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Property(name="No", width=30, isRecordNumber=true, position=0)
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @Property(name = "Salary", width = 45,  position = 4, horizontalAlignment = HorizontalAlignment.Center, fontSize=6)   
    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    @Property(width = 35, position = 8, horizontalAlignment = HorizontalAlignment.Center, fontSize=6, verticalAlignment=VerticalAlignment.Middle)   
    public Integer getCapacity() {
        return capacity;
    }
    public void setCapacity(Integer capacity) {
        this.capacity = capacity;
    }

    public Person getPerson() {
        return person;
    }
    public void setPerson(Person person) {
        this.person = person;
    }
   
}


You can see that this class uses standard JavaBean naming conventions for property getter and setter methods, as well as private visibility for the fields. This is a recommended design.

Kismiss-reports properties are defined at JavaBean class. Let's see “Employee.java” for more detail :

  • The characteristic of kismiss is we must define “@Kismiss” and “@Header” and the “@Property” for the first at the class.
  • Kismiss and Header are defined at the top of the class. Attribute name of Kismiss is required.
  • Property is defined at the getter method. (Kismiss choose the getter method for defining property to prevent too many annotations at the fields). Property is used for defining field, width and position are required.
  • Width in property indicate the width of the field and position indicate the sequence of the field from left, it begin from zero.

Now, we will write some java code to fill the report data and generate Employee report :

List<Employee> employees = new ArrayList<Employee>();
        for(int i=0; i < 1000; i++)
        {
            Employee employee = new Employee();
            String[] name = produceName();
            employee.setAddress("California Rd. No. 143, Jakarta Barat");
            employee.setDivision("Kalem Kalem");
            employee.setFirstName(name[0]);
            employee.setLastName(name[1]);
            employee.setPhoneNumber(producePhone());
            employee.setPostCode(producePostCode());
            employee.setSalary(produceSalary());
            employee.setCapacity(9);
            employees.add(employee);
        }
       
        for(int i=0; i < 1000; i++)
        {
            Employee employee = new Employee();
            String[] name = produceName();
            employee.setAddress("Last Vegas Rd. No. 341, Jakarta Timur");
            employee.setDivision("Hura Hura");
            employee.setFirstName(name[0]);
            employee.setLastName(name[1]);
            employee.setPhoneNumber(producePhone());
            employee.setPostCode(producePostCode());
            employee.setSalary(produceSalary());
            employee.setCapacity(5);
            employees.add(employee);
        }
       
   
        KismissReport report = KismissReport.getInstance();
       
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put(ReportFactory.TITLE, "TEST KISMISS REPORT");
        params.put(ReportFactory.INFOTITLE, "Report");
        params.put(ReportFactory.PDF_NAME, "employeeTest.pdf");

        report.generateAnnotatedPdfFiles(Employee.class, employees, "D:/Personal/Test/", params);



Let us see step by step :
  1. initialize kismiss report instance
  2. declare the report params to be included
  3. defining title of report
  4. give report file name
  5. generate report

The code above is quite simple. We do not need a long code to generate the report. Prepare the data then call the generate method function.

The generateAnnotatedPdfFiles method has four parameters :
  1. the JavaBean class that will be generated, in this example : “Employee.class”.
  2. collection data of class, this is the content of report.
  3. path where the pdf file will be generated.
  4. the params of report, such as title, report file name, etc.

After finishing the following steps above, let us see the report result :
Kismiss Report will be released in 2011, a full reference documentation will be included.

Instant Guide to Jasper IReport

A short guide for designing java reporting with jasper ireport :
  1. Open your ireport (it can be installed version or portable ).


  1. Create new report file.
    See the ireport menu tool bar, you will see “File, Edit, View Format, Preview, Window, Tools, and Help” menu. For create new report template file click “File” menu than the “File” menu option will appear. Choose “new” option.



3. Choose report template.
New file popup window appear. There are many templates that can be used. Choose any template that suitable your report needs. In this example I use “Blank A4” template.

  1. Fill report name.
    New report name popup window appear. Fill your report name, folder location, and where to put generated jrxml file. Click next.


5. Finish report template.
Report tempate finish window appear. Click finish if everything has been filled well, other wise click back and following the step before.



6. Show “Palette” tool bar.
By default, pallete is hidden. We must show it for using label, textfield and the others.



7. Pallete tool bar appear in the right top window.


8. Create title using “static text” component (label).
From the pallete window drag “static text” to title band. Write your report title.



9. Create report column name at column header band using “static text” component.
Drag the “static text” to column header band as many as your report columns. Arrange their column width, height by drag the box. Right click → Padding And Border for setting the padding and border property.




10. Give value to “line width” and “padding” property.
After right click → Padding And Border, a popup window will be appeared. Fill the value of padding and line width as you want.


11. Create report content by using text field component in detail band.
    Drag “text field” componet to detail band as many as your report columns. Arrange their column width, height by drag the box. Right click → Padding And Border for setting the padding and border property.


12. Omit the unused band.
Colum Footer, Page Footer, Summary can be omitted when unused. It can be done by dragging the border line of the band. Put the cursor of the bottom line of the band then drag to the top till meet the bottom line of the above band.
See the final report template.



The report template is done. We can get the jrxml file in the location specified at point 4. Now, we can use the report template to generate the report by filling the data and view it.