Ejemplo n.º 1
0
        public void SetUp()
        {
            _server = MBeanServerFactory.CreateMBeanServer();

            _connectorServer = new Jsr262ConnectorServerFactory().NewNetMXConnectorServer(new Uri(_serviceUrl), _server);
            _connectorServer.Start();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            const string address = "http://localhost:12345/adaptor/sample";

            var server = MBeanServerFactory.CreateMBeanServer("HttpAdaptorDemo");

            server.RegisterMBean(new RelationService(), RelationService.ObjectName);

            server.RegisterMBean(new Sample(), "sample:t=static");
            server.RegisterMBean(new Sample(), "d1.sample:t=static");
            server.RegisterMBean(new Sample(), "d1.sample2:t=static");
            server.RegisterMBean(new Sample(), "d1.d2.sample1:t=static");
            server.RegisterMBean(new Sample(), "d1.d2.sample2:t=static");
            server.RegisterMBean(new Sample(), "d1.d2.d3.sample1:t=static");

            var dynamicMBean = new SampleDynamicMBean();

            dynamicMBean.AddRow(1, "Simon");
            dynamicMBean.AddRow(2, "John");
            dynamicMBean.SetComposite(3, "Jane");
            dynamicMBean.SetArray(new[] { 1, 2.5m, 4.3m, 5.64m });

            server.RegisterMBean(dynamicMBean, "sample:t=dynamic");

            var relationSerice = server.CreateDynamicProxy(RelationService.ObjectName);

            relationSerice.CreateRelationType("Binding",
                                              new[]
            {
                new RoleInfo("Source", typeof(SampleMBean), true, false, 1, 1,
                             "Source"),
                new RoleInfo("Destination", typeof(SampleDynamicMBean), true, false, 1,
                             1, "Destination")
            });

            relationSerice.CreateRelation("Rel1", "Binding",
                                          new[]
            {
                new Role("Source", new ObjectName("sample:t=static")),
                new Role("Destination", new ObjectName("sample:t=dynamic"))
            });

            var adaptor = new SelfHostingHttpAdaptor(server, address);

            adaptor.Start();

            Console.WriteLine("Http adaptor started at {0}. Press <enter> to exit.", address);
            Console.ReadLine();

            adaptor.Stop();
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            _server = MBeanServerFactory.CreateMBeanServer();
            SimpleStandard o    = new SimpleStandard();
            ObjectName     name = new ObjectName("Tests:key=value");

            _server.RegisterMBean(o, name);
            Uri serviceUrl = GetUri();

            _connectorServer = GetConnectorServerFactory().NewNetMXConnectorServer(serviceUrl, _server);
            _connectorServer.Start();
            _connector    = GetConnectorFactory().Connect(serviceUrl, null);
            _remoteServer = _connector.MBeanServerConnection;
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
        public void Initialize()
        {
            Server = MBeanServerFactory.CreateMBeanServer();

            Server.RegisterMBean(new Sample(), "sample:a=b");
            var dynamicMBean = new SampleDynamicMBean();

            dynamicMBean.AddRow(1, "Simon");
            dynamicMBean.AddRow(2, "John");
            dynamicMBean.SetComposite(3, "Jane");
            dynamicMBean.SetArray(new[] { 1, 2.5m, 4m, 5m });

            Server.RegisterMBean(dynamicMBean, "dynamic:a=b");

            Adaptor = new SelfHostingHttpAdaptor(Server, "http://localhost:12345/adaptor");
            Adaptor.Start();
        }
        public void SetUp()
        {
            _bean1   = new Test();
            _server1 = MBeanServerFactory.CreateMBeanServer("1");
            _server1.RegisterMBean(_bean1, "someDomain:t=test");

            _bean2   = new Test();
            _server2 = MBeanServerFactory.CreateMBeanServer("2");
            _server2.RegisterMBean(_bean2, "someDomain:t=test");

            _bean3   = new Test();
            _server3 = MBeanServerFactory.CreateMBeanServer("3");
            _server3.RegisterMBean(_bean3, "someDomain:t=test");
            _server3.RegisterMBean(_bean3, "invalidPrefix.someDomain:t=test");

            _aggregateConnection = new AggregateMBeanServerConnection(_server3);
            _aggregateConnection.AddChildServer("one", _server1);
            _aggregateConnection.AddChildServer("two", _server2);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            IMBeanServer server = MBeanServerFactory.CreateMBeanServer();
            Timer        timer  = new Timer();
            ObjectName   name   = new ObjectName("Timer:");

            server.RegisterMBean(timer, name);

            var timerBean = server.CreateDynamicProxy(name);

            timerBean.Start();
            server.AddNotificationListener(name, OnTimerEvent, null, null);

            Console.WriteLine("******");
            timerBean.AddNotification2("Type1", "Message1", 4, DateTime.Now.AddSeconds(2), new TimeSpan(0, 0, 0, 1));
            //timerBean.AddNotification4("Type1", "Message1", 4, DateTime.Now.AddSeconds(2), new TimeSpan(0,0,0,1),3,true);
            timerBean.SendPastNotifications = true;
            bool exit = false;

            while (!exit)
            {
                ConsoleKeyInfo info = Console.ReadKey();
                switch (char.ToUpper(info.KeyChar))
                {
                case 'X':
                    exit = true;
                    break;

                case 'S':
                    if (timerBean.IsActive)
                    {
                        timerBean.Stop();
                    }
                    else
                    {
                        timerBean.Start();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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();
                }
            }
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        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();
                }
            }
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var connectorServerFactory = new Jsr262ConnectorServerFactory();
            var connectorFactory       = new Jsr262ConnectorFactory();

            IMBeanServer server = MBeanServerFactory.CreateMBeanServer();
            Sample       o      = new Sample();
            ObjectName   name   = new ObjectName("Sample:a=b");

            server.RegisterMBean(o, name);
            Uri serviceUrl = new Uri("http://localhost:12345/MBeanServer");

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

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

                    string defaultDomain = remoteServer.GetDefaultDomain();
                    Console.WriteLine("Default domain is {0}", defaultDomain);

                    IEnumerable <string> domains = remoteServer.GetDomains();
                    Console.WriteLine("Following domains are registereds:");
                    foreach (string domain in domains)
                    {
                        Console.WriteLine(" * {0}", domain);
                    }

                    IEnumerable <ObjectName> names = remoteServer.QueryNames(null, new EqualExp(new AttributeExp("Counter"), new ConstantExp <Number>(0)));
                    Console.WriteLine("Following MBeans have attribute counter with value 0:");
                    foreach (ObjectName objectName in names)
                    {
                        Console.WriteLine(" * {0}", objectName);
                    }

                    //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}. Press <enter>", counter);
                    Console.ReadLine();

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

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

                    Console.WriteLine("Press <enter> to exit.");
                    Console.ReadLine();
                }
            }
        }