Ejemplo n.º 1
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.º 2
0
        public void SetUp()
        {
            _server = MBeanServerFactory.CreateMBeanServer();

             _connectorServer = new Jsr262ConnectorServerFactory().NewNetMXConnectorServer(new Uri(_serviceUrl), _server);
             _connectorServer.Start();
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            _notificationFlag = new ManualResetEvent(false);
            _server           = MockRepository.GenerateMock <IMBeanServer>();
            Uri serviceUrl = GetUri();

            _connectorServer = GetConnectorServerFactory().NewNetMXConnectorServer(serviceUrl, _server);
            _connectorServer.Start();
            _connector    = GetConnectorFactory().Connect(serviceUrl, null);
            _remoteServer = _connector.MBeanServerConnection;
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            _notificationFlag = new ManualResetEvent(false);
             _server = MockRepository.GenerateMock<IMBeanServer>();
             Uri serviceUrl = GetUri();

             _connectorServer = GetConnectorServerFactory().NewNetMXConnectorServer(serviceUrl, _server);
             _connectorServer.Start();
             _connector = GetConnectorFactory().Connect(serviceUrl, null);
             _remoteServer = _connector.MBeanServerConnection;
        }
Ejemplo n.º 5
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.º 6
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;
        }
        /// <summary>
        /// Starts this MBeanServer.
        /// </summary>
        public void Start()
        {
            jsr262ConnectorServer = DoCreateJsr262Server(mbeanServer);

            // A thread must be spawned else the flow will block here when the server starts!
            Logger.Info("Spawning a thread to non-block the application when MBeanServer is started...");
            var thread = new Thread(() =>
            {
                try
                {
                    serverStarted = true;
                    Logger.Info("Started the MBeanServer with the JSR262 connector!");
                    jsr262ConnectorServer.Start();
                }
                catch (Exception exception)
                {
                    Logger.Error("Problem starting the MBeanServer with the JSR262 connector!", exception);
                    serverStarted = false;
                }
            });
            thread.Start();
        }
Ejemplo n.º 8
0
        public static bool initializeServerMBean()
        {
            if (!initializedServerMBean)
            {
                server = MBeanServerFactory.CreateMBeanServer();
                server1Counter = new Counter();
                server2Counter = new Counter();
                server3Counter = new Counter();
                name = new ObjectName("server1Counter:");
                name2 = new ObjectName("server2Counter:");
                name3 = new ObjectName("server3Counter:");
                server.RegisterMBean(server1Counter, name);
                server.RegisterMBean(server2Counter, name2);
                server.RegisterMBean(server3Counter, name3);
                Uri serviceUrl = new Uri(Global.Server.MBeansServer);
                connectorServer = NetMXConnectorServerFactory.NewNetMXConnectorServer(serviceUrl, server);
                connectorServer.Start();
                initializedServerMBean = true;
            }
            return true;

        }
        /// <summary>
        /// Starts this MBeanServer.
        /// </summary>
        public void Start()
        {
            jsr262ConnectorServer = DoCreateJsr262Server(mbeanServer);

            // A thread must be spawned else the flow will block here when the server starts!
            Logger.Info("Spawning a thread to non-block the application when MBeanServer is started...");
            var thread = new Thread(() =>
            {
                try
                {
                    serverStarted = true;
                    Logger.Info("Started the MBeanServer with the JSR262 connector!");
                    jsr262ConnectorServer.Start();
                }
                catch (Exception exception)
                {
                    Logger.Error("Problem starting the MBeanServer with the JSR262 connector!", exception);
                    serverStarted = false;
                }
            });

            thread.Start();
        }
Ejemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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();
                }
            }
        }