Archive for category Advance

Serverless using Java

My colleague were just discussing about the new architecture serverless most of the time and out of curiosity I fiddle around with this term and learned what this really is? Then I found out that it is just a way to execute your normal functions and from URL and you do not need  your server to be online all the time which results in super cost effective unlike normal server where you pay for every month/hour/second of its availability. The term looks super easy to understand. Execute my function foo() when is called via HTTP protocol. The term serverless without any server is just for the developers but beneath this architecture there will still be a fully managed server who handles your request and warms up your code (jar file). So I came to think of demonstrating how to run your minimal functions as serverless . But before that lets learn some basics via image.


Serverless diagram

Java Serverless diagram

Long thing in short : If any POST request in /foo URI happen the Function handler will call to the appropriate function of a class which is predefined in serverless.yml. We developers do not have to worry about all those API endpoints handling because these are handled by serverless itself, this is the beauty of serverless. In an Amazon Web Service world serverless is handled from AWS Lambda service.

Now it is the time to catchup and write our very first and simple serverless project.



Create a new serverless maven  project


Edit some codes inside

You can directly override RequestHandler‘s handleRequest()method/function or you can create just simple method which is also supported for serverless function execution. The only difference is you have to use fully qualified Classname as well as the method name while mapping it to the URI in serverless.yml


Now there is one final piece of puzzle which is serverless.yml which will do the mappings of all functions to uri .

And it is just simple is that. You are ready for deploying your first serverless using simple Java class which will handle your HTTP request directly.  You can deploy your codes directly using your serverless command. But make sure you have proper AWS credentials and policy to deploy your code from commandline.

Once you deploy it the verbose log will look something like this.

Now it is time to do small testing from Postman .  As provided in the url : [POST]


AWS Lambda Serverless Endpoing test

AWS Lambda Serverless Endpoing test


It is quiet so easy isn’t it ? Just code what you want and deploy it. But there are some limitation of the serverless. It is not suitable for all kind of application and it definitely does not supersede the normal server deployment because of its nature and limits.

1. Maximum execution duration per request

We just cannot use request for long task like more than 5 minutes. AWS has a hard limit of 5 minutes for every request execution.


2. Memory resources limit

There are some limits of memory to be used by every single function . It is like 3008M in aws lambda as of now (2018-09-11).


3. Coldstart

Your function will actually sleep after unused for some minutes. When you request after the sleep time it need to warm up the server again which takes some seconds and it might not be good for those who wants to get the request instantly (realtime). There are some way which will keep your server warm all time described How to keep desired amount of AWS Lambda function containers warm


4. Payload size limit

You might not want to send a large data from your http request because there is a limit for request payload as well . As per AWS there is 6MB limit for payload however you can use event driven aws lambda execution for avoid sending payload directly to lambda.


5. Ephemeral disk capacity

You just cannot use your disk space more than 512 mb which is /tmp directory of server while you do any data processing or any process which involves usage of hard disk space.


After talking about the limitations I would still prefer this serverless for some of my application like generating the pdf invoices for customer, doing scheduled tasks and others. In next blog post I would talk about how to run serverless locally and we can discuss about the overall complication and solutions.

Stay cool , be happy and code  😉


Tags: , , , , ,

Lights in JavaFX 3D

It has been so long day that I have not blogged but today I am here with some new stuffs related to the JavaFX 3D. Before touching in JavaFX it is better to introduce some lights definition. There are many lights types but let not go more we are relating only two lights


  • JDK 8 EA build ver. 91 or later (or JDK8 General Release Version)

 Ambient Light 
An ambient light source represents a fixed-intensity and fixed-color light source that affects all objects in the scene equally. Upon rendering, all objects in the scene are brightened with the specified intensity and color. This type of light source is mainly used to provide the scene with a basic view of the different objects in it.

ambient lights javafx

Read the rest of this entry »

Tags: , , , , , ,

3d Object (Cube) Concept to Code Part 2

After all I am near to Christmas, My hands are shaking so cold: P. Today I’m writing about the post of how to create a 3d cube box in JavaFX. Well I’ve you have already read my previous post of how to create Cube in JavaFX using the technique I’ve described.


We’ll create here one function which can create a cube box using parameter of width. Even if we create a 3D in JavaFX, The Object will not look like a real 3D because there is absence of good Camera stuffs class. But hope these things will arrive very soon.

Here is the JavaFX function which can create the Cube3D
Read the rest of this entry »

Tags: , , , ,

3d Object (Cube) Concept to Code Part 1

Hi geeks,
After a long day I’m here again . Wow Christmas is coming near !! Hope I can blog more post before Christmas 🙂
Today I’m going to explain about the 3D Concepts. Well this post is not related to specific Java Language because in this post there will be no any talks about the language specific code. But we’ll be talking about codes in next part of this post. Before going to 3D Object we need to know what is the axis and rotation.

Read the rest of this entry »

Tags: , , , , , , ,

JavaFX Live View

I was playing with some of the screenshot stuffs in the JavaFX 2.2 and came up with idea of showing the image of the Operating system’s window stuffs in JavaFX ImageView and that was really easy to make via Java Robot API and JavaFX’s SwingFXUtils class. Thanks to the JavaFX teams 🙂

Ok here we go now . First we’ll look over how the algorithm goes for this task.

Flow of Screen capture in JavaFX


As you can see in above picture The portion of the Monitor is being screen captured by the Java Robot API . This give the BufferedImage Object of Java and then we convert them in to JavaFX Image using SwingFXUtils class. Now finally it’s  all in our hand to show that Image in appropriate way.
Read the rest of this entry »

Tags: , , , , , , ,