SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 282 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"


Listing 10-3. src/com/bb/rails/RailsOperationMBean.java
package com.bb.rails;
public interface RailsOperationMBean {
String runner(String command);
}// RailsOperationMBean
CHAPTER 10 ?–  AN EJB-BACKED RAILS APPLICATION 194
This MBean takes a command as a String, and returns a String that describes the result
of this operation. The implementation looks like the one in Listing 10-4.
Listing 10-4. src/com/bb/rails/RailsOperation.java
package com.bb.rails;
import java.util.List;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;
public class RailsOperation implements RailsOperationMBean {
private Ruby runtime;
private int number;
private static int runtimes = 0;
public RailsOperation(IRubyObject obj) throws Exception {
this.runtime = obj.getRuntime();
synchronized(RailsOperation.class) {
this.number = runtimes++;
}
List servers = MBeanServerFactory.findMBeanServer(null);
MBeanServer server = (MBeanServer) servers.get(0);
ObjectName on = new ObjectName(
"Rails:Name=OperationController,Number=" +
this.number);
server.registerMBean(this,on);
}
public String runner(String command) {
return runtime.evalScriptlet(command).callMethod(
runtime.getCurrentContext(),"inspect").toString();
}
}// RailsOperation
Now, as I said before, you??™ve already seen everything that happens in this class. You have a
static field containing a number of runtimes in the same process.


Pages:
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294