Thursday, 20 July 2017

Linux: Know PID running at a specific port number

To know the process id which is running on a specific port number

$ sudo netstat -nlp | grep :1212
   tcp6       0      0 :::1212        :::*   LISTEN      21341/java 

$ lsof -i 

It displays the information of all currently running process like PID, port number, user etc.


$ lsof -i
java       60729   ram  7188u  IPv6  121212      0t0  TCP *:1291 (LISTEN)
java       60850   ram  7181u  IPv6  1212        0t0  TCP *:1195 (LISTEN)
java       60949   ram  8173u  IPv6  1212        0t0  TCP *:2272 (LISTEN)
java       70040   ram  1971u  IPv6  1213        0t0  TCP *:2230 (LISTEN)
java       70142   ram  9072u  IPv6  11111       0t0  TCP *:4449 (LISTEN)
java       70232   ram  1365u  IPv6  111         0t0  TCP *:5585 (LISTEN)
java       70318   ram  1476u  IPv6  111         0t0  TCP *:6514 (LISTEN)
python     70400   ram    43u  IPv4  2222        0t0  TCP *:1232 (LISTEN)
java      180595   ram  3402u  IPv6  22222       0t0  TCP *:3232 (LISTEN)

Then run kill command to kill it.

$kill -9 <PID>

Thanks you.

Wednesday, 17 May 2017

Activator will be EOL-ed on May 24, 2017.

Activator will be EOL-ed on May 24, 2017.

We’re making it easier and simpler for developers to get started with Lightbend technologies.

This unfortunately means that future releases of Play, Akka and Scala will no longer include Activator support, and Lightbend’s Activator server will be decommissioned by the end of 2017. Instead of supporting Activator to create and set up development projects, we'll be supporting standard Giter8 templates for sbt users and Maven archetypes for Maven users.

So going forward,
To create new Lightbend projects
Instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template.

For example, “$ sbt new akka/hello-akka.g8”. You can find a list of templates here.

Also, as a convenience, the Lightbend Project Starter allows you to quickly create a variety of example projects that you just unzip and run.

To create new templates

If you want to create new templates, you can now do that in Giter8.

To migrate templates from Activator to Giter8
If you created Activator templates in the past, please consider migrating them to Giter8 with this simple process.

Thank you!

Friday, 21 April 2017

Akka 2.5.0 Framework Features

Akka 2.5.0 Released!
we—the Akka committers—are proud to be able to announce the availability of Akka 2.5.0. Since the release of Akka 2.4.0 (already 18 months ago) we have incrementally added many new features to the 2.4.x release series, including Akka Streams and HTTP. That has worked well and we think you appreciate the API stability of all those patch versions. As always, there are some changes one cannot do in patch versions and therefore it is time for Akka 2.5. One of these changes is to promote some of the experimental modules to fully stable modules and incorporate some API improvements before declaring them stable.
Akka 2.5 is binary backwards compatible with 2.4 with the ordinary exceptions listed in a separate section below. Read the migration guide as the first step.
The key features of the 2.5.0 release are:
  • The Java API for AbstractActor was promoted to fully stable API. While doing this we made some small, yet important, improvements to the API that will require some mechanical changes of your source code.Thanks to @ortigali for help.
  • Faster and more flexible Akka Streams materializer, which matters for short lived streams, such as HTTP requests.
  • Distributed Data was promoted to a fully stable module. Several improvements were also included, such as:
    • Support for delta-CRDTs in Distributed Data to reduce the amount of data that is replicated, thanks to help from @gosubpl.
    • Generic type for the key in Distributed Data ORMap, thanks to jgordijn
  • Coordinated shutdown to facilitate ordered stopping of actors and services and perform registered tasks during the shutdown process. This greatly simplifies tasks involved in graceful leaving of Akka Cluster.
  • Support remembering entities in Cluster Sharding with the Distributed Data (ddata) mode. ddata is now also the default mode for Cluster Sharding.
  • New Java API for Testkit taking advantage of lambas, thanks to @Hawstein
  • Fix performance regression for Scala 2.12, due to change in scheduling fairness of the JDK8 ForkJoinPool implementation
  • We added @ApiMayChange and other annotations which can be used to mark experimental API inside stable modules, primarily for use in Akka HTTP.
  • API improvements of Akka Typed, including Java API

Binary Compatibility

Akka 2.5.x is backwards binary compatible with previous 2.4.x versions (exceptions listed below). This means that the new JARs are a drop-in replacement for the old one (but not the other way around) as long as your build does not enable the inliner (Scala-only restriction). It should be noted that Scala 2.12.x is is not binary compatible with Scala 2.11.x, which means that Akka’s binary compatibility property only holds between versions that were built for a given Scala version—akka-actor_2.12-2.5.0.jar is compatible with akka-actor_2.12-2.4.17.jar but not with akka-actor_2.11-2.4.17.jar.
Binary compatibility is not maintained for the following:
  • akka-testkit and akka-multi-node-testkit
  • modules and API marked as “may change”, such as akka-typed and akka-contrib
  • features, classes, methods that were deprecated in 2.4.0 or earlier and removed in 2.5.x
We had to make two additional exceptions:
  • Custom Mailbox implementations. Scala 2.12 is using the standard JDK8 ForkJoinPool, which may cause performance regression for some Actor messaging scenarios. Therefore we have embedded the ForkJoinPool from Scala 2.11 in Akka. This breaks binary backwards compatibility for custom Mailboximplementations that were compiled with Akka 2.4.
  • To make the Java APIs AbstractPersistentActor and AbstractPersistentActorWithAtLeastOnceDelivery to work with Scala 2.12 we could find no other solution but to break the binary compatibility of the Scala versions (which the Java ones were based on).
Being binary backwards compatible means that applications and libraries built on top of Akka 2.4.x continue to work with Akka 2.5.x without recompilation (subject to the conditions below), which implies that Akka HTTP as well as Play Framework 2.5 can be combined with Akka 2.5.

Tuesday, 4 April 2017

Play Framework 2.5.13 New Features

Play 2.5.13 “Streamy”

  • #7040: Add @helper.repeatWithIndex(…) helper
  • #7033: Fix XHTML mime type
  • #7013: Add note to Migration25 about Lucidchart blog
  • #6966: Fix documentation code NPE
  • #6954: Update Typesafe Config to 1.3.1
  • #6934: Update docs with more information about sbt new
  • #6948: Remove images that related to activator
  • #6944: Add Scalate as a library for Play support documentation
  • #6933: Add immutable header to aggressiveCacheControl
  • #6925: Upgrade sbt-native-packager to latest stable version
  • #6874: Update
  • #6908: Remove unnecessary println call
  • #6906: added play-guard (Scala) to module directory
  • #6850: Reference to play-redis module in Module directory in the documentation

Friday, 10 March 2017

My Posts on Website


As you know, I am writing tutorials to and on Java, Java EE, Spring Hibernate, Scala, Play, Akka, No SQL, BigData etc.

Recently started writing tutorials to one of the famous tutorials website:

In this post, I will list out all my MKYong website posts so that you can browse them easily with just one simple click.

Please support my Blog by clicking some Ads to improve it with more Look &Feel and more and more useful tutorials.

That’s it all about My Tutorials at website.
Please drop me a comment if you like my post or have any issues/suggestions/type errors.
Thank you for reading my tutorials.
Happy Learning!

Tuesday, 14 February 2017

Tech News for Dev and QA


Like Scala News, in this post, I'm going to update all Technology News useful for any IT Guys: IT, DEV and QA. Please check this post regularly to know more news.

Tech News

  • MongoDB Stitch
         Configure your application backend in the cloud
  • Convert Unix timestamp to Readable Date/time 
         Convert a Date/Time to a Unix timestamp
  • JSON Formatter Tool  
  • Gradle 3.5 now available! 
  • Chrome DevTools  Free Tutorial 

  • Nice JSON Formater

  • JSON Validator or Formater

  • To Create Regexpressions easily

  • MongoDB UI Tool or Manager
  • Another useful MongoDB Manager

  • ZAP Security (PEN) Testing Tool      

  • BigData Hadoop Softwares
BigData SoftwareOrganization
Apache HadoopApache Software
ClouderaCloudera Inc.
Microsoft AzureMicrosoft 
IBM BigInsights IBM
Google Cloud DataprocGoogle 
Oracle Big Data ApplianceOracle Corporation

  • Cloud Platform

AWS (Amazon WebService)Amazon
GCP(Google Colud Platform)Google

Stay tuned for further updates to this post to know more news about Technology New.

I love your valuable comments please.

Thank you.

Sunday, 5 February 2017

Scala Future and Promise API With Examples

Post Brief TOC

  • Introduction
  • Scala Future API
  • Scala Promise API
  • Scala Promise API
Let us start exporting Scala Future and Promise API with some simple examples now.


Scala Future and Promise API is defined in scala.concurrent package. This API is used to develop Concurrent and Parallel applications in Scala Language.
Future represents a Computation unit. This unit is executed by Promise and put into the Future.
In simple words, Future is an object to read that result and Promise is an object to execute that computation unit. Let us explore these concepts in-depth with some useful examples in the coming sections.

NOTE:- Please support my Blog by clicking Ads to deliver more and more useful tutorials.

Scala Future API

Future[T] contains a computation unit of type T. This computation is done sometime in future either successfully or not.
What is Computation Unit?
A Computation Unit is a block of code (which is used to perform a task or calculate some value etc.)
Generally, this Computation unit runs Synchronously. If we place this Computation unit in Future, it runs in Asynchronously.
If this computation is completed successfully, Future contains a value of type T.
If this computation is completed with failure, Future contains an exception of Type Throwable.
Like Scala Constructs: Option, Either, Try etc., Scala Future is also a Container type. It may contain a value or an exception in future.
It is write-only-once container. Once it’s completed, we cannot change it’s value that means it becomes Immutable.
Who writes that value into Future: Promise (Will discuss it in next section).
Future Companion Object:
object Future{
  def apply[T](body: => T): Future[T]
Here computation unit is body. As it’s computed Asynchronously, it is defined as “By-Name Parameter”.
scala> import scala.concurrent.Future
import scala.concurrent.Future

scala> import

scala> val intFuture = Future(10)
intFuture: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise@6b9ce1bf


scala> val intFuture = Future{10}
intFuture: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise@6b9ce1bf
We can use either parentheses or curly braces.
scala> val nameFuture = Future("Rams")
nameFuture: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@19fe4644

scala> nameFuture.value
res5: Option[scala.util.Try[String]] = Some(Success(Rams))

scala> nameFuture.value.get
res6: scala.util.Try[String] = Success(Rams)

scala> nameFuture.value.get.get
res7: String = Rams
Future Trait Definition:
trait Future[+T] extends Awaitable[T]{
 def map[S](f: T => S) :Future[S]
    def flatMap[S](f: T => Future[S]) :Future[S]
Complete Scala Future API:
Almost all Future functions contains ExecutionContext as implicit parameter.
object Future{
  def apply[T](body: => T)(implicit executor: ExecutionContext): Future[T]
trait Future[+T] extends Awaitable[T]{
 def map[S](f: T => S)(implicit executor: ExecutionContext) :Future[S]
    def flatMap[S](f: T => Future[S])(implicit executor: ExecutionContext) :Future[S]
Here executor is an implicit parameter, we don’t need to specify it.

What is an ExecutionContext?

ExecutionContext is a place where our Future’s Computation unit is executed.
Scala Language gives us a ready-made static global ExecutionContext in
NOTE:- In simple words, ExecutionContext is something similar to a Thread Pool (Java Guys also can understand this).
Future combinator API
Converting a list of Futures into a Single Future that means Collections of Futures into a Single Future
List[Future[T]] ======> List[T]
scala> val pricesList:List[Future[Int]] = List(Future(1001),Future(999),Future(-2000),Future(1000))
pricesList: List[scala.concurrent.Future[Int]] = List(scala.concurrent.impl.Promise$DefaultPromise@680a66dd, scala.concurrent.impl.Promise$DefaultPromise@2dd8239, scala.concurrent.impl.Promise$DefaultPromise@472698d, scala.concurrent.impl.Promise$DefaultPromise@7b7683d4)

scala> val maxPrice:Future[Int] = Future.sequence(pricesList).map(_.max)
maxPrice: scala.concurrent.Future[Int] = scala.concurrent.impl.Promise$DefaultPromise@14fded9d

scala> { price => println("Max price = " + price) }
res0: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@ebda593
Max price = 1001

Scala Promise API

As we discussed, Future is a placeholder to hold a computation unit (which retuns a value or exception and which does not yet exist). It is used to read that result. Where as Promise is used to finish that computation and write value into Future.
So, Future is used to read that value where as Promise is used to write that value.
In simple words, we can say that Future is used to Query or Read the result and Promise is used to Write or Put the result.
As we discussed, We can write the result into a Future only once. Once it is done, we cannot change that value. So Promise can write a value into Future only once.
A Promise instance is always linked to exactly one and only one instance of Future.
object Promise[T] {
  def apply[T](): Promise[T]
trait Promise[T]{
 def success(value: T) : this.type
 def failure(cause: Throwabale): this.type

  def future: Future[T]
Empty Promise to Future
scala> val cityPromise = Promise[String]()
cityPromise: scala.concurrent.Promise[String] = scala.concurrent.impl.Promise$DefaultPromise@7f36b021

scala> val cityFuture = cityPromise.future
cityFuture: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@7f36b021

scala> cityFuture.value
res11: Option[scala.util.Try[String]] = None
Once a Promise or Future is completed (either successfully with a result or failure with an Exception), we cannot rerun them. Doing so will throw an error as shown below:
scala> cityPromise.success("Hyderabad")
java.lang.IllegalStateException: Promise already completed.
Promise to write value to Future
scala> val cityPromise = Promise[String]()
cityPromise: scala.concurrent.Promise[String] = scala.concurrent.impl.Promise$DefaultPromise@7d07e6aa

scala> cityPromise.success("Hyderabad")
res13: cityPromise.type = scala.concurrent.impl.Promise$DefaultPromise@7d07e6aa

scala> cityPromise.future.value.get.get
res15: String = Hyderabad

scala>{ value => println(value) }
res16: scala.concurrent.Future[Unit] = scala.concurrent.impl.Promise$DefaultPromise@770d65c2
That is about Scala Future and Promise API with some simple examples.
NOTE:- Please support my Blog by clicking Ads to deliver more and more useful tutorials.
That’s it all about “Scala/Java Concurrency and Parallelism related Interview Questions and Answers”. We will discuss some more Scala Interview Questions in my coming posts.
Please drop me a comment if you like my post or have any issues/suggestions.
I love your valuable comments so much.