Tuesday, 20 October 2015

Deploying PlayFramework application on Amazon EC2

Friend of mine asking about deploying PlayFramework application on EC2(Elastic Compute Cloud).So I dicided to write all the steps required. Following are the steps for deploying play app on EC2.

  • Creating EC2 instance 
  1.  Create Amazon account and "Sign Into Console"
  2.  Select "Launch Instance".
  3. Choose Amezon machine image , select ubuntu Srever.
  4. Choose Available micro Instance. Select next setting upto to "Configure Security Group".
  5. Add Security Rule for SSH,HTTP,HTTPS, Basically these rule control traffic.
  6.  Launch Instance. 

  7. Please find following image for more info




  • Create key 
    •  Save generated key on your machine, we need it while connecting using SSH.
  • Create Elastic IP
    • Select your instance while creating Elastic IP. 
  • Connect EC2 instance using ssh  
  • Install JAVA 8 on EC2
  • Install Play framework on EC2.
  • Create and deploy distribution.
  • Port Forword (default 8080 to plays default 9000)
  • Register with Godaddy .




Wednesday, 16 September 2015

Blocking Queue (Typical Example of Producer and Consumer )

Some days ago my boss comes with new changes in our product. Then I started looking into solution that solve my problem.
I will explain my problem and its solution (Typical producer, consumer problem).

we have three objects 

  1. Learning Module
  2. Validate 
  3. Training Content
Relations 
  • Learning Module one To Many Validate 
  • Learning Module one To Many Training Content

So, typical case is that we have Learning Module with around 20,000 validate object connected to it. Whenever new Training Content connected to Learning Module we have to update all Validate object(20000) connect to Learning Module. 
First thing that comes in mind is put process of updating Validate Object in separate thread. Ok and that is the solution, punting it in separate thread.

Problem with above solution is we don't to create new thread for every time new Training Content connected to Learning Module.(Lets 1000 user connecting Training Content to different Learning Module then 1000 thread is going created .... and bang).

So, We comes with idea that we dedicate one single thread for all Learning Module connecting to New Training Content for updating connected Validate Object.
In this we have multiple producer (Action of connection Learning Module and Training Content) and one consumer thread (For Update related validate object).       
From above we have multiple user that connecting Learning Module and updating of related Validate object is done by single dedicated thread.
As form java 1.5 we have some concurrent API that helps to build typical producer consumer problem and found BlockingQueue.

Blocking Queue is block consumer thread if it is empty and Block producer if it is overflow.We don't have to build Wait/Notify event for thread handling things.


Sunday, 21 June 2015

Coffee With Scala

What is difference between def and val ?
-- Def evaluate every time we access them but val only evaluate when object referenced first time.

Details on

  1. val
  2. lazy val
  3. def

Following example is best way to understand above three.

scala> class X { val x = { Thread.sleep(2000); 15 } }
defined class X

scala> class Y { lazy val y = { Thread.sleep(2000); 13 } }
defined class Y

scala> new X
res5: X = X@262505b7 // we have to wait two seconds to the result

scala> new Y
res6: Y = Y@1555bd22 // this appears immediately

Thursday, 18 June 2015

Compression and Decompression (tar,rar,zip,gzip)

About  tar, rar, zip, gzip

tar puts multiple files into a single(tar) file. [On unix or Unix like system]
rar    puts multiple files into a single(tar) file. [On Windows]
gzip compresses one file (only).  [On unix or Unix like system]
zip compresses one file (only).  [On windows]

We can first tar the all file into single tar file then compressed it using gzip and file has extension like  name.tar.gzip

Thursday, 11 June 2015

JavaScript Debugging and Testing

You can debug java script  by using two ways 

  • By logging into DevTool console using console.log()
  • Using debugger key word
<script>
     callDebugSentence();
    function callDebugSentence(){
             debugger;
            console.log("After debugger sentence");
     }
</script>