Example #1
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();
                }
            }
        }
 public MBeanPermissionImpl(string className, string memberName, ObjectName objectName, MBeanPermissionAction actions)
 {
     _className = className;
     _memberName = memberName;
     _objectName = objectName;
     _actions = actions;
 }
Example #3
0
        public void ApplyTest()
        {
            ObjectName pattern = new ObjectName("domain:a=1,b=2,c=3");
             Assert.IsTrue(pattern.Apply(pattern));

             pattern = new ObjectName("domain:a=1,b=2,c=3,*");
             ObjectName target = new ObjectName("domain:a=1,b=2,c=3");
             Assert.IsTrue(pattern.Apply(target));

             pattern = new ObjectName("domain:a=1,b=2,c=3,*");
             target = new ObjectName("domain:a=1,b=2,c=3,d=4");
             Assert.IsTrue(pattern.Apply(target));

             pattern = new ObjectName("domain:a=1,b=2,c=3");
             target = new ObjectName("domain:a=1,b=2,c=3,d=4");
             Assert.IsFalse(pattern.Apply(target));

             pattern = new ObjectName("domain:a=1,b=2,c=3");
             target = new ObjectName("domain:a=1,b=4,c=3");
             Assert.IsFalse(pattern.Apply(target));

             pattern = new ObjectName("do?ain:a=1,b=2,c=3");
             target = new ObjectName("doFain:a=1,b=2,c=3");
             Assert.IsTrue(pattern.Apply(target));

             pattern = new ObjectName("dom*in:a=1,b=2,c=3");
             target = new ObjectName("domHUGSXUain:a=1,b=2,c=3");
             Assert.IsTrue(pattern.Apply(target));
        }
 /// <summary>
 /// Creates new MBeanServerNotification object.
 /// </summary>
 /// <param name="type">A string denoting the type of the notification. Set it to one these values: 
 /// <see cref="NetMX.MBeanServerNotification.RegistrationNotification"/>, 
 /// <see cref="NetMX.MBeanServerNotification.UnregistrationNotification"/>.</param>
 /// <param name="source">The MBeanServerNotification object responsible for forwarding MBean server 
 /// notification.</param>
 /// <param name="sequenceNumber">A sequence number that can be used to order received notifications.</param>
 /// <param name="objectName">The object name of the MBean that caused the notification.</param>
 public MBeanServerNotification(string type, object source, long sequenceNumber, ObjectName objectName)
     : base(type, source, sequenceNumber)
 {
     if (type != RegistrationNotification && type != UnregistrationNotification)
      {
     throw new ArgumentException("Invalid notification type.", "type");
      }
      _objectName = objectName;
 }
Example #5
0
        public void CanonicalKeyPropertyListStringTest()
        {
            string domain = "domain";

             System.Collections.Generic.Dictionary<string, string> properties = new Dictionary<string, string>();
             properties["bbb"] = "1";
             properties["ccc"] = "2";
             properties["ddd"] = "3";
             properties["aaa"] = "4";
             ObjectName target = new ObjectName(domain, properties);

             string val = "aaa=4,bbb=1,ccc=2,ddd=3";
             Assert.AreEqual(val, target.CanonicalKeyPropertyListString);
        }
        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!");
        }
Example #7
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();
        }
Example #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;

        }
Example #9
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;
            }
             }
        }
Example #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();
            }
             }
        }
 public IList<AttributeValue> GetAttributes(ObjectName name, string[] attributeNames)
 {
     return contractDelegate.GetAttributes(name, attributeNames);
 }
 public MBeanInfo GetMBeanInfo(ObjectName name)
 {
     return contractDelegate.GetMBeanInfo(name);
 }
 public ObjectInstance CreateMBean(string className, ObjectName name, object[] arguments)
 {
     return contractDelegate.CreateMBean(className, name, arguments);
 }
 public object GetAttribute(ObjectName name, string attributeName)
 {
     return contractDelegate.GetAttribute(name, attributeName);
 }
 public void RemoveNotificationListener(ObjectName name, ObjectName listener)
 {
     contractDelegate.RemoveNotificationListener(name, listener);
 }
 public MBeanInfo GetMBeanInfo(ObjectName name)
 {
     return proxy.GetMBeanInfo(name);
 }
 /// <summary>
 /// Initializes this emitter. Should be called in PreRegister phase of inheriting or owning MBean.
 /// </summary>
 /// <param name="objectName">ObjectName of inheriting or owning MBean</param>
 /// <param name="notificationInfo">NotificationInfo list of inheriting or owning MBean</param>
 public void Initialize(ObjectName objectName, IEnumerable <MBeanNotificationInfo> notificationInfo)
 {
     _notificationInfo = new List <MBeanNotificationInfo>(notificationInfo).AsReadOnly();
     _objectName       = objectName;
 }
 public bool IsRegistered(ObjectName name)
 {
     return contractDelegate.IsRegistered(name);
 }
 public object GetAttribute(ObjectName name, string attributeName)
 {
     return proxy.GetAttribute(name, attributeName);
 }
 public void RemoveNotificationListener(ObjectName name, ObjectName listener, NotificationFilterCallback filterCallback, object handback)
 {
     throw new InvalidOperationException("This operation is not supported by ServiceModel connector.");
 }
 public bool IsRegistered(ObjectName name)
 {
     return proxy.IsRegistered(name);
 }
 public bool IsInstanceOf(ObjectName name, string className)
 {
     return proxy.IsInstanceOf(name, className);
 }
 public object Invoke(ObjectName name, string operationName, object[] arguments)
 {
     return proxy.Invoke(name, operationName, arguments);
 }
 public object Invoke(ObjectName name, string operationName, object[] arguments)
 {
     return contractDelegate.Invoke(name, operationName, arguments);
 }
 public void SetAttribute(ObjectName name, string attributeName, object value)
 {
     contractDelegate.SetAttribute(name, attributeName, value);
 }
 public bool IsInstanceOf(ObjectName name, string className)
 {
     return contractDelegate.IsInstanceOf(name, className);
 }
 public IList<AttributeValue> SetAttributes(ObjectName name, IEnumerable<AttributeValue> namesAndValues)
 {
     return contractDelegate.SetAttributes(name, namesAndValues);
 }
 public IEnumerable<ObjectName> QueryNames(ObjectName name, QueryExp query)
 {
     return contractDelegate.QueryNames(name, query);
 }
 public void UnregisterMBean(ObjectName name)
 {
     contractDelegate.UnregisterMBean(name);
 }
 public IEnumerable<ObjectName> QueryNames(ObjectName name, QueryExp query)
 {
     return proxy.QueryNames(name, query);
 }
 public IList<AttributeValue> GetAttributes(ObjectName name, string[] attributeNames)
 {
     return proxy.GetAttributes(name, attributeNames);
 }