Beispiel #1
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

            using (INetMXConnector connector = NetMXConnectorFactory.Connect(new Uri("http://localhost:9998/jmxws"), null))
            {
                IMBeanServerConnection remoteServer = connector.MBeanServerConnection;
                ObjectName             name         = ":type=Sample2";
                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, "Value");

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

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

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

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

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

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

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

                Console.ReadKey();
            }
        }
Beispiel #2
0
        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();
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            IApplicationContext ctx = ContextRegistry.GetContext();


            using (INetMXConnector connector = NetMXConnectorFactory.Connect(new Uri("http://localhost:1010/MBeanServer"), null))
            {
                IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

                ObjectName name = "Sample:name=SampleComponent";

                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, "Count");

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

                Console.WriteLine("Invoking StringAndIntOperation...");
                remoteServer.Invoke(name, "StringAndIntOperation", new object[] { "a", 5 });
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }