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("http://localhost:1010/MBeanServer"); using (INetMXConnectorServer connectorServer = NetMXConnectorServerFactory.NewNetMXConnectorServer(serviceUrl, server)) { connectorServer.Start(); using (INetMXConnector connector = NetMXConnectorFactory.Connect(serviceUrl, null)) { IMBeanServerConnection remoteServer = connector.MBeanServerConnection; //MBeanInfo metadata = remoteServer.GetMBeanInfo(name); object counter = remoteServer.GetAttribute(name, "Counter"); Console.WriteLine("Counter value is {0}", counter); //remoteServer.SetAttribute(name, "Counter", 1); //counter = remoteServer.GetAttribute(name, "Counter"); //Console.WriteLine("Counter value is {0}", counter); //int beanCount = remoteServer.GetMBeanCount(); //Console.WriteLine("MBean count is {0}", beanCount); //string defaultDomain = remoteServer.GetDefaultDomain(); //Console.WriteLine("Default domain is {0}", defaultDomain); //string domains = string.Join(", ", remoteServer.GetDomains().ToArray()); //Console.WriteLine("Registered domains: {0}", domains); //Console.WriteLine("Is {0} instance of {1}: {2}", name, typeof(SampleMBean).FullName, remoteServer.IsInstanceOf(name,typeof(SampleMBean).AssemblyQualifiedName)); //Console.WriteLine("Is {0} registered: {1}", name, remoteServer.IsRegistered(name)); //string beans = string.Join(", ", remoteServer.QueryNames(null, null).Select(x => x.ToString()).ToArray()); //Console.WriteLine("Registered MBeans: {0}", beans); //Console.ReadKey(); } } }
private static void InitializeMBeanServer() { _beanServer = MBeanServerFactory.CreateMBeanServer(); _beanServer.RegisterMBean(new RelationService(), RelationService.ObjectName); Sample sample1 = new Sample(); Sample sample2 = new Sample(); Sample sample3 = new Sample(); _beanServer.RegisterMBean(sample1, "Sample:type=Sample,id=1"); _beanServer.RegisterMBean(sample2, "Sample:type=Sample,id=2"); _beanServer.RegisterMBean(sample3, "Sample:type=Sample,id=3"); RelationServiceMBean relationSerice = NetMXProxyExtensions.NewMBeanProxy <RelationServiceMBean>(_beanServer, RelationService.ObjectName); relationSerice.CreateRelationType("Binding", new RoleInfo[] { new RoleInfo("Source", typeof(SampleMBean), true, false, 1, 1, "Source"), new RoleInfo("Destination", typeof(SampleMBean), true, false, 1, 1, "Destination") }); relationSerice.CreateRelation("Rel1", "Binding", new Role[] { new Role("Source", new ObjectName("Sample:type=Sample,id=1")), new Role("Destination", new ObjectName("Sample:type=Sample,id=2")) }); relationSerice.CreateRelation("Rel2", "Binding", new Role[] { new Role("Source", new ObjectName("Sample:type=Sample,id=1")), new Role("Destination", new ObjectName("Sample:type=Sample,id=3")) }); Uri serviceUrl = new Uri("net.pipe://localhost/MBeanServer"); _connectorServer = NetMXConnectorServerFactory.NewNetMXConnectorServer(serviceUrl, _beanServer); _connectorServer.Start(); }