Esempio n. 1
0
        public MBeanInfo GetMBeanInfo()
        {
            if (_beanInfoDirty)
            {
                string description;
                if (_perfInstanceName != null)
                {
                    description = string.Format(CultureInfo.CurrentCulture, "Performance counter MBean for {0} of {1}.", _perfObjectName, _perfInstanceName);
                }
                else
                {
                    description = string.Format(CultureInfo.CurrentCulture, "Performance counter MBean for {0}.", _perfObjectName);
                }
                List <object> legalCountersToCreate = new List <object>();
                List <object> legalCountersToRemove = new List <object>();

                foreach (PerformanceCounter counter in _category.GetCounters(_perfInstanceName))
                {
                    if (_counters.ContainsKey(counter.CounterName))
                    {
                        legalCountersToRemove.Add(counter.CounterName);
                    }
                    else
                    {
                        legalCountersToCreate.Add(counter.CounterName);
                    }
                }

                MBeanOperationInfo addOperation =
                    MBean.MutatorOperation("AddPerformanceCounter", "Adds new performance counter")
                    .WithParameters(
                        MBean.Parameter("counterName", "Name of new counter")
                        .WithLimitedValues(legalCountersToCreate)
                        .TypedAs(SimpleType.String)
                        )
                    .Returning(SimpleType.Boolean)();

                MBeanOperationInfo removeOperation =
                    MBean.MutatorOperation("RemovePerformanceCounter", "Removes existing performance counter")
                    .WithParameters(
                        MBean.Parameter("counterName", "Name of new counter")
                        .WithLimitedValues(legalCountersToRemove)
                        .TypedAs(SimpleType.String)
                        )
                    .Returning(SimpleType.Boolean)();

                _beanInfo = MBean.Info(typeof(PerfCounterMBean).AssemblyQualifiedName, description)
                            .WithAttributes(GetCurrentAttributes)
                            .WithOperations(addOperation, removeOperation)
                            .AndNothingElse()();

                _beanInfoDirty = false;
            }
            return(_beanInfo);
        }
Esempio n. 2
0
        public OpenDynamic()
        {
            _tabularType = Tabular.Type("Table", "Table")
                           .WithIndexColumn("ID", "UniqueID").TypedAs(SimpleType.Integer)
                           .WithColumn("Name", "Name").TypedAs(SimpleType.String);

            _tabularValue = new TabularDataSupport(_tabularType);

            _outerTabularType = Tabular.Type("Outer table", "Outer table")
                                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                                .WithColumn("Value", "Tabular value").TypedAs(
                Tabular.Type("Inner table", "Inner table")
                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                .WithColumn("Name", "Name").TypedAs(SimpleType.String)
                .WithColumn("CompositeValue", "Composite Value").TypedAs(
                    Composite.Type("Composite value", "Composite value")
                    .WithItem("Item1", "Item 2").TypedAs(SimpleType.Integer)
                    .WithItem("Item2", "Item 2").TypedAs(SimpleType.Boolean)
                    .WithItem("Item3", "Item 3").TypedAs(
                        Composite.Type("Nested", "Nested composite")
                        .WithItem("NestedItem1", "NestedItem1").TypedAs(SimpleType.String)
                        .WithItem("NestedItem2", "NestedItem2").TypedAs(SimpleType.Double))));

            _nestedTabularValue = new TabularDataSupport(_outerTabularType);

            _beanInfoGetter = MBean.Info <OpenDynamic>("Sample dynamic MBean")
                              .WithAttributes(
                MBean.WritableAttribute("Attribute", "Sample attribute").TypedAs(TabularType),
                MBean.WritableAttribute("NestedTableAttribute", "Nested Table Attribute").TypedAs(NestedTabularType)
                )
                              .WithOperations(
                MBean.MutatorOperation("DoSomething", "Does somthing").WithParameters(
                    MBean.Parameter("First", "First parameter").TypedAs(SimpleType.Double),
                    MBean.Parameter("Second", "Second parameter").TypedAs(TabularType)
                    ).Returning(SimpleType.Void)
                )
                              .AndNothingElse();
        }