Пример #1
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;
        }
Пример #2
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;
        }
Пример #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;
        }
Пример #4
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;
        }
Пример #5
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();
            }
        }
Пример #6
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();
                }
            }
        }
Пример #7
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();
            }
        }
        public void TestJsr262Connector()
        {
            var             jsr262ConnectorProvider = new Jsr262ConnectorProvider();
            INetMXConnector connector = null;
            string          uri       = string.Format("http://{0}:8888/MBeanServer", GetLocalAddress());

            Logger.DebugFormat("URI used to connect to the MBeanServer: {0}", uri);
            try
            {
                var url = new Uri(uri);
                connector = jsr262ConnectorProvider.NewNetMXConnector(url);
            }
            catch (Exception)
            {
                string msg = string.Format("Unable to create a client connection to the MBeanServer: URI-{0}", uri);
                Logger.Error(msg);
                Assert.Fail(msg);
            }
            connector.Connect(null);

            using (connector)
            {
                Logger.Debug("Starting the connection...");
                IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

                var       name = new ObjectName("MBeanServer:component=ValidMBean");
                MBeanInfo info = remoteServer.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) [Action]"
                            : "Operation ResetCounter (Sets counter value to 0) [Action]", operation);

                    index++;
                }

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

                Assert.AreEqual(0, counter);

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

                Assert.AreEqual(5, counter);

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

                Assert.AreEqual(10, counter);

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

                Assert.AreEqual(0, counter);

                Logger.Debug("Completed the JSR262 server-side tests!");
            }
        }
Пример #9
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();
                }
            }
        }
Пример #10
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();
                }
            }
        }