Exemplo n.º 1
0
 /// <summary>
 /// Creates new RelationSupport object.
 ///
 /// This constructor has to be used when the user relation MBean implements the interfaces expected
 /// to be supported by a relation by delegating to a RelationSupport object.
 ///
 /// This object needs to know the Relation Service expected to handle the relation. So it has to know
 /// the MBean Server where the Relation Service is registered.
 ///
 /// According to a limitation, a relation MBean must be registered in the same MBean Server as the
 /// Relation Service expected to handle it. So the user relation MBean has to be created and
 /// registered, and then the wrapped RelationSupport object can be created with identified MBean Server.
 ///
 /// Nothing is done at the Relation Service level, i.e. the RelationSupport object is not added,
 /// and no check if the provided values are correct. The object is always created, EXCEPT if:
 /// <list type="bullet">
 /// <item>one required parameter is not provided</item>
 /// <item>the same name is used for two roles.</item>
 /// </list>
 /// To be handled as a relation, the object has then to be added in the Relation Service using the Relation
 /// Service method <see cref="RelationServiceMBean.AddRelation"/>().
 /// </summary>
 /// <param name="relationId">Relation identifier, to identify the relation in the Relation Service. Expected to be unique in the given Relation Service.</param>
 /// <param name="relationServiceName">ObjectName of the Relation Service where the relation will be registered.
 /// It is required as this is the Relation Service that is aware of the definition of the relation type
 /// of given relation, so that will be able to check update operations (set).
 /// </param>
 /// <param name="relationServiceMBeanServer">MBean Server where the wrapping MBean is or will be registered.
 /// Expected to be the MBean Server where the Relation Service is or will be registered.
 /// </param>
 /// <param name="relationType">Name of relation type. Expected to have been created in given Relation Service.</param>
 /// <param name="roles">Roles (Role objects) to initialised the relation. Can be null. Expected to conform to relation info in associated relation type.</param>
 public RelationSupport(string relationId, ObjectName relationServiceName, IMBeanServer relationServiceMBeanServer,
                        string relationType, IEnumerable <Role> roles)
 {
     _relationId = relationId;
     if (relationServiceMBeanServer == null || relationServiceName.Domain != "")
     {
         _relationServiceName = relationServiceName;
     }
     else
     {
         _relationServiceName = new ObjectName(relationServiceMBeanServer.GetDefaultDomain(), relationServiceName.KeyPropertyList);
     }
     _relationServiceMBeanServer = relationServiceMBeanServer;
     _relationService            = _relationServiceMBeanServer.CreateDynamicProxy(_relationServiceName);
     _relationTypeName           = relationType;
     _roles = new Dictionary <string, Role>();
     if (roles != null)
     {
         foreach (Role role in roles)
         {
             if (!_roles.ContainsKey(role.Name))
             {
                 _roles[role.Name] = role;
             }
             else
             {
                 throw new InvalidRoleValueException();
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates new RelationSupport object.
 /// 
 /// This constructor has to be used when the user relation MBean implements the interfaces expected 
 /// to be supported by a relation by delegating to a RelationSupport object.
 /// 
 /// This object needs to know the Relation Service expected to handle the relation. So it has to know 
 /// the MBean Server where the Relation Service is registered.
 /// 
 /// According to a limitation, a relation MBean must be registered in the same MBean Server as the 
 /// Relation Service expected to handle it. So the user relation MBean has to be created and 
 /// registered, and then the wrapped RelationSupport object can be created with identified MBean Server.
 /// 
 /// Nothing is done at the Relation Service level, i.e. the RelationSupport object is not added, 
 /// and no check if the provided values are correct. The object is always created, EXCEPT if:
 /// <list type="bullet">
 /// <item>one required parameter is not provided</item>
 /// <item>the same name is used for two roles.</item>
 /// </list>
 /// To be handled as a relation, the object has then to be added in the Relation Service using the Relation 
 /// Service method <see cref="RelationServiceMBean.AddRelation"/>().      
 /// </summary>
 /// <param name="relationId">Relation identifier, to identify the relation in the Relation Service. Expected to be unique in the given Relation Service.</param>
 /// <param name="relationServiceName">ObjectName of the Relation Service where the relation will be registered.
 /// It is required as this is the Relation Service that is aware of the definition of the relation type 
 /// of given relation, so that will be able to check update operations (set).
 /// </param>
 /// <param name="relationServiceMBeanServer">MBean Server where the wrapping MBean is or will be registered.
 /// Expected to be the MBean Server where the Relation Service is or will be registered.
 /// </param>
 /// <param name="relationType">Name of relation type. Expected to have been created in given Relation Service.</param>
 /// <param name="roles">Roles (Role objects) to initialised the relation. Can be null. Expected to conform to relation info in associated relation type.</param>
 public RelationSupport(string relationId, ObjectName relationServiceName, IMBeanServer relationServiceMBeanServer,
     string relationType, IEnumerable<Role> roles)
 {
     _relationId = relationId;
      if (relationServiceMBeanServer == null || relationServiceName.Domain != "")
      {
     _relationServiceName = relationServiceName;
      }
      else
      {
     _relationServiceName = new ObjectName(relationServiceMBeanServer.GetDefaultDomain(), relationServiceName.KeyPropertyList);
      }
      _relationServiceMBeanServer = relationServiceMBeanServer;
       _relationService = _relationServiceMBeanServer.CreateDynamicProxy(_relationServiceName);
      _relationTypeName = relationType;
      _roles = new Dictionary<string, Role>();
      if (roles != null)
      {
     foreach (Role role in roles)
     {
        if (!_roles.ContainsKey(role.Name))
        {
           _roles[role.Name] = role;
        }
        else
        {
           throw new InvalidRoleValueException();
        }
     }
      }
 }
Exemplo n.º 3
0
 public ObjectName PreRegister(IMBeanServer server, ObjectName name)
 {
     _relationServiceMBeanServer = server;
     if (_relationServiceName.Domain == "")
     {
         _relationServiceName = new ObjectName(server.GetDefaultDomain(), _relationServiceName.KeyPropertyList);
     }
     _relationService = _relationServiceMBeanServer.CreateDynamicProxy(_relationServiceName);
     return(name);
 }
Exemplo n.º 4
0
        public ObjectName PreRegister(IMBeanServer server, ObjectName name)
        {
            _server = server;
            var timer = new Timer.Timer();
            IDictionary <string, string> props = name.KeyPropertyList;

            props.Add("EmbeddedTimer", "true");
            var timerName = new ObjectName(name.Domain, props);

            server.RegisterMBean(timer, timerName);
            _timer = _server.CreateDynamicProxy(timerName);
            _server.AddNotificationListener(timerName, OnTimerEvent, null, null);
            return(name);
        }
Exemplo n.º 5
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;
                }
            }
        }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
 public ObjectName PreRegister(IMBeanServer server, ObjectName name)
 {
     _relationServiceMBeanServer = server;
      if (_relationServiceName.Domain == "")
      {
     _relationServiceName = new ObjectName(server.GetDefaultDomain(), _relationServiceName.KeyPropertyList);
      }
       _relationService = _relationServiceMBeanServer.CreateDynamicProxy(_relationServiceName);
      return name;
 }