Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.collection.RawIterator<Object[], org.neo4j.internal.kernel.api.exceptions.ProcedureException> apply(org.neo4j.kernel.api.proc.Context ctx, Object[] input, org.neo4j.kernel.api.ResourceTracker resourceTracker) throws org.neo4j.internal.kernel.api.exceptions.ProcedureException
        public override RawIterator <object[], ProcedureException> Apply(Context ctx, object[] input, ResourceTracker resourceTracker)
        {
            string query = input[0].ToString();

            try
            {
                // Find all beans that match the query name pattern
                IEnumerator <ObjectName> names = _jmxServer.queryNames(new ObjectName(query), null).GetEnumerator();

                // Then convert them to a Neo4j type system representation
                return(RawIterator.from(() =>
                {
                    if (!names.hasNext())
                    {
                        return null;
                    }

                    ObjectName name = names.next();
                    try
                    {
                        MBeanInfo beanInfo = _jmxServer.getMBeanInfo(name);
                        return new object[] { name.CanonicalName, beanInfo.Description, ToNeo4jValue(name, beanInfo.Attributes) };
                    }
                    catch (JMException e)
                    {
                        throw new ProcedureException(Status.General.UnknownError, e, "JMX error while accessing `%s`, please report this. Message was: %s", name, e.Message);
                    }
                }));
            }
            catch (MalformedObjectNameException)
            {
                throw new ProcedureException(Org.Neo4j.Kernel.Api.Exceptions.Status_Procedure.ProcedureCallFailed, "'%s' is an invalid JMX name pattern. Valid queries should use" + "the syntax outlined in the javax.management.ObjectName API documentation." + "For instance, try 'org.neo4j:*' to find all JMX beans of the 'org.neo4j' " + "domain, or '*:*' to find every JMX bean.", query);
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _jmxServer     = mock(typeof(MBeanServer));
            _beanName      = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
            _attributeName = "name";

            when(_jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(_beanName));
            when(_jmxServer.getMBeanInfo(_beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo(_attributeName, "someType", "This is the attribute desc.", true, false, false) }, null, null, null));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleCompositeAttributes() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleCompositeAttributes()
        {
            // given
            ObjectName beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");

            when(_jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
            when(_jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo("name", "differenceMaker", "Who makes the difference?", true, false, false) }, null, null, null));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: when(jmxServer.getAttribute(beanName, "name")).thenReturn(new javax.management.openmbean.CompositeDataSupport(new javax.management.openmbean.CompositeType("myComposite", "Composite description", new String[]{"key1", "key2"}, new String[]{"Can't be empty", "Also can't be empty"}, new javax.management.openmbean.OpenType<?>[]{javax.management.openmbean.SimpleType.STRING, javax.management.openmbean.SimpleType.INTEGER}), map("key1", "Hello", "key2", 123)));
            when(_jmxServer.getAttribute(beanName, "name")).thenReturn(new CompositeDataSupport(new CompositeType("myComposite", "Composite description", new string[] { "key1", "key2" }, new string[] { "Can't be empty", "Also can't be empty" }, new OpenType <object>[] { SimpleType.STRING, SimpleType.INTEGER }), map("key1", "Hello", "key2", 123)));

            JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), _jmxServer);

            // when
            RawIterator <object[], ProcedureException> result = procedure.Apply(null, new object[] { "*:*" }, _resourceTracker);

            // then
            assertThat(asList(result), contains(equalTo(new object[] { "org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference", "This is a description", map(_attributeName, map("description", "Who makes the difference?", "value", map("description", "Composite description", "properties", map("key1", "Hello", "key2", 123)))) })));
        }