Rest: quick start web app using maven and jersey

Below lines works wonder using maven, creates web app structure and pull all dependencies.

mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArtifactId=jersey-quickstart-webapp -DarchetypeVersionId=2.16

Advertisements

Groovy: Multi threaded producer consumer program

import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue

BlockingQueue queue = new LinkedBlockingQueue();

Thread.start('Producer') {
    10.times {
        println(Thread.currentThread().name + " adding $it")
        queue << it
        sleep(100)
    }
}

Thread.start('Consumer') {
    for(i in 0..9){
        sleep(200)
        print(Thread.currentThread().name)
        println("consuming ${queue.take()}")
    }
}

Groovy: Closure Composition

Closure composition corresponds to the concept of function composition, that is to say creating a new function by composing two or more functions (chaining calls), as illustrated in this example:

def plus2  = { it + 2 }
def times3 = { it * 3 }

def times3plus2 = plus2 << times3
assert times3plus2(3) == 11
assert times3plus2(4) == plus2(times3(4))

def plus2times3 = times3 << plus2
assert plus2times3(3) == 15
assert plus2times3(5) == times3(plus2(5))

// reverse composition
assert times3plus2(3) == (times3 >> plus2)(3)

 

SDK MAN – Software Development Kit Manager

I use sdk man to maintain multiple versions of Groovy, Java, Scala. It makes switching very easy.

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates. Formerly known as GVM the Groovy enVironment Manager, it was inspired by the very useful RVM and rbenv tools, used at large by the Ruby community.

Installing SDKMAN! on UNIX-like platforms is as easy as ever. SDKMAN! installs smoothly on Mac OSX, Linux, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells.
Simply open a new terminal and enter:

$ curl -s "https://get.sdkman.io" | bash

Follow the instructions on-screen to complete installation.
Next, open a new terminal or enter:

$ source "$HOME/.sdkman/bin/sdkman-init.sh"

Lastly, run the following code snippet to ensure that installation succeeded:

$ sdk version

If all went well, the version should be displayed. Something like:

  sdkman 5.0.0+51

Architecture: Bridge Design Pattern

Hi Friends,
I have made a project of “Remote Control Application” by implementing Bridge design pattern.

Project: Solves the problem of dependency / coupling between parallel development / evolution of 2 different components by creating a bridge between their interfaces 😉

What is Bridge Design Pattern: decouples an abstraction so two classes can vary independently

Github project code: https://github.com/premaseem/DesignPatternsJava9/tree/bridge-pattern

I have written the working code based on the Architectural diagram, which can be downloaded from Github.

4_4_Bridge_pattern_sequence

Bridge Design Pattern class diagram.png

MongoDB : History tracking micro service

Mongo DB local -> oplog.$main collection keeps records of all changes which happen in the primary database, which are eventually read by secondaries to catch up data or syncup data in the mongo replica set.

A micro service can be written, which can pull up data / delta form oplog.$main based on the name space ( defined db and collection) and can save that data in destination Db or audit DB.

Later on audit DB can the queried to fetch the history or log data pertaining to entity.

audit log sequence diagram