/// <summary>Register a listener for jobs life cycle notifications emitted by the server</summary> /// <param name="client">The JPPF client from which to get a JMX connection</param> public static void RegisterJobNotificationListener(JPPFClient client) { JMXDriverConnectionWrapper jmx = GetJMXConnection(client); AbstractMBeanStaticProxy jobProxy = new DriverJobManagementMBeanStaticProxy(jmx); jobProxy.AddNotificationListener(new MyJobNotificationListener(), "job notification"); }
/// <summary>Register a listener which forward node notifications via the driver</summary> /// <param name="jmx">holds the connection to the driver's JMX server</param> /// <param name="selector">specifies the nodes from which notifications are forwarded</param> /// <param name="mbeanName">the name of the node MBean for which notifications are forwarded</param> /// <param name="listener">the listener to register</param> /// <param name="handback">an arbitrary object provided when the listerner was registered</param> /// <returns>A unique id under which the listener is registered</returns> public static string RegisterFowrwardingNotificationListener(this JMXDriverConnectionWrapper jmx, NodeSelector selector, string mbeanName, BaseDotnetNotificationListener listener, object handback) { NotificationListener javaListener = new DotnetNotificationListenerWrapper(new DotnetNotificationDispatcher(listener, handback)); String id = jmx.registerForwardingNotificationListener(selector, mbeanName, javaListener, null, null); //Console.WriteLine("added forwarding notification listener " + listener + " to " + jmx + " with id=" + id); return(id); }
/// <summary>Print the number of nodes connected to the server</summary> /// <param name="client">The JPPF client connected to the server</param> public static void PrintNbNodes(JPPFClient client) { JMXDriverConnectionWrapper jmx = GetJMXConnection(client); java.lang.Integer n = jmx.nbNodes(); int nbNodes = (n == null) ? 0 : n.intValue(); Console.WriteLine("there are " + nbNodes + " nodes"); }
/// <summary>Obtain a JMX connection from a JPPF client</summary> /// <param name="client">The client to get the JMX connection from</param> /// <returns>An instance of <code>JMXDriverConnectionWrapper</code></returns> public static JMXDriverConnectionWrapper GetJMXConnection(JPPFClient client) { if (jmx == null) { // wait for a connection pool to be ready JPPFConnectionPool pool = client.awaitWorkingConnectionPool(); // wait until at least one JMX connection is available from the pool java.util.List list = pool.awaitJMXConnections(Operator.AT_LEAST, 1, true); // return the first available JMX connection jmx = (JMXDriverConnectionWrapper)list.get(0); } return(jmx); }
/// <summary>Register a listener for tasks completion notifications emitted by all the nodes</summary> /// <param name="client">The JPPF client from which to get a JMX connection</param> /// <returns>An id string assigned to the registered listener</returns> public static string RegisterTaskNotificationListener(JPPFClient client) { // name of the node task monitor MBean string mbeanName = JPPFNodeTaskMonitorMBeanStaticProxy.getMBeanName(); // only receive notifications from .Net-capable nodes ExecutionPolicy dotnetPolicy = new Equal("jppf.dotnet.bridge.initialized", true); NodeSelector selector = new ExecutionPolicySelector(dotnetPolicy); // register the forwarding listener with the driver JMXDriverConnectionWrapper jmx = GetJMXConnection(client); string listenerId = jmx.RegisterFowrwardingNotificationListener(selector, mbeanName, new MyTaskNotificationListener(), "task notification"); Console.WriteLine("registered task notifications listener with listenerId = " + listenerId); // return the listener id so it can be eventually removed later return(listenerId); }
/// <summary>Provision the specified number of slave nodes. /// This method forwards the provisioning request to all relevant nodes via the driver</summary> /// <param name="client">The JPPF client connected to the server</param> /// <param name="nbNodes">The number of slave nodes to provision</param> public static void ProvisionNodes(JPPFClient client, int nbNodes) { // we are invoking the remote provisioning mbeans string mbeanName = JPPFNodeProvisioningMBeanStaticProxy.getMBeanName(); // policy applied on master nodes with a .Net bridge initialized ExecutionPolicy masterPolicy = new Equal("jppf.node.provisioning.master", true).and(new Equal("jppf.dotnet.bridge.initialized", true)); NodeSelector masterSelector = new ExecutionPolicySelector(masterPolicy); // parameters to the MBean method java.lang.Object[] parameters = { new java.lang.Integer(nbNodes), null }; // Java signature of the remote MBean method to invoke java.lang.String[] signature = { "int", "org.jppf.utils.TypedProperties" }; // send the request via the forwarding mbean JMXDriverConnectionWrapper jmx = GetJMXConnection(client); JPPFNodeForwardingMBeanStaticProxy proxy = new JPPFNodeForwardingMBeanStaticProxy(jmx); proxy.forwardInvoke(masterSelector, mbeanName, "provisionSlaveNodes", parameters, signature); }