Java – Technical Blogs http://www.easywaytech.com/blog Just another WordPress site Tue, 11 Dec 2018 09:44:51 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.2 Play Framework http://www.easywaytech.com/blog/index.php/2016/09/23/play-framework/ http://www.easywaytech.com/blog/index.php/2016/09/23/play-framework/#respond Fri, 23 Sep 2016 11:23:40 +0000 http://www.easywaytech.com/blog/?p=101 For one of our projects, we used Play framework for web app implementation. It was easy to learn Play framework given my background of working with Maven, Tomcat and Eclipse style implementations. Play framework website has clear documentation for installation and usage. Play supports Scala and Java, but we have used it for Java app development.

Why is it developer friendly?

    • Easy installation: Download, extract Activator and then add Activator to the system path. That is all! Play is ready to use. An Activator is nothing but combination of SBT (a build tool) plus a means of downloading project templates (like Maven archetypes) and a web interface for managing those projects. Activator also acts as a lightweight server that runs apps. The applications built using Play Framework can also be deployed to any servlet container, like Tomcat.
    • Easy Project Creation: Creating a project based off a template is very easy. We can create a template either from Activator’s Web Interface or directly from the command line.
    • Easy Execution: Play has an easy to use “development mode” that will let you make changes to code. You can see your results immediately on the page as there is no need to recompile and restart the server.
    • Easy IDE Support: With a simple command “activator eclipse”, we can get support for Eclipse IDE.
    • Easy Http Routing: HTTP routing is very easy with the built-in HTTP router, i.e., conf/routes file. The router is the component in charge of translating each incoming HTTP request into an Action.
    • Easy database schema synchronization: We had two teams, off-shore and on-site working on this project. During development, each team member made updates to the database schema. To make it easier for integrating development, we used evolutions and evolution scripts. When the developer pulls latest code and runs the app, Play checks if there are any database updates. Play updates the developer about any changes and provides an option to execute evolution scripts.
    • It comes with type safety: In Play, the compiler checks parts of the code for type safety. This is not only useful for detecting mistakes early in the development process, but it also makes it a lot easier to work on large projects with many developers.
    • SBT Awareness: I was aware of Maven and ANT build tools. By using Play framework, I got a chance to build using SBT. SBT is a build tool for Scala and Java, similar to POM in Maven. The build.sbt file defines settings for the project.  We can also customize the settings for a project.
    • Easy JPA integration: There is no built-in JPA implementation in Play. We can choose any available implementation. We have used Hibernate, and we achieved it by adding dependency in ‘build.sbt’. Clear instructions are available on the Play website.

      Sample

      libraryDependencies ++= Seq(
       javaJpa, "org.hibernate" % "hibernate-entitymanager" % "3.6.10.Final"exclude("javassist","javassist")
       )
]]>
http://www.easywaytech.com/blog/index.php/2016/09/23/play-framework/feed/ 0
AngularJS Framework http://www.easywaytech.com/blog/index.php/2016/07/11/angularjs-framework/ http://www.easywaytech.com/blog/index.php/2016/07/11/angularjs-framework/#respond Mon, 11 Jul 2016 05:48:26 +0000 http://www.easywaytech.com/blog/?p=29 We have many frameworks like JQUERY, Angular JS, Mustache, etc., in JavaScript. Based on the project need, I had an opportunity to work on AngularJS framework. Based on the advantages of Angular JS framework, I have extended its usage to other projects.

Why AngularJS?

  • Single Page Application: We can build a single page application by using RouteProviders or StateProviders. o RouteProviders – We can load all the dependencies (i.e., js, css) in html and can shift to all the other pages through routing o StateProviders – We can load dependency for a state and can shift to all the other pages through state routing.
  • MVC Support: As it supports MVC framework, we can manage manipulations easily in html and JS files.
  • Data Models: It is very easy to show data model by using “ng-repeat” without any coding in JavaScript and we can handle it in html itself. We can show the whole response of JSON from API as expected through ng-repeat.
  • Directives: By using directives, we can create customized tags and use it anywhere in the app. We can include any html page directly by using inbuilt directive “ng-template.” We have created customized directives like:

        o focusDiv – to focus on a particularDiv
           Example:-

appName.directive('focusMe',function() {
	return {
		link: function(scope, element, attrs) {
			var model = $parse(attrs.focusMe);
			scope.$watch(model, function(value) {
				if(value === true) {
					$timeout(function() {
						element[0].focus();

					});
				}
			});
		});
	}
});

                     We can use in html as <inputng-model=’testId’ focus-me=’testId’>

        o customPopover – to show popup data by loading dynamically from API response
        o leftMenu/topMenu – to load left/top menu html into main page
           Example:-

 appName.directive('topmenu', function() {
	return {
		restrict: 'E',
		templateUrl: 'pages/top-menu.html',
		replace: true
	}
});

                      We can use in html as <topmenu></topmenu>

  • Events:We have built-in events and we can create customized events by using directives. Built-in Events including Mousedown, ngMouseenter, ngClick, ngDblClick ,ngChange, ngKeyDown, etc. We have created events for an element in directives as draggable, click, keypress, focus, etc.

        Example:-

appName.directive('eventsdirective', function() {
	return {
		restrict: 'A',
		replace: true,
		link: function(scope, element, attrs) {
			element.draggable({
				cursor: "move",
			})
			element.bind('mouseover', function() {
				//we can do whatever we need in mouseover here
			});
		}
	};
});

                     We can use in html like <div eventsdirective></div> 

  • Filters: We can create our own filters or we can use built-in filters by using pipe character followed by the filter. Built-in Filters include Filter, Currency, Date, Lowercase, Uppercase, JSON, Number, OrderBy, LimitTo, etc. We have created filters to filter data with atleast one field, i.e.,

        o searchFilter – to filter rows in a list, add filtername followed by fields to search.    

           Example:-

(ng - repeat = "listObj in myList =
	(myListBackup | menuFilterCustomSearch: myListBackup: filed1: field2)")

         o menuFilterCustomSearch is my custom directive name where it filters based on field1 and field2 values

  • Services: We can create our own services or we can use built-in services by injecting in any controller. Built-in Services include $parse, $timeout, $interval, $window, $location, $cookies, etc.
  • Data Binding: We are able to bind html elements through js easily by using scope to change any element value or any input field value,like $scope.modelName = value.             

        Example:-
                            <div>{{modelValue}}</div>
                            <div ng-bind=’modelValue’></div>
                         We can bind value to div from controller as $scope.modelValue = ‘test’

  • Less code and more functionality
  • It supports all major browsers and smart phones including Android, IOS based phones/tablets
  • It is an ideal partner with any server technology

]]> http://www.easywaytech.com/blog/index.php/2016/07/11/angularjs-framework/feed/ 0 Need for Microservices http://www.easywaytech.com/blog/index.php/2016/06/20/need-for-microservices/ http://www.easywaytech.com/blog/index.php/2016/06/20/need-for-microservices/#respond Mon, 20 Jun 2016 12:45:42 +0000 http://www.easywaytech.com/blog/?p=15 Microservices architecture is a concept that supports agile development and delivery of complex/large applications. Let’s see how it is different from usual Monolithic, SOA architectures.

A Monolithic architecture is a method of developing applications where the front-end UI, core of the application business logic and database layer are implemented in a single application. This method is more focused on a modular architecture and is very simple to deploy and test. It makes horizontal scaling easier by having multiple copies of application behind a load balancer, but the application size keeps on growing along with the features added to it which makes scaling, agile development and continuous deployment a bit complex.

This is where Microservices comes in handy by tackling all these complexities by decomposing the modules into small individual services which can be hosted separately. Each microservice is aligned to a specific business function. Each backend service exposes a REST API and most services consume APIs provided by other services.

By this method, we can apply scaling to each independent microservice at the scale it needs. Also instead of sharing a single database schema through the whole application, each service can have a separate schema as it ensures loose coupling.

Benefits of Microservices

  • Each service can be developed and deployed independently of other services – easier to deploy new versions of services frequently
  • Easier to scale development. It enables you to organize the development effort around multiple teams
  • A simpler, lightweight service

We use AWS Elastic Compute Cloud (EC2) in our organization to deploy and scale our applications using Microservices architecture. We use the following libraries built by Netflix to develop a Microservice in JAVA:

  • Ribbon – Used for Load balancing and it gives support for multiple protocol (HTTP, TCP, UDP) in an asynchronous and reactive model
  • Hystrix – This provides Latency and Fault Tolerance for rapid recovery. It also provides thread and semaphore isolation with circuit breakers
  • Archaius – It is used for dynamic configuration and typed properties. It achieves high throughput and Thread safe configuration operations
  • Eureka – It is used for Service Discovery and load balancing at middle-tier

To summarize, the Microservices architecture pattern is a better choice for complex, evolving applications despite the implementation challenges.

]]> http://www.easywaytech.com/blog/index.php/2016/06/20/need-for-microservices/feed/ 0