If you do this in production, make sure that this won??™t lead to a memory
leak somewhere. Depending on your deployment scenario, this could cause huge amounts
of memory to be leaked. The proper way to avoid this is to save the runtime reference in a
WeakReference, and once that WeakReference returns null, deregister the MBean from the
MBean server. You can easily find how to do all that in the JavaDoc for Java.
Now it??™s time to start up the Rails application and try the MBean out. After the application
has started, run jconsole. Navigate to MBeans, and find the Rails entry in the left pane. Within
it you will have OperationControl, one or more numbers, and beneath each number an entry
called ???operations.??? Go to one of these, and you??™ll see the runner operation in the right pane.
Here you??™re free to try any valid Ruby code out. Because you have the whole Rails application
available, you can use it to add a new authorized user, test the sequence manager, or whatever
else you might feel like. To try it out, find out the names of all your users:
User.find(:all).map(&:name)
On my current installation, this returns the String '["Administrator", "Ola Bini"]'.
If you want to list sequences, just do it the same way as you would from the controller:
SequenceManager.list(@user)
This gives you a nasty-looking printout of each struct instance for every sequence, but
you get the idea.
Of course, letting access such as this lie around is a good way to get cracked, so make sure
you read up on how to secure your JMX server.
Pages:
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296