static void Main(string[] args) { var connectorServerFactory = new RemotingConnectorServerFactory(100, new NullSecurityProvider()); var connectorFactory = new RemotingConnectorFactory(new NotificationFetcherConfig(true, TimeSpan.FromSeconds(1))); IMBeanServer server = MBeanServerFactory.CreateMBeanServer(); Sample o = new Sample(); ObjectName name = new ObjectName("Sample:a=b"); server.RegisterMBean(o, name); Uri serviceUrl = new Uri("tcp://localhost:1234/MBeanServer.tcp"); using (INetMXConnectorServer connectorServer = connectorServerFactory.NewNetMXConnectorServer(serviceUrl, server)) { connectorServer.Start(); using (INetMXConnector connector = connectorFactory.Connect(serviceUrl, null)) { IMBeanServerConnection remoteServer = connector.MBeanServerConnection; remoteServer.AddNotificationListener(name, CounterChanged, null, null); Console.WriteLine("******"); MBeanInfo info = remoteServer.GetMBeanInfo(name); Console.WriteLine("MBean description: {0}", info.Description); Console.WriteLine("MBean class name: {0}", info.ClassName); foreach (MBeanAttributeInfo attributeInfo in info.Attributes) { Console.WriteLine("Attribute {0} ({1}) [{2}{3}]: {4}", attributeInfo.Name, attributeInfo.Description, attributeInfo.Readable ? "r" : "", attributeInfo.Writable ? "w" : "", attributeInfo.Type); } foreach (MBeanOperationInfo operationInfo in info.Operations) { Console.WriteLine("Operation {0} ({1}) [{2}]", operationInfo.Name, operationInfo.Description, operationInfo.Impact); } Console.WriteLine("******"); 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 Main(string[] args) { IMBeanServer server = MBeanServerFactory.CreateMBeanServer(); server.RegisterMBean(new RelationService(), RelationService.ObjectName); Sample sample1 = new Sample(); Sample sample2 = new Sample(); Sample sample3 = new Sample(); server.RegisterMBean(sample1, "Sample:type=Sample,id=1"); server.RegisterMBean(sample2, "Sample:type=Sample,id=2"); server.RegisterMBean(sample3, "Sample:type=Sample,id=3"); SampleDynamicMBean dynSample = new SampleDynamicMBean(); dynSample.AddRow(1, "First row"); dynSample.AddRow(2, "Second row"); dynSample.AddNestedRow(1, 3, "First nested row"); dynSample.AddNestedRow(2, 4, "Second nested row"); server.RegisterMBean(dynSample, "Sample:type=SampleDynamicMBean"); var relationSerice = server.CreateDynamicProxy(RelationService.ObjectName); relationSerice.CreateRelationType("Binding", new[] { 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"))}); OpenMBeanMapperService mapperService = new OpenMBeanMapperService(new ObjectName[] { "Sample:type=SampleMappedMBean" }); server.RegisterMBean(mapperService, ":type=OpenMBeanMapperService"); SampleMapped mappedMBean = new SampleMapped(); CollectionElement firstColEl = new CollectionElement(); firstColEl.Elements.Add(new NestedCollectionElement(1, "Name1")); firstColEl.Elements.Add(new NestedCollectionElement(2, "Name2")); CollectionElement secondColEl = new CollectionElement(); secondColEl.Elements.Add(new NestedCollectionElement(3, "Name3")); secondColEl.Elements.Add(new NestedCollectionElement(4, "Name4")); mappedMBean.Add(firstColEl); mappedMBean.Add(secondColEl); server.RegisterMBean(mappedMBean, "Sample:type=SampleMappedMBean"); Uri serviceUrl = new Uri("tcp://localhost:1234/MBeanServer.tcp"); var connectorServerFactory = new RemotingConnectorServerFactory(100, new NullSecurityProvider()); using (INetMXConnectorServer connectorServer = connectorServerFactory.NewNetMXConnectorServer(serviceUrl, server)) { connectorServer.Start(); Console.WriteLine("Press any key to quit"); Console.ReadKey(); } }