Click here to Skip to main content
15,886,519 members
Articles / Programming Languages / C#

NetMX - a JMX port to the .NET world

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
10 Mar 2008LGPL34 min read 39.5K   268   11  
An introduction to NetMX - a lightweight .NET management solution.
using System;
using System.Collections.Generic;
using System.Text;
using NetMX;
using NetMX.Remote;
using System.Security.Principal;

namespace RemotingDemo
{
	class Program
	{
		static void Main(string[] args)
		{
			AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
			IMBeanServer server = MBeanServerFactory.CreateMBeanServer();
			Sample o = new Sample();
			ObjectName name = new ObjectName("Sample:");
			server.RegisterMBean(o, name);
			Uri serviceUrl = new Uri("tcp://localhost:1234/MBeanServer.tcp");

			using (INetMXConnectorServer connectorServer = NetMXConnectorServerFactory.NewNetMXConnectorServer(serviceUrl, server))
			{
				connectorServer.Start();

				using (INetMXConnector connector = NetMXConnectorFactory.Connect(serviceUrl, null))
				{
					IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

					remoteServer.AddNotificationListener(name, CounterChanged, null, null);

					object counter = remoteServer.GetAttribute(name, "Counter");

					Console.WriteLine("Counter value is {0}", counter);

					remoteServer.SetAttribute(name, "Counter", 5);
					counter = remoteServer.GetAttribute(name, "Counter");

					Console.WriteLine("Now, counter value is {0}", counter);

					counter = remoteServer.Invoke(name, "AddAmount", new object[] { 5 });
					counter = remoteServer.GetAttribute(name, "Counter");

					Console.WriteLine("Now, counter value is {0}", counter);

					counter = remoteServer.Invoke(name, "ResetCounter", new object[] { });
					counter = remoteServer.GetAttribute(name, "Counter");

					Console.WriteLine("Now, counter value is {0}", counter);

					Console.ReadKey();
				}
			}
		}
		static void CounterChanged(Notification notification, object handback)
		{
			Console.WriteLine("Counter changed! New value is {0}", notification.UserData);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer (Senior) VSoft
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions