Friday, July 28, 2017

Java - Calculate Total Time Elapsed using Java5 or higher



Java - How to calculate the total Time elapsed for a java method.

It is a standard requirement in a lot Java components/applications to find out the total time a method has taken to execute the call.

Though there are several 3rd party libraries (Spring MethodInterceptor,  java-InvocationHandler/DynamicProxy, and AspectOrientedProgramming) that offer method interceptor feature where the time can can be tracked.
Looking at greater need of this requirement of calculating precise time (NanoSeconds..) that a method spent on, Java5 has introduced a new TimeUnit class.

Please see below example for reference

public static String calculateTotalTimeElapsed(long startNanoSec, long endNanoSec) {
long difference = endNanoSec - startNanoSec;
String totalTimeString = String.format("%d Hours, %d Min, %d Sec, %d Millis, %d Micro, %d Nano",
TimeUnit.NANOSECONDS.toHours(difference), TimeUnit.NANOSECONDS.toMinutes(difference),
TimeUnit.NANOSECONDS.toSeconds(difference), TimeUnit.NANOSECONDS.toMillis(difference),
TimeUnit.NANOSECONDS.toMicros(difference), TimeUnit.NANOSECONDS.toNanos(difference));
return totalTimeString;
}


       public static void main(String args[]){ 
               long timeBefore1 = System.nanoTime();
               //TODO: call any other function (db or resource intensive)
               String timeString = calculateTotalTimeElapsed(timeBefore1, System.nanoTime());
              System.out.println("Method has taken  "+timeString);
       }
     

output:
o Hours, 1 Min, 2 Sec, 400 Millis, 298 Micro, 12345 Nano.



Thursday, May 4, 2017

My Desktop background

Recently I've been thinking to come up with collection of best quotes that can keep reminding and motivating me everyday at work.

As Health, Finance and Career are my current priorities, I've come up with the following collection.

Feel free to use if you like.


Thursday, April 13, 2017

My view on Microservices Architecture (MSA)


It is a new architectural pattern to Design & Develop application(s) into smaller and manageable modular services that can be built using APIs/services with modern languages/frameworks. 

Though this is more popular and fashionable idea, is not a very new in Architects and Designers world when creating large and monolithic application. They have been contemplating to adopt this to build more scalable and maintainable solutions. Their thoughts were always limited by the availability of tools and technologies for implementation and new operational complexities.

Why MSA and What is the reason behind the popularity?
  • The emergence of lightweight REST integration (API Management) over popular SOAP (SOA-ESB) systems.
  • The emergence of new languages/technologies/frameworks that allow a few solutions can be developed with modern languages/frameworks. The replacement of these solutions can also be built more quickly if they are not addressing the requirements.
  • DevOps: Advancement in hardware where a software (Hypervisor) can be used to automate infrastructure, scaling the instances as needed and utility computing. 
  • Virtualization and Docker/Container management.
  • Change in how systems are communicated with Datastore, As there are more reads of data over writes; the gaining popularity of CQRS (Command Query Responsibility Segregation) with Event Sourcing over CRUD (Create Read Update and Delete) operations.
  • Emergence of new DBMS systems (RDBMS, SQL, NO-SQL, Graph SQL) etc..
  • Different interfaces (Desktops, Hand held devices with Mobility) to access the solutions with different user experience built on the same back-end solutions.
  • Growing popularity in Systems working on Distributed Architecture.
Characteristics:
The API brings standardization of service development and its accessibility.
It promotes to develop, build and deploy the pieces (modules) of software independently and also offers scalability in deployment.
It is also a new architecture & design style to migrate Monolithic application (one big single application with lot of components without modularity) into more smaller services that are designed, developed, built and deployed independently.
It offers re-usability of these smaller modules (services) as this is essential to Enterprise with shared services organization.
It prefers BASE (BasicallyAvailable, SoftState and Eventually Consistent) transactions over ACID (Atomicity,Consistency,Isolation, Durability) in Distributed Architecture.
It prefers CQRS (Command Query Responsibility Segregation) with ES (Event Sourcing) over CRUD operations as there are more Reads than Writes.

Problems of Monolithic:
Code complexity and maintainability
Deployment becomes the bottleneck
Fear to change once the asset is grown big enough to make changes and regression-impacts.
Lack of ownership as it is
One size doesn’t fit all (ex: relational DB)
Hard to scale out, though limited scale up is possible.

Benefits of Microservices:
  • Speed
    • Faster development and deployment
    • Polyglot
  • Innovation
    • Autonomy of teams, culture of change
    • Ownership and DevOps culture
  • Quality
    • Reusability & more maintainable code
    • Better scaling and optimizations
    • Failure Isolation and Resilience
Disadvantages
  • Overhead or Complexity of Communication in Development, Deployment and Operational Management. Some Cloud vendors (AWS) have addressed some of these solutions with tools.
  • Fairly new concept. Challenges in Finding experienced resources in market and Enterprise adoption.
  • Change of mindset is required to adopt to realize the benefit on ease of doing.
  • Technology stack is evolving fast: Determining when they are ready for Enterprise.
  • Investment overhead of both new API and ESB in large enterprises.
Though the Tier-1 technology companies (ex. FAANG) which can repeatedly re-invest in re-writing their popular solutions on new and modern architectures to offer new experience to customers, it is fair to say that the Tier-2 and organizations where IT is supporting the other business would mostly wait and see until the tools and practices are stable and technology becomes enterprise ready.

The startups and smaller organization can always venture into as their size, existing and limited investments would allow them to invest in these new areas.
         

Thursday, March 23, 2017

Plan for TOGAF9.1

Plan for TOGAF 9.1


Preparation Resources:
  1. Read preparation plan at http://softwarearchitect.ca/the-four-week-plan-for-togaf-foundation/?utm_content=educational&utm_campaign=2015-11-03&utm_source=email-sendgrid&utm_term=58935&utm_medium=312662
  2. Read others experience from http://www.selikoff.net/2013/04/09/jeannes-togaf-foundation-cert-in-3-weeks-experiences/
  3. Read preparation from http://abhishrek.blogspot.com/2011/03/togaf-9-certification-preparation-tips.html
  4. https://setandbma.wordpress.com/2011/05/16/togaf-preparation-aid-for-part-2/
Materials:
  1. Materials  from https://quizlet.com/subject/Togaf/    
  2. https://quizlet.com/27682126/togaf-9-foundation-core-concepts-flash-cards/
  3. Read the 'ADM cheat sheet' of 'Scott Duffy'  PDF.  Sign up for free PDF at http://softwarearchitect.ca/
  4. Cheat sheets (2) from http://yaathirigan.blogspot.in/2013/03/togaf-prep-material.htm    a. http://yaathirigan.blogspot.in/search/label/Cheatsheet
  5. Go through  http://wiki.glitchdata.com/index.php?title=TOGAF
  6. Check Resources  section/table at http://www.selikoff.net/2013/04/09/jeannes-togaf-foundation-cert-in-3-weeks-experiences/
  7. TOGAF input/output PDF at  https://dl.dropboxusercontent.com/u/1700928/TOGAF/TOGAF9%20Input%20Output.pdf
  8. Read the TOGAF official document from OpenGroup.  http://pubs.opengroup.org/architecture/togaf9-doc/arch/chap01.html
  9. Read Exam study Guide at https://nikansell.files.wordpress.com/2010/12/togaf_9_exam_study_guide.pdf
  10. Go through https://chriseaton.wordpress.com/2010/09/08/togaf-9-exam-review-worksheets/
  11. Go through http://blog.goodelearning.com/togaf/passing-exam-top-ten-tips-togaf-certification/
  12. https://www.goodelearning.com/downloads/enterprise-architecture/how-well-do-you-know-the-adm
  13. https://www.linkedin.com/pulse/mindmap-togaf-v91-jagadish-chichria   
  14. Read the MindMap http://1drv.ms/1WvYO4N 
  15. Buy the PART 1 course at https://www.udemy.com/togaf-enterprise-architect/learn/ and download all Videos.
  16. Buy the PART 2 course at https://www.udemy.com/togaf-part2/learn/#/ and download all Videos.
  17. https://dl.dropboxusercontent.com/u/1700928/TOGAF/TOGAF9%20Input%20Output.pdf
Mock Exams:
  1. Mock Exam at http://hexopus.com/togaf-study-guide/togaf-9-foundation-quiz/
  2. Mock Exams at http://theopenarch.com/   http://theopenarch.com/81-tests/72-togaf-9-exam-tests.html
  3. Mock exams at http://www.aiotestking.com/the-open-group/
  4. Mock exams at http://www.testsnow.net/list/789/1.html

  5. Sample Exams from http://wiki.glitchdata.com/index.php?title=TOGAF_Certification
  6. Go through TOGAF 9 Scenario questions: https://chriseaton.files.wordpress.com/2009/10/togaf-9-scenario-questions.pdf
  7. Go through TOGA 9 sample questions at https://chriseaton.files.wordpress.com/2009/08/togaf-9-multiple-choice-questions.pdf

Private Repositories, Not available to Public
 Modeling Tools:
  1. EA  at http://www.sparxsystems.com/products/ea/index.html
  2. https://www.modeliosoft.com/en/modules/togaf-architect.html
  3. http://www.togaf-modeling.org/
  4. Abacus at http://www.avolutionsoftware.com/products/
  5. http://www.aprocessgroup.com/atpl/