Monday, April 13, 2015

Handle the Unexpected with Bluemix Auto-Scaling

Handle the Unexpected with Bluemix Auto-Scaling #bluemix #autoscaling

Handle the Unexpected with Bluemix Auto-Scaling

One of the intrinsic benefits of cloud platform services is that they drastically simplify the process of scaling your application. Scaling can be done both vertically - by increasing the amount of memory available to each instance - or horizontally - by creating additional instances. This process of scaling your application can be done manually, either through the Cloud Foundry CLI or the application dashboard. However, it is also useful to be able to scale automatically in order to quickly react to spikes in application usage. The Auto-Scaling service provides the ability for users to dynamically scale their application horizontally by creating custom policies that dictate scaling behavior.
IBM Technical Rock Star Program

Track the world's top newsmakers with IBM Watson

Track the world's top newsmakers with IBM Watson

Track the world's top newsmakers with IBM Watson


IBM Technical Rock Star Program

Tuesday, April 23, 2013

struts2-jquery: jquery is undefined

I was using struts2-jquery plugin while learning jquery with struts2 and was stuck at the error

jquery is undefined

After doing lot of research found that the fix was very simple. I did'nt use sj:head tag in my jsp. After adding tag to the jsp, my problem got solved.

Thursday, October 25, 2012


Finding out the tables referencing the given table in Oracle Database:

Below query gives you details about the tables referencing the given table in Oracle database:


select table_name, constraint_name, status, owner
from all_constraints
where r_owner =  :owner
and constraint_type = 'R'
and r_constraint_name in
 (
   select constraint_name from all_constraints
   where constraint_type in ('P', 'U')
   and table_name = :tablename
   and owner = :owner
 )
order by table_name, constraint_name

Replace the parameters owner, tablename to your schema owner and the table name.

Wednesday, June 15, 2011

JVM shutdown hook (Surviving abrupt shotdown)

Project I am working currently requires the ability to detect shutdown on JVM. Its basically required to be detected so that active connections to the JMS server to be destroyed. I wrote code to destroy connection on ServletContextListener which worked fine for some scenario, but failed if I kill web server processes explicitly.


The solution is a little known feature of the language that lets you register JVM shut down hooks. A shut down hook is simply a Thread that is registered with the JVM and run just before the JVM shuts down.

Here is code snippet to register shutdown hook with JVM:

Runtime.getRuntime().addShutdownHook(new Thread()
  {
   public void run()
   {
    // your code here which needs be executed before shutdown
   }
  });

Runtime.getRuntime().addShutdownHook(new Thread()
  {
   public void run()
   {
    try
    {
     Thread.sleep(10000);
    }
    catch (InterruptedException ex)
    {
    }
    // halt will bail out without calling further shutdown hooks or
    // finalizers

    Runtime.getRuntime().halt(1);
   }
  });


Monday, June 13, 2011

Database encryption using Jasypt (Java Simplified Encryption)


Here are required jars for using Jasypt
commons-lang
commons-codec
jasypt

Here is example of string encryptor with Spring and Hibernate.


Define encryptor in spring configuration file:

    
    
        PBEWithSHA1AndDESede
    
  
    
        jasypt
    
    
        4
    
 
  
  
    
        strongHibernateStringEncryptor
    
    
        
    
 

In hibernate mapping file define type as follows:

@TypeDef(
        name="encryptedString", 
        typeClass=EncryptedStringType.class, 
        parameters={@Parameter(name="encryptorRegisteredName",
                               value="strongHibernateStringEncryptor")}
    )


And then specify type as encryptedString for the columns you want to encrypt.
e.g.

@Column(name = "QO_OPTION", length = 4000, nullable = false)
 @Type(type="encryptedString")
 private String optionText;

Here hibernate will take care of encrypting while saving string to database and decrypting while loading object from database.