| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!-- |
| 3 |
~ Copyright 2009-2013 Roland Huss |
| 4 |
~ |
| 5 |
~ Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
~ you may not use this file except in compliance with the License. |
| 7 |
~ You may obtain a copy of the License at |
| 8 |
~ |
| 9 |
~ http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
~ |
| 11 |
~ Unless required by applicable law or agreed to in writing, software |
| 12 |
~ distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
~ See the License for the specific language governing permissions and |
| 15 |
~ limitations under the License. |
| 16 |
--> |
| 17 |
|
| 18 |
<chapter id="architecture"> |
| 19 |
<title>Architecture</title> |
| 20 |
<para> |
| 21 |
The architecture of Jolokia is quite different to that of JSR-160 |
| 22 |
connectors. One of the most striking difference is Jolokia's |
| 23 |
typeless approach. |
| 24 |
</para> |
| 25 |
<para> |
| 26 |
JSR-160, released in 2003, has a different design goal than |
| 27 |
Jolokia. It is a specification with which a client can transparently |
| 28 |
invoke MBean calls, regardless whether the MBean resides within a |
| 29 |
local or remote MBeanServer. This provides a good deal of |
| 30 |
comfort for Java clients of this API, but it is also dangerous |
| 31 |
<emphasis>because</emphasis> it hides the remoteness of JMX |
| 32 |
calls. There are several subtle issues, performance |
| 33 |
being one of them. It <emphasis>does</emphasis> matter whether a |
| 34 |
call is invoked locally or remotely. A caller should at least be |
| 35 |
aware what happens and what the consequences are. On the other |
| 36 |
side, there are message passing models which include remoting |
| 37 |
explicitly, so that the caller <emphasis>knows</emphasis> from |
| 38 |
the programming model that she is calling a potentially expensive |
| 39 |
remote call. This is probably the main reason why RMI (the default |
| 40 |
protocol stack of JSR-160 connectors) lost market share to |
| 41 |
more explicit remote protocols. |
| 42 |
</para> |
| 43 |
<para> |
| 44 |
One problem with JSR-160 is it implicit reliance on RMI and its |
| 45 |
requirement for a complete (Java) object serialization mechanism |
| 46 |
for passing management information over the wire. This closes the |
| 47 |
door for all environments which are not Java (or more precisely, JVM) |
| 48 |
aware. Jolokia uses a typeless approach, where some sort of |
| 49 |
lightweight serialization to JSON is used (in both directions, but |
| 50 |
a bit <emphasis>asymmetrically</emphasis> in its capabilities). Of course |
| 51 |
this approach has some drawbacks, too, but also quite some |
| 52 |
advantages. At least it is unique in the JMX world ;-). |
| 53 |
</para> |
| 54 |
|
| 55 |
<section id="agent-mode"> |
| 56 |
<title>Agent mode</title> |
| 57 |
<para> |
| 58 |
<xref linkend="fig-architecture-overview"/> illustrates the |
| 59 |
environment in which Jolokia operates. The agent exports on the |
| 60 |
frontside a JSON based protocol over HTTP that gets bridged to |
| 61 |
invocation of local JMX MBeans. It lives outside the JSR-160 |
| 62 |
space and hence requires a different setup. Various techniques |
| 63 |
are available for exporting its protocol via HTTP. The most |
| 64 |
prominent being to put the agent into a servlet container. This |
| 65 |
can be a lightweight one like Tomcat or Jetty or a full-blown |
| 66 |
Java EE Server. Since it acts like a usual web application the |
| 67 |
deployment of the agent is well understood and should pose no |
| 68 |
entry barrier for any developer who has ever dealt with Java web |
| 69 |
applications. |
| 70 |
</para> |
| 71 |
|
| 72 |
<figure id="fig-architecture-overview"> |
| 73 |
<title>Jolokia architecture</title> |
| 74 |
<mediaobject> |
| 75 |
<imageobject> |
| 76 |
<imagedata fileref="architecture.png"/> |
| 77 |
</imageobject> |
| 78 |
</mediaobject> |
| 79 |
</figure> |
| 80 |
|
| 81 |
<para> |
| 82 |
But there are more options. Specialized agents are able to use an OSGi |
| 83 |
HttpService or come with an embedded Jetty-Server in case of the |
| 84 |
Mule agent. The JVM agent uses the HTTP-Server included |
| 85 |
with every Oracle JVM 6 and can be attached dynamically to any |
| 86 |
running Java process. Agents are described in detail in <xref |
| 87 |
linkend="agents"/>. |
| 88 |
</para> |
| 89 |
<para> |
| 90 |
Jolokia can be also integrated |
| 91 |
into one's own applications very easily. The <literal>jolokia-core</literal> |
| 92 |
library (which comes bundled as a jar), includes a servlet |
| 93 |
which can be easily added to a custom application. <xref |
| 94 |
linkend="agent-war-programmatic"/> contains more information |
| 95 |
about this. |
| 96 |
</para> |
| 97 |
</section> |
| 98 |
|
| 99 |
<section id="proxy-mode"> |
| 100 |
<title>Proxy Mode</title> |
| 101 |
<para> |
| 102 |
Proxy mode is a solution for when it is impossible to deploy |
| 103 |
the Jolokia agent on the target platform. For this mode, the |
| 104 |
only prerequisite for accessing the target server is a JSR-160 |
| 105 |
connection. Most of the time this happens for political reasons, |
| 106 |
where it is simply not allowed to deploy an extra piece of |
| 107 |
software or where doing so requires a lengthy approval process. |
| 108 |
Another reason could be that the target server already |
| 109 |
exports JMX via JSR-160 and you want to avoid the extra step of |
| 110 |
deploying the agent. |
| 111 |
</para> |
| 112 |
|
| 113 |
<para> |
| 114 |
A dedicated proxy servlet server is needed for hosting |
| 115 |
<literal>jolokia.war</literal>, which by default supports both |
| 116 |
the <emphasis>agent mode</emphasis> and the <emphasis>proxy |
| 117 |
mode</emphasis>. A lightweight container like Tomcat or Jetty is |
| 118 |
a perfect choice for this kind of setup. |
| 119 |
</para> |
| 120 |
<para> |
| 121 |
Figure <xref linkend="fig-architecture-proxy"/> describes a typical setup for the proxy mode. A |
| 122 |
client sends a usual Jolokia request containing an extra section |
| 123 |
for specifying the target which should be queried. All routing |
| 124 |
information is contained in the request itself so that the proxy |
| 125 |
can act universally without the need of a specific |
| 126 |
configuration. |
| 127 |
</para> |
| 128 |
|
| 129 |
<figure id="fig-architecture-proxy"> |
| 130 |
<title>Jolokia as JMX Proxy</title> |
| 131 |
<mediaobject> |
| 132 |
<imageobject> |
| 133 |
<imagedata fileref="proxy.png"/> |
| 134 |
</imageobject> |
| 135 |
</mediaobject> |
| 136 |
</figure> |
| 137 |
|
| 138 |
|
| 139 |
<para> |
| 140 |
Having said all that, the proxy mode has some limitations which are |
| 141 |
listed in <xref linkend="proxy"/>. |
| 142 |
</para> |
| 143 |
<para> |
| 144 |
To summarize, the proxy mode should be used only when |
| 145 |
required. The agent servlet on its own is more powerful than the |
| 146 |
proxy mode since it eliminates an additional layer adding to the |
| 147 |
overall complexity and performance. Also, some features like |
| 148 |
merging of MBeanServers are not available in the proxy mode. |
| 149 |
</para> |
| 150 |
</section> |
| 151 |
</chapter> |