예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.Map<String,Object> toNeo4jValue(javax.management.ObjectName name, javax.management.MBeanAttributeInfo attribute) throws javax.management.JMException
        private IDictionary <string, object> ToNeo4jValue(ObjectName name, MBeanAttributeInfo attribute)
        {
            object value;

            try
            {
                value = toNeo4jValue(_jmxServer.getAttribute(name, attribute.Name));
            }
            catch (RuntimeMBeanException e)
            {
                if (e.InnerException != null && e.InnerException is System.NotSupportedException)
                {
                    // We include the name and description of this attribute still - but the value of it is
                    // unknown. We do this rather than rethrow the exception, because several MBeans built into
                    // the JVM will throw exception on attribute access depending on their runtime state, even
                    // if the attribute is marked as readable. Notably the GC beans do this.
                    value = null;
                }
                else
                {
                    throw e;
                }
            }
            return(map("description", attribute.Description, "value", value));
        }
예제 #2
0
        protected internal override string GetDescription(MBeanAttributeInfo info)
        {
            Description description = DescribeMethod(info, "get", "is");

            if (description != null)
            {
                return(description.value());
            }
            return(base.GetDescription(info));
        }
예제 #3
0
 public PropertyModelInfoType(MBeanAttributeInfo attributeInfo)
     : base(attributeInfo)
 {
     access = "";
     if (attributeInfo.Readable)
     {
         access += "r";
     }
     if (attributeInfo.Writable)
     {
         access += "w";
     }
     type = JmxTypeMapping.GetJmxXmlType(attributeInfo.Type);
 }
예제 #4
0
 public PropertyModelInfoType(MBeanAttributeInfo attributeInfo)
     : base(attributeInfo)
 {
     access = "";
      if (attributeInfo.Readable)
      {
     access += "r";
      }
      if (attributeInfo.Writable)
      {
     access += "w";
      }
      type = JmxTypeMapping.GetJmxXmlType(attributeInfo.Type);
 }
예제 #5
0
 internal virtual MBeanInfo Get()
 {
     curRecNo = 0;
     foreach (MetricsRecordImpl rec in recs)
     {
         foreach (MetricsTag t in ((IList <MetricsTag>)rec.Tags()))
         {
             attrs.AddItem(NewAttrInfo("tag." + t.Name(), t.Description(), "java.lang.String")
                           );
         }
         foreach (AbstractMetric m in rec.Metrics())
         {
             m.Visit(this);
         }
         ++curRecNo;
     }
     MetricsSystemImpl.Log.Debug(attrs);
     MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.Count];
     return(new MBeanInfo(name, description, Collections.ToArray(attrs, attrsArray
                                                                 ), null, null, null));
 }
예제 #6
0
 public MBeanInternalAttributeInfo(PropertyInfo propInfo, IMBeanInfoFactory factory)
 {
     _property      = propInfo;
     _attributeInfo = factory.CreateMBeanAttributeInfo(propInfo);
 }
예제 #7
0
        public ProxyBean(MBeanInfo originalBeanInfo, ObjectName originalName, OpenTypeCache typeCache)
        {
            _originalName = originalName;
            _typeCache    = typeCache;

            List <MBeanAttributeInfo>   attributes   = new List <MBeanAttributeInfo>();
            List <MBeanOperationInfo>   operations   = new List <MBeanOperationInfo>();
            List <MBeanConstructorInfo> constructors = new List <MBeanConstructorInfo>();

            foreach (MBeanAttributeInfo attributeInfo in originalBeanInfo.Attributes)
            {
                if (attributeInfo.Readable)
                {
                    Type     attributeType = Type.GetType(attributeInfo.Type, true);
                    OpenType mappedType    = _typeCache.MapType(attributeType);
                    if (mappedType != null)
                    {
                        Descriptor descriptor = new Descriptor(); //TODO: Copty fields
                        descriptor.SetField(OpenTypeDescriptor.Field, mappedType);
                        MBeanAttributeInfo openInfo = new MBeanAttributeInfo(
                            attributeInfo.Name, attributeInfo.Description, mappedType.Representation.AssemblyQualifiedName,
                            attributeInfo.Readable, false, descriptor);
                        attributes.Add(openInfo);
                        _attributeTypes[attributeInfo.Name] = new OpenAndClrType(attributeType, mappedType);
                    }
                }
            }
            foreach (MBeanOperationInfo operationInfo in originalBeanInfo.Operations)
            {
                Type     returnType       = Type.GetType(operationInfo.ReturnType, true);
                OpenType mappedReturnType = _typeCache.MapType(returnType);
                if (mappedReturnType == null)
                {
                    continue;
                }
                Descriptor descriptor = new Descriptor();
                descriptor.SetField(OpenTypeDescriptor.Field, mappedReturnType);
                bool success = true;
                List <MBeanParameterInfo> openParameters = new List <MBeanParameterInfo>();
                foreach (MBeanParameterInfo parameterInfo in operationInfo.Signature)
                {
                    OpenType mappedParamType = _typeCache.MapType(Type.GetType(parameterInfo.Type, true));
                    if (mappedParamType == null || mappedParamType.Kind != OpenTypeKind.SimpleType)
                    {
                        success = false;
                        break;
                    }
                    Descriptor paramDescriptor = new Descriptor(); //TODO: Copy fields
                    paramDescriptor.SetField(OpenTypeDescriptor.Field, mappedParamType);
                    openParameters.Add(new MBeanParameterInfo(parameterInfo.Name, parameterInfo.Description,
                                                              mappedParamType.Representation.AssemblyQualifiedName,
                                                              paramDescriptor));
                }
                if (!success)
                {
                    continue;
                }
                MBeanOperationInfo openInfo = new MBeanOperationInfo(operationInfo.Name, operationInfo.Description,
                                                                     mappedReturnType.Representation.AssemblyQualifiedName,
                                                                     openParameters, operationInfo.Impact, descriptor);
                operations.Add(openInfo);
                _operationReturnTypes[operationInfo.Name] = new OpenAndClrType(returnType, mappedReturnType);
            }

            _info = new MBeanInfo(originalBeanInfo.ClassName, originalBeanInfo.Description,
                                  attributes, constructors, operations, originalBeanInfo.Notifications);
        }
예제 #8
0
        public ProxyBean(MBeanInfo originalBeanInfo, ObjectName originalName, OpenTypeCache typeCache)
        {
            _originalName = originalName;
             _typeCache = typeCache;

             List<MBeanAttributeInfo> attributes = new List<MBeanAttributeInfo>();
             List<MBeanOperationInfo> operations = new List<MBeanOperationInfo>();
             List<MBeanConstructorInfo> constructors = new List<MBeanConstructorInfo>();

             foreach (MBeanAttributeInfo attributeInfo in originalBeanInfo.Attributes)
             {
            if (attributeInfo.Readable)
            {
               Type attributeType = Type.GetType(attributeInfo.Type, true);
               OpenType mappedType = _typeCache.MapType(attributeType);
               if (mappedType != null)
               {
                  Descriptor descriptor = new Descriptor(); //TODO: Copty fields
                  descriptor.SetField(OpenTypeDescriptor.Field, mappedType);
                  MBeanAttributeInfo openInfo = new MBeanAttributeInfo(
                     attributeInfo.Name, attributeInfo.Description, mappedType.Representation.AssemblyQualifiedName,
                     attributeInfo.Readable, false, descriptor);
                  attributes.Add(openInfo);
                  _attributeTypes[attributeInfo.Name] = new OpenAndClrType(attributeType, mappedType);
               }
            }
             }
             foreach (MBeanOperationInfo operationInfo in originalBeanInfo.Operations)
             {
            Type returnType = Type.GetType(operationInfo.ReturnType, true);
            OpenType mappedReturnType = _typeCache.MapType(returnType);
            if (mappedReturnType == null)
            {
               continue;
            }
            Descriptor descriptor = new Descriptor();
            descriptor.SetField(OpenTypeDescriptor.Field, mappedReturnType);
            bool success = true;
            List<MBeanParameterInfo> openParameters = new List<MBeanParameterInfo>();
            foreach (MBeanParameterInfo parameterInfo in operationInfo.Signature)
            {
               OpenType mappedParamType = _typeCache.MapType(Type.GetType(parameterInfo.Type, true));
               if (mappedParamType == null || mappedParamType.Kind != OpenTypeKind.SimpleType)
               {
                  success = false;
                  break;
               }
               Descriptor paramDescriptor = new Descriptor(); //TODO: Copy fields
               paramDescriptor.SetField(OpenTypeDescriptor.Field, mappedParamType);
               openParameters.Add(new MBeanParameterInfo(parameterInfo.Name, parameterInfo.Description,
                                                         mappedParamType.Representation.AssemblyQualifiedName,
                                                         paramDescriptor));
            }
            if (!success)
            {
               continue;
            }
            MBeanOperationInfo openInfo = new MBeanOperationInfo(operationInfo.Name, operationInfo.Description,
                                                                 mappedReturnType.Representation.AssemblyQualifiedName,
                                                                 openParameters, operationInfo.Impact, descriptor);
            operations.Add(openInfo);
            _operationReturnTypes[operationInfo.Name] = new OpenAndClrType(returnType, mappedReturnType);
             }

             _info = new MBeanInfo(originalBeanInfo.ClassName, originalBeanInfo.Description,
                                          attributes, constructors, operations, originalBeanInfo.Notifications);
        }
 /// <summary>
 /// Creates new <see cref="OpenMBeanAttributeInfoSupport"/> wrapping provided <see cref="MBeanAttributeInfo"/> value.
 /// </summary>
 /// <param name="wrappedInfo">Open MBean attribute metadata object to be wrappped.</param>
 public OpenMBeanAttributeInfoSupport(MBeanAttributeInfo wrappedInfo)
 {
     _wrappedInfo = wrappedInfo;
 }
예제 #10
0
 public JmxAttributeRepresentation(ObjectName objectName, MBeanAttributeInfo attrInfo) : base("jmxAttribute")
 {
     this.ObjectName = objectName;
     this.AttrInfo   = attrInfo;
 }
 public MBeanInternalAttributeInfo(PropertyInfo propInfo, IMBeanInfoFactory factory)
 {
     _property = propInfo;
      _attributeInfo = factory.CreateMBeanAttributeInfo(propInfo);
 }
 /// <summary>
 /// Creates new <see cref="OpenMBeanAttributeInfoSupport"/> wrapping provided <see cref="MBeanAttributeInfo"/> value.
 /// </summary>
 /// <param name="wrappedInfo">Open MBean attribute metadata object to be wrappped.</param>
 public OpenMBeanAttributeInfoSupport(MBeanAttributeInfo wrappedInfo)
 {
     _wrappedInfo = wrappedInfo;
 }
예제 #13
0
        /// <exception cref="System.IO.IOException"/>
        private void WriteAttribute(JsonGenerator jg, ObjectName oname, MBeanAttributeInfo
                                    attr)
        {
            if (!attr.IsReadable())
            {
                return;
            }
            string attName = attr.GetName();

            if ("modelerType".Equals(attName))
            {
                return;
            }
            if (attName.IndexOf("=") >= 0 || attName.IndexOf(":") >= 0 || attName.IndexOf(" "
                                                                                          ) >= 0)
            {
                return;
            }
            object value = null;

            try
            {
                value = mBeanServer.GetAttribute(oname, attName);
            }
            catch (RuntimeMBeanException e)
            {
                // UnsupportedOperationExceptions happen in the normal course of business,
                // so no need to log them as errors all the time.
                if (e.InnerException is NotSupportedException)
                {
                    Log.Debug("getting attribute " + attName + " of " + oname + " threw an exception"
                              , e);
                }
                else
                {
                    Log.Error("getting attribute " + attName + " of " + oname + " threw an exception"
                              , e);
                }
                return;
            }
            catch (RuntimeErrorException e)
            {
                // RuntimeErrorException happens when an unexpected failure occurs in getAttribute
                // for example https://issues.apache.org/jira/browse/DAEMON-120
                Log.Debug("getting attribute " + attName + " of " + oname + " threw an exception"
                          , e);
                return;
            }
            catch (AttributeNotFoundException)
            {
                //Ignored the attribute was not found, which should never happen because the bean
                //just told us that it has this attribute, but if this happens just don't output
                //the attribute.
                return;
            }
            catch (MBeanException e)
            {
                //The code inside the attribute getter threw an exception so log it, and
                // skip outputting the attribute
                Log.Error("getting attribute " + attName + " of " + oname + " threw an exception"
                          , e);
                return;
            }
            catch (RuntimeException e)
            {
                //For some reason even with an MBeanException available to them Runtime exceptions
                //can still find their way through, so treat them the same as MBeanException
                Log.Error("getting attribute " + attName + " of " + oname + " threw an exception"
                          , e);
                return;
            }
            catch (ReflectionException e)
            {
                //This happens when the code inside the JMX bean (setter?? from the java docs)
                //threw an exception, so log it and skip outputting the attribute
                Log.Error("getting attribute " + attName + " of " + oname + " threw an exception"
                          , e);
                return;
            }
            catch (InstanceNotFoundException)
            {
                //Ignored the mbean itself was not found, which should never happen because we
                //just accessed it (perhaps something unregistered in-between) but if this
                //happens just don't output the attribute.
                return;
            }
            WriteAttribute(jg, attName, value);
        }
예제 #14
0
        private void CreateMBeanInfo()
        {
            bool needsMinMaxResetOperation            = false;
            IList <MBeanAttributeInfo> attributesInfo = new AList <MBeanAttributeInfo>();

            MBeanOperationInfo[] operationsInfo = null;
            numEntriesInRegistry = metricsRegistry.Size();
            foreach (MetricsBase o in metricsRegistry.GetMetricsList())
            {
                if (typeof(MetricsTimeVaryingRate).IsInstanceOfType(o))
                {
                    // For each of the metrics there are 3 different attributes
                    attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName() + NumOps, "java.lang.Integer"
                                                                  , o.GetDescription(), true, false, false));
                    attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName() + AvgTime, "java.lang.Long"
                                                                  , o.GetDescription(), true, false, false));
                    attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName() + MinTime, "java.lang.Long"
                                                                  , o.GetDescription(), true, false, false));
                    attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName() + MaxTime, "java.lang.Long"
                                                                  , o.GetDescription(), true, false, false));
                    needsMinMaxResetOperation = true;
                    // the min and max can be reset.
                    // Note the special attributes (AVG_TIME, MIN_TIME, ..) are derived from metrics
                    // Rather than check for the suffix we store them in a map.
                    metricsRateAttributeMod[o.GetName() + NumOps]  = o;
                    metricsRateAttributeMod[o.GetName() + AvgTime] = o;
                    metricsRateAttributeMod[o.GetName() + MinTime] = o;
                    metricsRateAttributeMod[o.GetName() + MaxTime] = o;
                }
                else
                {
                    if (typeof(MetricsIntValue).IsInstanceOfType(o) || typeof(MetricsTimeVaryingInt).
                        IsInstanceOfType(o))
                    {
                        attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName(), "java.lang.Integer", o
                                                                      .GetDescription(), true, false, false));
                    }
                    else
                    {
                        if (typeof(MetricsLongValue).IsInstanceOfType(o) || typeof(MetricsTimeVaryingLong
                                                                                   ).IsInstanceOfType(o))
                        {
                            attributesInfo.AddItem(new MBeanAttributeInfo(o.GetName(), "java.lang.Long", o.GetDescription
                                                                              (), true, false, false));
                        }
                        else
                        {
                            MetricsUtil.Log.Error("unknown metrics type: " + o.GetType().FullName);
                        }
                    }
                }
                if (needsMinMaxResetOperation)
                {
                    operationsInfo = new MBeanOperationInfo[] { new MBeanOperationInfo(ResetAllMinMaxOp
                                                                                       , "Reset (zero) All Min Max", null, "void", MBeanOperationInfo.Action) };
                }
            }
            MBeanAttributeInfo[] attrArray = new MBeanAttributeInfo[attributesInfo.Count];
            mbeanInfo = new MBeanInfo(this.GetType().FullName, mbeanDescription, Collections.ToArray
                                          (attributesInfo, attrArray), null, operationsInfo, null);
        }