Package javax.management.openmbean

Examples of javax.management.openmbean.TabularData


            mb.setMBeanServer(mbs);
            Map<String, List<String>> query = new HashMap<String, List<String>>();
            query.put(objectName, Arrays.asList("otherMethod", "testMethod(long)", "testMethod(java.lang.String)"));
            query.put(objectName2, Collections.<String>emptyList());
            query.put(objectName3, Collections.<String>emptyList());
            TabularData result = mb.canInvoke(query);
            assertEquals(5, result.size());

            CompositeData cd = result.get(new Object[]{objectName, "testMethod(long)"});
            assertEquals(objectName, cd.get("ObjectName"));
            assertEquals("testMethod(long)", cd.get("Method"));
            assertEquals(true, cd.get("CanInvoke"));
            CompositeData cd2 = result.get(new Object[]{objectName, "testMethod(java.lang.String)"});
            assertEquals(objectName, cd2.get("ObjectName"));
            assertEquals("testMethod(java.lang.String)", cd2.get("Method"));
            assertEquals(false, cd2.get("CanInvoke"));
            CompositeData cd3 = result.get(new Object[]{objectName, "otherMethod"});
            assertEquals(objectName, cd3.get("ObjectName"));
            assertEquals("otherMethod", cd3.get("Method"));
            assertEquals(true, cd3.get("CanInvoke"));
            CompositeData cd4 = result.get(new Object[]{objectName2, ""});
            assertEquals(objectName2, cd4.get("ObjectName"));
            assertEquals("", cd4.get("Method"));
            assertEquals(true, cd4.get("CanInvoke"));
            CompositeData cd5 = result.get(new Object[]{objectName3, ""});
            assertEquals(objectName3, cd5.get("ObjectName"));
            assertEquals("", cd5.get("Method"));
            assertEquals(false, cd5.get("CanInvoke"));
        } finally {
            KarafMBeanServerBuilder.setGuard(prevGuard);
View Full Code Here


    public void testRegisterMBean() throws Exception {
        HttpMBeanImpl httpMBean = new HttpMBeanImpl(new ServletServiceImpl(new ServletEventHandler()));
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(httpMBean, new ObjectName("org.apache.karaf:type=http,name=root"));
       
        TabularData data = httpMBean.getServlets();
    }
View Full Code Here

                    new String[]{"presentationname", "symbolicname", "version"},
                    new String[]{"Presentation Name", "Symbolic Name", "Version"},
                    new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
            TabularType tableType = new TabularType("OBR Resources", "Table of all resources/bundles available in the OBR",
                    bundleType, new String[]{"symbolicname", "version"});
            TabularData table = new TabularDataSupport(tableType);

            Resource[] resources = repositoryAdmin.discoverResources("(|(presentationname=*)(symbolicname=*))");
            for (int i = 0; i < resources.length; i++) {
                try {
                    CompositeData data = new CompositeDataSupport(bundleType,
                            new String[]{"presentationname", "symbolicname", "version"},
                            new Object[]{resources[i].getPresentationName(), resources[i].getSymbolicName(), resources[i].getVersion().toString()});
                    table.put(data);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

View Full Code Here

        EasyMock.expect(instance.getState()).andThrow(new Exception("gotcha"));
        EasyMock.expect(instance.getLocation()).andReturn("somewhere");
        EasyMock.expect(instance.getJavaOpts()).andReturn("someopts");
        EasyMock.replay(instance);
       
        TabularData td = InstanceToTableMapper.tableFrom(Collections.singletonList(instance));
        Collection<?> keys = (Collection<?>) td.keySet().iterator().next();
        Assert.assertEquals("MyInstance", keys.iterator().next());
       
        CompositeData cd = td.get(keys.toArray());
        Assert.assertEquals(1712, cd.get("Pid"));
        Assert.assertEquals("MyInstance", cd.get("Name"));
        Assert.assertEquals(false, cd.get("Is Root"));
        Assert.assertEquals(0, cd.get("SSH Port"));
        Assert.assertEquals(0, cd.get("RMI Registry Port"));
View Full Code Here

        EasyMock.expect(instance.getState()).andReturn("Started");
        EasyMock.expect(instance.getLocation()).andReturn(null);
        EasyMock.expect(instance.getJavaOpts()).andReturn(null);
        EasyMock.replay(instance);
       
        TabularData td = InstanceToTableMapper.tableFrom(Collections.singletonList(instance));       
        Collection<?> keys = (Collection<?>) td.keySet().iterator().next();
        Assert.assertEquals("MyInstance", keys.iterator().next());
       
        CompositeData cd = td.get(keys.toArray());
        Assert.assertEquals(1712, cd.get("Pid"));
        Assert.assertEquals("MyInstance", cd.get("Name"));
        Assert.assertEquals(true, cd.get("Is Root"));
        Assert.assertEquals(0, cd.get("SSH Port"));
        Assert.assertEquals(0, cd.get("RMI Registry Port"));
View Full Code Here

            CompositeType servletType = new CompositeType("Servlet", "HTTP Servlet",
                new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"},
                new String[]{"ID of the bundle that registered the servlet", "Class name of the servlet", "Servlet Name", "Current state of the servlet", "Aliases of the servlet", "URL of the servlet"},
                new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING});
            TabularType tableType = new TabularType("Servlets", "Table of all HTTP servlets", servletType, new String[]{"Bundle-ID", "Servlet Name", "State"});
            TabularData table = new TabularDataSupport(tableType);
            List<ServletInfo> servletInfos = servletService.getServlets();
            for (ServletInfo info : servletInfos) {
           
                CompositeData data = new CompositeDataSupport(servletType,
                        new String[]{"Bundle-ID", "Servlet", "Servlet Name", "State", "Alias", "URL"},
                        new Object[]{info.getBundle().getBundleId(), info.getClassName(), info.getName(), info.getStateString(), info.getAlias(), Arrays.toString(info.getUrls())});
                table.put(data);
           
            }
            return table;
        } catch (Exception e) {
            throw new MBeanException(null, e.getMessage());
View Full Code Here

        InstanceService instanceService = EasyMock.createMock(InstanceService.class);
        EasyMock.expect(instanceService.getInstances()).andReturn(new Instance[]{i1, i2});
        EasyMock.replay(instanceService);

        InstancesMBeanImpl instanceServiceMBean = new InstancesMBeanImpl(instanceService);
        TabularData tabularData = instanceServiceMBean.getInstances();
        Assert.assertEquals(2, tabularData.size());
        CompositeData cd1 = tabularData.get(new Object[]{"i1"});
        Assert.assertTrue(cd1.containsValue("i1"));
        Assert.assertTrue(cd1.containsValue(true));
        Assert.assertTrue(cd1.containsValue(1234));
        Assert.assertTrue(cd1.containsValue(8818));
        Assert.assertTrue(cd1.containsValue(1122));
        Assert.assertTrue(cd1.containsValue(44444));
        Assert.assertTrue(cd1.containsValue("somewhere"));
        Assert.assertTrue(cd1.containsValue("someopts"));
        Assert.assertTrue(cd1.containsValue("Stopped"));

        CompositeData cd2 = tabularData.get(new Object [] {"i2"});
        Assert.assertTrue(cd2.containsValue("i2"));
    }
View Full Code Here

        JMXConnector connector = null;
        try {
            connector = this.getJMXConnector();
            MBeanServerConnection connection = connector.getMBeanServerConnection();
            ObjectName name = new ObjectName("org.apache.karaf:type=web,name=root");
            TabularData webBundles = (TabularData) connection.getAttribute(name, "WebBundles");
            assertEquals(0, webBundles.size());
        } finally {
            close(connector);
        }
    }
View Full Code Here

        assertEquals(isAdmin, connection.invoke(securityMBean, "canInvoke",
                new Object [] {serviceMBean.toString(), "getServices", new String [] {}},
                new String [] {String.class.getName(), String.class.getName(), String[].class.getName()}));

        Map<String, List<String>> map = new HashMap<String, List<String>>();
        TabularData td = (TabularData) connection.invoke(securityMBean, "canInvoke", new Object [] {map}, new String [] {Map.class.getName()});
        assertEquals(0, td.size());

        Map<String, List<String>> map2 = new HashMap<String, List<String>>();
        map2.put(systemMBean.toString(), Collections.<String>emptyList());
        map2.put(serviceMBean.toString(), Arrays.asList("getServices(boolean)", "getServices(long)", "getServices(long,boolean)", "getServices()"));
        TabularData td2 = (TabularData) connection.invoke(securityMBean, "canInvoke", new Object [] {map2}, new String [] {Map.class.getName()});
        assertEquals(5, td2.size());

        CompositeData cd1 = td2.get(new Object [] {serviceMBean.toString(), "getServices(boolean)"});
        assertEquals(serviceMBean.toString(), cd1.get("ObjectName"));
        assertEquals("getServices(boolean)", cd1.get("Method"));
        assertTrue((Boolean) cd1.get("CanInvoke"));

        CompositeData cd2 = td2.get(new Object [] {serviceMBean.toString(), "getServices(long)"});
        assertEquals(serviceMBean.toString(), cd2.get("ObjectName"));
        assertEquals("getServices(long)", cd2.get("Method"));
        assertEquals(isManager, cd2.get("CanInvoke"));

        CompositeData cd3 = td2.get(new Object [] {serviceMBean.toString(), "getServices(long,boolean)"});
        assertEquals(serviceMBean.toString(), cd3.get("ObjectName"));
        assertEquals("getServices(long,boolean)", cd3.get("Method"));
        assertEquals(isAdmin, cd3.get("CanInvoke"));

        CompositeData cd4 = td2.get(new Object [] {serviceMBean.toString(), "getServices()"});
        assertEquals(serviceMBean.toString(), cd4.get("ObjectName"));
        assertEquals("getServices()", cd4.get("Method"));
        assertEquals(isAdmin, cd4.get("CanInvoke"));

        CompositeData cd5 = td2.get(new Object [] {systemMBean.toString(), ""});
        assertEquals(systemMBean.toString(), cd5.get("ObjectName"));
        assertEquals("", cd5.get("Method"));
        assertTrue((Boolean) cd5.get("CanInvoke"));

        Map<String, List<String>> map3 = new HashMap<String, List<String>>();
        map3.put(serviceMBean.toString(), Collections.singletonList("getServices"));
        TabularData td3 = (TabularData) connection.invoke(securityMBean, "canInvoke", new Object [] {map3}, new String [] {Map.class.getName()});
        assertEquals(1, td3.size());

        CompositeData cd6 = td3.get(new Object [] {serviceMBean.toString(), "getServices"});
        assertEquals(serviceMBean.toString(), cd6.get("ObjectName"));
        assertEquals("getServices", cd6.get("Method"));
        assertTrue((Boolean) cd6.get("CanInvoke"));

        Map<String, List<String>> map4 = new HashMap<String, List<String>>();
        map4.put(systemMBean.toString(), Collections.singletonList("halt"));
        TabularData td4 = (TabularData) connection.invoke(securityMBean, "canInvoke", new Object [] {map4}, new String [] {Map.class.getName()});
        assertEquals(1, td4.size());

        CompositeData cd7 = td4.get(new Object [] {systemMBean.toString(), "halt"});
        assertEquals(systemMBean.toString(), cd7.get("ObjectName"));
        assertEquals("halt", cd7.get("Method"));
        assertEquals(isAdmin, cd7.get("CanInvoke"));
    }
View Full Code Here

        data.put("Type", "String");
        CompositeDataSupport cds = new CompositeDataSupport(ct, data);
        tds.put(cds);

        assertJmxInvoke(shouldSucceed, connection, mbean, "update", new Object [] {pid, tds}, new String [] {String.class.getName(), TabularData.class.getName()});
        TabularData td = (TabularData) connection.invoke(mbean, "getProperties", new Object [] {pid}, new String [] {String.class.getName()});
        if (shouldSucceed) {
            assertEquals("bar", td.get(new Object[] {"foo"}).get("Value"));
        }

        String[][] configs = (String[][]) connection.invoke(mbean, "getConfigurations", new Object [] {"(service.pid=" + pid + ")"}, new String [] {String.class.getName()});
        if (shouldSucceed) {
            assertEquals(1, configs.length);
            assertEquals(pid, configs[0][0]);
        }
        assertJmxInvoke(shouldSucceed, connection, mbean, "delete", new Object [] {pid}, new String [] {String.class.getName()});

        TabularDataSupport tds2 = new TabularDataSupport(tt);
        Map<String, Object> data2 = new HashMap<String, Object>();
        data2.put("Key", "a.b.c");
        data2.put("Value", "d.e.f");
        data2.put("Type", "String");
        CompositeDataSupport cds2 = new CompositeDataSupport(ct, data2);
        tds2.put(cds2);

        String suffix2 = infix + "_" + counter.incrementAndGet();
        String pid2 = pidPrefix + suffix2;
        String location2 = "mylocation" + System.currentTimeMillis();
        assertJmxInvoke(shouldSucceed, connection, mbean, "updateForLocation", new Object [] {pid2, location2, tds2}, new String [] {String.class.getName(), String.class.getName(), TabularData.class.getName()});
        TabularData td2 = (TabularData) connection.invoke(mbean, "getPropertiesForLocation", new Object [] {pid2, location2}, new String [] {String.class.getName(), String.class.getName()});
        if (shouldSucceed) {
            assertEquals("d.e.f", td2.get(new Object[] {"a.b.c"}).get("Value"));
        }
        assertJmxInvoke(shouldSucceed, connection, mbean, "deleteForLocation", new Object [] {pid2, location2}, new String [] {String.class.getName(), String.class.getName()});

        if (isAdmin) {
            String suffix3 = infix + "_" + counter.incrementAndGet();
View Full Code Here

TOP

Related Classes of javax.management.openmbean.TabularData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.