Skip to main content

Posts

Showing posts from 2014

Custom Log4J Appenders

  1.     Definitions 1.         com.habanoz.logging. CombinedDailyAndRollingFileAppender This appender combines functions of log4j DailyRollingFileAppender and RollingFileAppender. Files are rotated according to max file parameter. If rolling date reaches, all indexed files are renamed to have date pattern. Rolling Algorithm can be depicted as follows: file.log                                                                                    (name of log file.corresponds to File param.) if(maxFileSize)  {                                                             (corresponds to MaxFileSize param.)  file.log -> file.log.1  file.log.1 -> file.log.2  ..   file.log.max-1 -> file.log.max       (max determined by MaxBackupIndex param) } if(date passed) {                                   (determined by DatePattern param.)   file.log -> file.log.date   file.log.1 -> file.log.date.1   file.log.2 -> file.log.date.2   ..   file.lo

Convert Tabular Data to Matrix Form Data

  1.     Introduction Select   count (*),  category ,  subcategory  from   table   where  somecontions = true   group   by  category ,  subcategory Suppose you extracted data from database which contains data according to a category and a shared subcategory. You need to display this data with an excel chart. Unfortunately it is not easy to build a chart using structure of data. It is required to reorganize this data to easily build a chart out of this data. 2.     Problem Definition Category is hour. Sub-category is status. This table contains hourly status values of some variable. To use this data in excel to create a chart, data needs to be re-organized. New table should have a matrix like layout. Row of the matrix should contain category values while Column of the matrix needs to contain sub-category values. Resulted table should look like picture below. 3- Solution Implementation A simple java application is developped to help us do requir

SSH Public Key Based Authentication

1-        Generate public and private keys by using  puttygen . Save public and private keys with or without passphrase. 2-        Public key which is seen as selected in picture, needs to be added to authorized_keys file in GIT server. While copying make sure that: -            Key starts with “ssh-rsa” -            Key does not include “ rsa-key-20140505” -            Key must be single line. 3-        In GIT server, generated key needs to be added to   ~/.ssh/authorized_keys  file. Make sure public key is copied according to remarks above. A sample public key is as below: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAi6ZlUMEIwB4UAhE8WQL0BFzDK/4dnQzSHhhIGgqmrunLd4IkK1lGDF3YpqMOz5VLFggfJZPx+VgGkqliOvHdHn4GVsqOQZOiIku3ZuipvWIR4ZC6IBO31N/2nZaeRYXWPVdT9WzcT8mWi6Xh+0ULZdf++b8CqyFa4uuziqw7qb15dIczhDfsZfxpJovYwb/HDKFKznFtehrLG1Xc3VlfUzq2SO89+7vWFjLBaSPG5y7Fcx20SreJiF4ESV0wBdAh7N6ab1vYpK++ab1sNxD5rrdbgqsoUT7yFcGroBPmFuIfqKyP6QWwNYFjH2urhmG5efiLTbRWOQEXsL1nt9PMPQ==

Remote Monitoring of Java Process Using Jvisual VM

A-    Using Jstatd Jstatd deamon is a process which comes with JDK. It can be used to remotely monitor jvm processes. It is possible to monitor any jvm processes without need to commanline parameters. However, it is limited when compared to JMX connection. 1-        Create a  jstatd.all.policy  file in statd directory. cd /usr/jdk/bin touch jstatd.all.policy vi jstatd.all.policy Add following lines to  jstatd.all.policy : grant codebase "file:${java.home}/../lib/tools.jar" {    permission java.security.AllPermission; }; 2-        Run jstatd daemon. ./jstatd -J-Djava.security.policy=jstatd.all.policy 3-        In client machine, open Jvisualvm and goto  Applications->Remote->Add Remote Host  and enter ip address of remote machine hosting java process. 4-        Right click newly added remote node and click “ Add Jstatd connection... ” . 5-         Available process will be listed under newly created remote no

A Quick Java Decompilers Comparison in the Case of String Concatenation

Introduction Java decompilers are great tools to give insight about efficiency of compiled code. Currently there are two popular java decompilers: cavaj and jd-gui. Comparison Case It is a well-known fact that concatenation of strings is not an efficient way of building strings using some number of other string obects. Since string objects are immutable, each concatenation creates a new string, this will continue until final string object is created. All created string objects other than the final one, are intermediate objects and nothing but garbage. For this reaseon java compiler converts string concatenations into StringBuilder statements. Using decompilers lets see if this is really true. Below are the original source code and decompiled versions of original code using two decompilers. // original source code logger . debug ( "bulkId:"   +  bulkId  +   " is TIME_RULES_VIOLATED..." ); logger . debug ( new  StringBuilder ( "bulkId:&qu

Java Application as Windows Service

  Introduction In cases when it is needed to run application in background and to start whenever system starts then it is required to make it a service. In windows platform an application needs to have service capabilities such as start, stop and status to run it a service.  For java applications this capability is not inherent and a wrapper application is needed to achieve this.  Apache Commons-Daemon  project is one common tool for this.   Steps 1-        Java Application needs to implement  org.apache.commons.daemon.Daemon  interface.   public   class  ServiceWrapper  implements  Daemon  {      private   final   static  Logger logger  =  LoggerFactory . getLogger ( ServiceWrapper . class );      private   static   final  ServiceWrapper serviceWrapper  =   new  ServiceWrapper ();      static   void  main ( String []  args )   throws  Exception  {         String mode  =  args [ 0 ];         logger . info ( "ServiceWrapper main started" );