Suggestions on architecture to monitor services and databases - java

I am trying to make a monitoring system for JAVA web services. It would be a simple switch kind of system where based on the health of a service it would report 'RUNNING', 'CRITICAL' or 'UNSTABLE'. The challenge is integrating it with existing code. While calling an endpoint with the data would be the easiest, I am not too keen on going down that path because it would require too many changes to the source code. Instead I was looking at run-time injection. Your suggestions on coming up with an architecture would be very helpful. Thanks and let me know if you have questions.
EDIT: Tips on how to extend it to monitor stored procedures in an Oracle DB would be great too.

There is a common answer for such kind of question: just try JMX.
If you already use such frameworks like Spring - feel free to use Spring JMX there.
Aslo you can built your application into OSGi framework if it suits to you (here you can also use JMX layer for that).

Related

How/Where I can learn the structure of a real world Java web application with sample code and explanation

Please do not skip my question due to its length and also please read it completely so that you can know why I am stuck.
My problem in short : How/Where I can learn the structure of a real world Java web application with sample code and explanation
My problem in details : I know basics things like inheritance, logging , MVC etc. I have completed programming tutorials on these topics, but only after I started to do
some maintenance work of an application of a real world company, I realised that these basics and other things need to be properly and efficiently organised in an application. That application
have code to automatically log what values are send to data base for debugging purpose, code to automatically load different property files in different environments and
code to similar non business but essential functionalities I do not even know exist in the application. All that kind of codes for that application were already done and since it
was a maintenance project I only had to add new pages, so I did not know how these functionalities were implemented and what other similar non business functionalities exists
in the application.
Could you please let me know, Which book/tutorial/git hub/Video I have to learn to understand what non business functionalities needs to be present in a real world web application
and how that should be put together. I would like to see complete code for a small dummy application with all these codes with explanation that I can download and go through
each class by class to understand all these.
Can I call this architecture of the application or should I refer it as architecture of application at micro level ?
Thanks
If I understood you correctly, you are not looking for a language centric features; but a more comprehensive knowledge of the components of an enterprise application?.
Unfortunately they don't teach this skill in school. And there is a reason. The architecture of an application depends mainly on the business function. Each architecture differs with the type of business function it performs. Adding to this complexity, there is the cloud infrastructure architecture too. Both of these compliments each other.
Many of these are skills you will acquire on the job. You develop an intuition after reading many lines of codes for many years. However, you can advance your pace by following the stalwarts of the industry. One such guy is Martin Fowler. His book Patterns of Enterprise Application Architecture is a good start. He has compiled a list of best practices and architectural considerations you need to follow while designing an enterprise application.
Spring Framework Guru is a great resource for learning Spring, and building web applications. In particular, I would suggest you to go through the Spring Boot web application series. It's a step by step guide, and goes into all the aspects of building a web application in Spring, in a fairly detailed manner.
Links:
Bootstrapping a Spring boot application
Rendering Simple Pages using Thymeleaf (templating engine)
Adding a data layer with Spring Jpa and performing CRUD operations
Using Spring MVC to build a Controller and tying with the data layer
Setting up authentication (and authorization) with Spring Security
Going deeper into Spring Security with Auth Providers (optional)
The tutorials above will help you get started with the core ideas (and architecture) used in most web applications, and help you explore further.
One good option is the online courses platforms like Udemy, you could easily find courses like this:
https://www.udemy.com/course/spring-framework-5-beginner-to-guru .
This is a beginner course and it's full of good practices.
You can also find advanced courses:
https://www.udemy.com/course/spring-core-advanced-beyond-the-basics/

Differences between a java profiler and spring insight?

I am working on a java project which is based on Spring and Hibernate frameworks. Recently we have some performance issues and we want to have a deep visibility into the app. Currently we have Spring Insight on our test environment that helps us towards that. But I also want to know a bout the features of a java profiler that we can take benefit of that. I couldn't find a good source that explain what are the differences between a java profiler framework with spring insight. Can anybody explain the differences? Thanks.
For Spring Insight, I will say that I have used it with my Spring applications and its important prerequisite is that it will be deployed as a web application in TC Server. After installing and setting it up in a TC Server, I deployed the application on the TC Server instance and browsed to the Insight interface where I could monitor my application’s flow. It gave me a nice flow layout of the classes and methods. It showed me how much time the methods took to complete, I could see the values of input parameters as well as the return values.
Coming to your question I will suggest that choice of profiling tools totally depends on your requirement. If you have Spring based application the right choice is clearly the Spring Insight. It is free for development purposes, but your application needs to be deployed on the TC Server.
If you want more freedom in monitoring local and remote processes you should go for JProfiler or YourKit. These two can also assist the Spring Insight monitoring in your conquest in finding performance bottlenecks. JProfiler and YourKit also provides the monitoring of memory usage which Spring Insight does not provide.

What tech to use to build a very basic hotel booking type web-app?

I'm a newbie. :(
I've taken about 4 Java courses and written some simple apps. As part of a class, I wrote a order purchasing application with JDBC and JSP pages/servlets. The bummer about all this is that there wasn't much info in the class on using eclipse & such and it seems there are more efficient and modern ways of doing this now.
I want to keep learning and since my ski club has a need to streamline it's booking process (currently email), I thought I would see if I could write an application to do this. I think the right way to do this would be to write something that could support a webservices type interface, so I could eventually (maybe I'm getting ahead of myself) write a mobile app as well. I'm getting a bit confused by all the choices out there though as I don't understand well how the different layers fit together and what the best place is to start. So, to summarize:
1) Beginner level Java - would like to continue using it.
2) Want to build a simple hotel booking type app.
3) Would like a webservices (SOAP?) like interface to the front end
4) Open-source tools
FWIW: I'll be doing this on a macbook but could also do a linux VM. I also have my own hosted domain and mysql db I could setup there for testing.
I'd like it if someone could recommend an approach for me. Perhaps some tutorials or an online class that would get me closer to getting started? Pretend you are me. :)
Thanks!
Your plan seems pretty good.
I think this makes sense.
MySQL if you want to use a SQL DB
JSP/Servlets for the front-end; probably only JSP
JDBC and Hibernate for accessing the DB (unless you want to use a NoSQL DB like e.g. MongoDB); maybe only Hibernate really as you don't want to mess with the low-level JDBC API
MongoDB Java driver if you want to use MongoDB instead of a SQL DB
Tomcat to run your JSPs
I would suggest RESTful web services over SOAP web services, if you really need to use web services; REST is easier to implement and more lightweight
I guess that would be sufficient.
Use Spring ROO. It is good for an entry-level website and it doesn't required in-depth knowledge of all technologies enlisted. As you learn more you can replace components with your own.
http://projects.spring.io/spring-roo/
I would suggest -
UI - JSP, HTML , CSS
Database - You said you already have MySQL, which should be good for your use case.
Java Framework - Spring framework. This will give you out of the box support for rest service. Using spring will help you adhere to some good design principles without having to know them. As a newbie I would highly recommend to go with spring. I am not a big fan of SOAP. Unless that is imposed as a constraint I would not recommend SOAP.
Reference that could be helpful - http://docs.spring.io/docs/Spring-MVC-step-by-step/

GWT and Spring integration

I'm currently working on a specification for a web application which consist of a administration interface, and a set of web-services which will be consumed by parter websites.
I been playing around with GWT and it seems like an amazing fit for the administration interface, but at the same time, I would love to use the Spring framework to produce the REST based web-service API exposed by the application.
My plan is to create two separate web applications, one for the admin and one for the web-services. One set up for spring and the other with the GWT app. Obviously, I wish to share the domain model between the two applications, I'm guessing this should be fairly trivial to accomplish? I'm thinking just to keep it simple, implement the full domain model in the GWT client project, and simply setting the sourcepath of the web-service to include the domain model from the relevant folders in the GWT project.
Now, to my question. I'm sure somebody out there have done something similar to this, are there any potential pitfalls I should be aware of before starting out?
I got a fair amount of time set aside for this project, but I never actually used GWT before for anything "serious" I just played around with it out of personal interest and I'm fairly experienced in both Swing and Android UI development, so I'm confident I can mange to use it for the (very simple) UI. The "unknown" in this equation is sharing of a domain model. I cant imagine this being a problem, since the domain model will be just POJO's (using JDBC, but again, I cant really imagine this being a problem).
Also, are there better ways of integrating GWT and Spring than simply doing to separate web applications and sharing their domain model?
Why do you want to create two separate applications?
Create one, with a clearly separated application services tier. Expose this services via standard Spring annotations as webservices, and also expose access to this services via GWT requestfactory (unfortunately, as far as I know, currently requestfactory does not play nice with REST requests, mainly because their way of serialization). This approach results in only one entrance (facade) to your application and allows to use this facade in two different ways.
I've worked on several GWT+Spring projects - for standard cases development goes very fast, frameworks integrates very well. However, if you want to do some customization, e.g. introduce security based on spring security - you will need to do some hacks, such as overriding transport classes. Of course it takes some time, but results are very nice.
I would definitely recommend to take a look at Spring ROO sample applications (as far as I know, roo is partially developed by google guys).

How to make my Java Swing application a Client-Server application?

I have made a Java Swing application. Now I would like to make it a Client-Server application. All clients should be notified when data on the server is changed, so I'm not looking for a Web Service. The Client-Server application will be run on a single LAN, it's a business application. The Server will contain a database, JavaDB.
What technology and library is easiest to start with? Should I implement it from scratch using Sockets, or should I use Java RMI, or maybe JMS? Or are there other alternatives that are easier to start with?
And is there any server library that I should use? Is Jetty an alternative?
Given that you have the application already, perhaps the simplest thing to do is to identify the interface that you require between the client and server, and first of all to refactor your application to use that interface to talk between the back-end/front-end within the same process.
Then you can start to split this apart. A simple solution would be to split this apart using RMI (since you're talking Java objects and have Java method calls). Spring contains useful tools to simplify/automate the RMI exposure of interfaces.
For the notification requirement, a simple UDP multicast (or broadcast) would suffice.
Note that as soon as you split your application up, you have issues re. maintaining consistent views of data, managing timely updates, handling cases when the server is down, possible loading issues when you get lots of clients etc. In a sense, splitting the application up into a client and server is just the start of a new architecture process.
Mina is a good choice as a network application framework for building a simple server for this purpose - it's a much better option than using raw sockets.
http://mina.apache.org/
If you really need an application server then you could take look at JBoss. It also provides a remoting component (as an alternative to something like Mina):
http://www.jboss.org/jbossremoting
You probably won't have much need for Enterprise Java Beans though. In most cases a simple POJO based framework is more than sufficient - you could tie this altogether with a dependency injection framework such as Guice:
http://code.google.com/p/google-guice/
or Spring. Keep it simple, don't use a J2EE server unless you really need to. Hope that helps.
This is much of what J2EE does, but it's a whole new learning curve because they have pre-solved many of the problems you will run into and many you may not and therefore add on a lot of new technologies.
But at it's most basic, J2EE answers just that question.
I worked in a project like this. We implemented Client-Side Swing and Server side with J2EE. We used EJB,Stateless beans and Message Driven Beans.Also I have been in a device tracking, management project. Our clients were trucks+Swing users and We have used Servets+TCP/UDP,Apache Mina framework to handle and keep connections.
I have been working in Java Swing Client/Server applications for almost 3 years. I would suggest you to go for RMI/EJBs. The initial application that we developed was doing this using RMI/EJB for client-server communication with WebLogic being the server.
But we later found out that there are lot of "browser-like" features to be included to the application such as session-timeout etc., So, we used the BrightSide Framework which wraps the RMI calls through HTTP. One more enhancment we made is that we replaced Weblogic with the open source JBoss server.
The wrapping of calls with HTTP will become very handy and you can make your swing applications really rich. Later, when the situation demands for you to use a website strictly, you can deploy your swing using jnlp.
Hope this helped.

Categories