Monday, August 21, 2017

Creating APIs - Enterprise Service Bus

This page describes how you can create an API that allows URL parameters to be sent directly into the ESB. 

Goto wso2 developer Studio. 

01 . Create ESB Solution Project 
Click Developer Studio -> Open Dashboard -> Click ESB Solution Project 

ESB Project Name is  TestAPI


Remove Create Registry Resources Project and Create Connector Exporter Project. Only tick Create Composite Application Project. Then click Finish.

 02. Create REST API 

Right click on created project(Left side)

New =>REST API =>Create A New API Artifact 


Enter bellow parameters to text fields 









You can see created API in leftside





















Select Source code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/service" hostname="localhost" name="urlParameterAPI" port="8280" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence/>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>


Then Change it like bellow code

<?xml version="1.0" encoding="UTF-8"?>
<api context="/service" hostname="localhost" name="urlParameterAPI" port="8280" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET">
        <inSequence>
             <log level="full">
                <property expression="get-property('username')"                  name="====USERNAME===="/>
            </log>
        </inSequence/>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>


Now its ok.

http://localhost:8280/service?username=Priyantha_Samaraweera



Wednesday, August 16, 2017

Deadlock, livelock

deadlock, livelock

Threads


Abstract Class in Java

A class that is declared using “abstract” keyword is known as abstract class.

Abstract is a process of hiding the data implementation details and showing only functionality to the user.Abstraction lets you focus on what the object does instead of how it does it.

Main things of abstract class

  • Abstraction class may or may not contain abstraction method.(There can be non abstract method) Point : An abstract method is method that declare that is declared without an implementation (without braces, and followed by a semicolon), like this:      Ex : abstract void moveTo(double deltaX, double deltaY);
  • But, If a class has at least one abstract method then class must be abstract
  • If a class is declared abstract, it cannot be instantiated (Abstract classes may not be instantiated) {You are not allowed to create object of Abstract class}
  • To use abstract class you have to inherit it from another class. Provide implementation to all the abstract method in it.
  • If you inherit abstract class, You have to provide implementation to all the abstract method in it.

Declare abstract class

Specifying abstract keyword before the class during declaration, make it abstract. Have look below code:
abstract class AbstractDemo{ }

Declare abstract method

Specifying abstract keyword before the method during declaration, make it abstract. Have look below code
abstract void moveTo();//no body

Why we need to abstraction class

In an object-oriented drawing application, you can draw circles, rectangles, lines, Bezier curves, and many other graphic object. These object all have certain states(for ex -: position, orientation, line color, fill color) and behaviors(for ex -: moveTo, rotate, resize, draw) in common. Some of these states and behaviors are the same for all graphic objects (for ex : fill color,position, and moveTo). Others require different implementation(for ex: resize or drow). All GraphicObject must be able to draw or resize themselves; they just differ in how they do it. This is a perfect situation for abstract superclass. You can take advantage of the similarities and declare all the graphic object to inherit from the same abstract parent object(for ex : GraphicObject) as shown in the following figure.


First, you declare an abstract class, GraphicObject, to provide member variables and method that are wholly shared by all subclasses, such as the current position and the move to method.GraphicObject also declared abstract methods for abstract methods, such as drow or resize, that need to be a implemented by all subclasses but must  be implemented in different ways. The GraphicObject class can look something like this:

abstract class GraphicObject {

   void moveTo(int x, int y) {
       //Inside  this method we have to do change position of the graphic object
// according to x,y .This changes same to every graphic object.
//Then we can implement here.
   }
   abstract void draw(); //But every graphic object drawing case is unique.
// Not common. Then we have to create that case
// inside each class . Then create these method as abstract
    abstract void resize();
}


Usage of abstract method in sub classes

Each non abstract subclasses of GraphicObject, such as Circle and Rectangle, must provide implementations for the draw and resize method.

class Circle extends GraphicObject {
   void draw() {
       //Add to some implementation here
   }
   void resize() {
       //Add to some implementation here   
   }
}
class Rectangle extends GraphicObject {
   void draw() {
       //Add to some implementation here
   }
   void resize() {
       //Add to some implementation here
   }
}

Inside the main method you can call all methods like this

Public static void main(String args[]){
GraphicObject c = new Circle();
c.drow();
c.resize();
c.moveTo(4,5);
}

Ways to achieve abstraction in java

There are two ways to achieve abstraction in java
  • Abstract class(0 to 100%)
  • Interface(100%)

Abstraction class having construction, data member, method etc

abstract class GraphicObject {
  
   GraphicObject (){
       System.out.println("GraphicObject  is created");
   }
   void moveTo(int y, int x) {
          System.out.println("Change position according to "+ x+ " and " + y);
   }
   abstract void draw();
}

class Circle extends GraphicObject {
   void draw() {
       System.out.println("Draw the Circle");
   }
}
class TestAbstract
{  
   
   public static void main(String args[]){
      
       GraphicObject  grObj = new Circle ();
       grObj.draw();
       grObj.moveTo(4,6);
   }
}

Output:
GraphicObject  is created
Draw the Circle
Change position according to 6 and 4


Remember two rules:

  • If the class is having few abstract methods and few concrete methods: declare it as abstract class.
  • If the class is having only abstract methods: declare it as interface.


Tuesday, August 15, 2017

WSO2 Enterprise Service Bus Quick Start Guide

Before you working start with wso2 esb tool you have to download two different tool.

Enterprise Service Bus Tool
Developer Studio Tool

Download wso2 esb tool

  • Go to this link
  • Select binary type of 5.0.0 version
  • Enter your details and select and Select submit. It will download esb tool
When downloaded it you can extract and ready to use it


Download Developer studio tool(Current best version)

  • This developed on the eclipse mars version. 
  • Go to this link
  • Click download button
  • Enter your email and click Download Tooling
  • Select your operating system(OS) then it will start download 

Congratulation! Now you are ready to work with wso2 esb product.

Friday, August 4, 2017

What is the Compiler, JVM in java

When we type code using some IDE like eclipse,  netbeans  it's only can understand us. But computer can't understand it. There for compiler and JVM help to machine to understand this code. How ever compiler , compile the code to the bite code. And java virtual machine(JVM) convert that byte code to the ascii value using Just in Time (JIT). That's why java slow compatibility.