Hold on, everybody. We’re about to start. But before we get behind the wheel, let’s do a routine recap of the points we shared last time.


Last time we had a deep talk about JMX, the architecture of JMX understand seven, eight, eight, finally through code practice, to solve a series of questions, achieve remote dynamic modification of application parameters, so that online service upgrade, parameter tuning and other problems are no longer difficult.


Say say, the brain flash suddenly, past company of a small talk of the scene. That was an old code farmer who I thought was very successful. He shared his past with us. He probably said that they knew some skills at that time. If know, that next is to come to work tomorrow, because understand very few people; When the Spring Festival is near, I found that the online service is always down, so I rely on the restart to solve the problem temporarily. But the Spring Festival will be over. Then I thought of a temporary solution with another colleague: once the service finds the problem, it will send SMS notification and accept SMS instructions to complete the service restart.


Now why would they need a text message to reboot? No matter how much he shared the story, doping water not to talk about, with the current two old code farmers, one is the product director, one is the vice president, and I still in helpless pain ha ha of the masturbation code, I have to convince ah.


So, without further ado, let’s get to the point: how to restart the service? It’s 9012 now. How do you solve the same problem now?


We all know that engaged in programming, there is no silver bullet, the only silver bullet is to practice more, in fact, is familiar with the three hundred Tang poetry, can not write poetry will also sing, that might as well look at others how to achieve.


Pour out the Resin source code, although many people are the first time to meet with Resin, it doesn’t matter if you think it is Tomcat, as long as you can get through the two direction, whatever it is, mainly to realize the idea.


In the face of an open source project or technology wheel, I usually have the following tips, here are all the tips, please enjoy.


Tip 1: Use it



Run the source code first, take a look, use it, think about it. Import the project, be sure to do your homework, and then navigate to the application entry using the manifest file (which can be found in any more formal application).



Resin source code run when the need to pass in the parameter watchdog, in fact, support N command (not in-depth).



Visit http://127.0.0.1:8080/ to see if it started successfully?



Click /resin-admin to access resin monitoring management platform, the first login needs to configure the user name and password, the subsequent login can be directly, the successful page is as follows.



Click on the menu to play around, click on the Memory menu, and it looks like this, but where does the data come from? Questions aside, don’t get in the way of the functional experience.



Click on the Thread menu and it looks like this, but where does the data come from? Questions aside, don’t get in the way of the functional experience.



Click the WebApp menu, the effect is as follows, the key is that the corresponding Actions can actually complete the corresponding service start, stop, restart, god lalui, shocked everyone there is no.



Other menus can also be liberated, and there may be unexpected surprises.


Tip 2: Ask



Holding their own doubts, to explore, try to destroy the doubt in the heart. Please get JConsole to assist you, the console type in JConsole, connect to Resin process, inside Resin, take a peek.


Where did the data come from in the memory menu above? Sure enough, Resin customizes a MemoryMXBean with properties that correspond to the memory menu. Well, I guess that’s what happened. Do you get it? The ape fan who didn’t understand left a message backstage.



Where did the data from the thread menu above come from? Resin created a ThreadPoolMXBean with the same properties as the ThreadPoolMXBean.



When you click the WebApp menu, how do you start, stop, and restart the service to complete the corresponding restart, stop, and restart operations? Resin is still in accordance with the conventional design, custom definition of a WebAppMXBean, and provide start()/stop()/restart() and other operation methods, have to say that the design is very high-end.



Speaking of which, it might as well demonstrate the stop and restart function of the service, otherwise it is difficult to convince the public, click resin-Admin webApp menu again, the effect is as follows.



Back on the JConsole page, click stop() to stop the resin-Admin service and just look at the image.



At this point we go back to the administrative console page and, sure enough, the service is unavailable.



Just click start() in JConsole to start the service.



At this time we visit resin-admin management console page, can be accessed normally again, is really the rhythm of heaven.


Note: JConsole is used to see how many MXbeans are defined, but the start, Stop, and restart buttons on the page do exactly what JConsole does.


Tip 3: Write it down



Deep into any framework source code, log is an essential part, in order to facilitate the source process to string up, the key position must be printed belongs to their own style of log, it is best to play their own log, and then run up with a string of log process.



Move 4: Draw a picture


Can I draw class drawings? Comb through the relationships and see the big picture. If you use IDEA, it’s super easy to generate class diagrams. Select interface or class and right click menu Diagrams –> Show Diagram… (Please remember this operation, it will save you a lot of work.)



The result is clear and clear, a series of MXBeans come into view, and the inheritance relationship is similar to that of our log printing.


Is an Resin application server on such a thing, in fact, is really the following, really huge (picture is not clear, in fact, this is really not clear on the right, need to use high power glasses, complex a little hot eyes), but the implementation of the routine is the same, are a series of MXBean definition.



Can I also draw sequence diagrams? The answer is required if the IDEA is installed with the SequenceDiagram plugin, for example.




Tip 5: Guess

Go to http://127.0.0.1:8080/resin-admin/? Q =index&s=0

If you look with great concentration, you will find that the page of resin-admin is realized by PHP language. In fact, it is very simple to obtain the Q parameter in the request URL, and then directly display the corresponding page page. If the q parameter is empty, the summary page will be displayed by default.


For example, http://127.0.0.1:8080/resin-admin/? Q =memory&s=0 will display memory.page, which can be seen by accessing MBeanServer to find the corresponding MemoryMXBean and retrieve the corresponding value.



Move six: copy one copy



Can we use ideas to do that? The answer is yes, and I won’t go further today.


Well, today mainly with Resin source simple analysis, let us more in-depth understanding of JMX application; At the same time want to convey the face of the framework source code or technical wheel, usually I commonly used some of the methods, simply divided into six tricks: with a use, ask, remember, draw a picture, guess a guess, copy a copy, I hope you can help a little.


Well, today’s car to the station, there are a lot of application scenarios did not say, we still listen to the next decomposition, sincerely hope that a small ape spoke each share can help you a little bit.


Finally, if you feel a little help, please pay attention to the wechat public account “One Ape Small Talk” for more wonderful sharing.

Recommended reading:

Java Application Monitoring Tool JMX (1)

Java Application Monitoring Tool JMX (2)

Life depends on reflection, Java depends on generics

The art of making eye contact