public void TestMBeanServer()
        {
            IMBeanServer mbeanServer = mbeanServerExtension.MBeanServer;

            var       name = new ObjectName("MBeanServer:component=ValidMBean");
            MBeanInfo info = mbeanServer.GetMBeanInfo(name);

            Assert.AreEqual("MBean", info.Description);
            Assert.AreEqual("CrimsonLogic.Common.Library.Tests.ValidInstanceMBean, CrimsonLogic.Common.Library.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5fb9aab394206ec1", info.ClassName);
            foreach (MBeanAttributeInfo attributeInfo in info.Attributes)
            {
                string attribute = string.Format("Attribute {0} ({1}) [{2}{3}]: {4}", attributeInfo.Name,
                                                 attributeInfo.Description,
                                                 attributeInfo.Readable ? "r" : "", attributeInfo.Writable ? "w" : "",
                                                 attributeInfo.Type);
                Assert.AreEqual("Attribute Counter (Counter value) [rw]: System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", attribute);
            }
            int index = 0;

            foreach (MBeanOperationInfo operationInfo in info.Operations)
            {
                string operation = string.Format("Operation {0} ({1}) [{2}]", operationInfo.Name, operationInfo.Description,
                                                 operationInfo.Impact);
                Assert.AreEqual(
                    index == 0
                        ? "Operation AddAmount (Adds specified value to value of the counter) [Unknown]"
                        : "Operation ResetCounter (Sets counter value to 0) [Unknown]", operation);

                index++;
            }

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

            Assert.AreEqual(0, counter);

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

            Assert.AreEqual(5, counter);

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

            Assert.AreEqual(10, counter);

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

            Assert.AreEqual(0, counter);

            Logger.Debug("Completed testing the MBeanServer!");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //Server side
            IMBeanServer     server       = MBeanServerFactory.CreateMBeanServer("PlatformMBeanServer");
            PerfCounterMBean processMBean = new PerfCounterMBean("Process", true, new[] { "% Processor Time" });

            server.RegisterMBean(processMBean, "CLR:type=Process");

            //Client side
            Console.WriteLine("Attributes of 'CLR:type=Process' MBean:");
            foreach (AttributeValue v in server.GetAttributes("CLR:type=Process", server.GetMBeanInfo("CLR:type=Process").Attributes.Select(x => x.Name).ToArray()))
            {
                Console.WriteLine("{0}: {1}", v.Name, v.Value);
            }
            Console.WriteLine();
            Console.WriteLine("Attributes of 'CLR:type=Memory' MBean:");
            foreach (AttributeValue v in server.GetAttributes("CLR:type=Memory", server.GetMBeanInfo("CLR:type=Memory").Attributes.Select(x => x.Name).ToArray()))
            {
                Console.WriteLine("{0}: {1}", v.Name, v.Value);
            }
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            IMBeanServer server = MBeanServerFactory.CreateMBeanServer();
            Counter      o      = new Counter();
            ObjectName   name   = new ObjectName("QuickStart:type=counter");

            server.RegisterMBean(o, name);

            Console.WriteLine("******");
            MBeanInfo info = server.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("******");

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

            object counter = server.GetAttribute(name, "Value");

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

            server.SetAttribute(name, "Value", 5);
            counter = server.GetAttribute(name, "Value");

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

            counter = server.Invoke(name, "Add", new object[] { 5 });
            counter = server.GetAttribute(name, "Value");

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

            counter = server.Invoke(name, "Reset", new object[] { });
            counter = server.GetAttribute(name, "Value");

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

            server.RemoveNotificationListener(name, CounterChanged, null, null);

            Console.ReadKey();
        }
Exemple #4
0
        private void MapBean(ObjectName originalBeanName)
        {
            Dictionary <string, string> props = new Dictionary <string, string>(originalBeanName.KeyPropertyList);

            props.Add(_proxyIndicatorProperty, "true");
            ObjectName proxyName = new ObjectName(originalBeanName.Domain, props);

            MBeanInfo originalInfo = _server.GetMBeanInfo(originalBeanName);

            if (!(originalInfo is NetMX.OpenMBean.IOpenMBeanInfo))
            {
                ProxyBean proxyBean = new ProxyBean(originalInfo, originalBeanName, _typeCache);
                _server.RegisterMBean(proxyBean, proxyName);
            }
        }
        public OutgoingMessage GetMBeanInfo(IncomingMessage requestMessage)
        {
            CheckResourceUri(requestMessage, Schema.DynamicMBeanResourceUri);

            var selectorSet = requestMessage.GetHeader <SelectorSetHeader>();
            var objectName  = selectorSet.ExtractObjectName();

            var info = _server.GetMBeanInfo(objectName);

            var response = new ResourceMetaDataTypeMessage(new ResourceMetaDataType(info));

            return(new OutgoingMessage()
                   .AddHeader(new ActionHeader(Schema.GetMBeanInfoResponseAction), true)
                   .SetBody(new SerializerBodyWriter(response)));
        }