/** * Starts the management context. * Creates and registers a TransportLoggerControl MBean which enables the user * to enable/disable logging for all transport loggers at once. */ private void createTransportLoggerControl(int port) { try { this.managementContext = new ManagementContext(); this.managementContext.setConnectorPort(port); this.managementContext.start(); } catch (Exception e) { LOG.error("Management context could not be started, reason: " + e, e); } try { this.objectName = new ObjectName(this.managementContext.getJmxDomainName()+":"+ "Type=TransportLoggerControl"); AnnotatedMBean.registerMBean(this.managementContext, new TransportLoggerControl(this.managementContext),this.objectName); this.transportLoggerControlCreated = true; } catch (Exception e) { LOG.error("TransportLoggerControlMBean could not be registered, reason: " + e, e); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static void registerMBean(ManagementContext context, Object object, ObjectName objectName) throws Exception { String mbeanName = object.getClass().getName() + "MBean"; for (Class c : object.getClass().getInterfaces()) { if (mbeanName.equals(c.getName())) { context.registerMBean(new AnnotatedMBean(object, c, objectName), objectName); return; } } context.registerMBean(object, objectName); }
public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception{ ObjectInstance result = null; if (isAllowedToRegister(name)) { result = getMBeanServer().registerMBean(bean, name); this.registeredMBeanNames.put(name, result.getObjectName()); } return result; }
public void stop() { try { if (this.transportLoggerControlCreated) { this.managementContext.unregisterMBean(this.objectName); this.managementContext.stop(); this.managementContext = null; } } catch (Exception e) { LOG.error("TransportLoggerFactory could not be stopped, reason: " + e, e); } }
@Test public void testQueueTempUsageWhenBrokerTempUsageUpdated() throws Exception { ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queue.getQueueName()); QueueViewMBean queueViewMBean = (QueueViewMBean) brokerService.getManagementContext().newProxyInstance( queueViewMBeanName, QueueViewMBean.class, true); // Check that by default the queue's temp limit is the same as the broker's. BrokerView brokerView = brokerService.getAdminView(); long brokerTempLimit = brokerView.getTempLimit(); assertEquals(brokerTempLimit, queueViewMBean.getTempUsageLimit()); // Increase the broker's temp limit and check the queue's limit is updated to the same value. long newBrokerTempLimit = brokerTempLimit + 555; brokerView.setTempLimit(newBrokerTempLimit); assertEquals(brokerView.getTempLimit(), newBrokerTempLimit); assertEquals(queueViewMBean.getTempUsageLimit(), newBrokerTempLimit); } }
@Override protected void registerMbean() { if (getBrokerService().isUseJmx()) { ManagementContext managementContext = getBrokerService().getManagementContext(); try { objectName = new ObjectName(getBrokerService().getBrokerObjectName().toString() + objectNamePropsAppendage); managementContext.registerMBean(new RuntimeConfigurationView(this), objectName); } catch (Exception ignored) { LOG.debug("failed to register RuntimeConfigurationMBean", ignored); } } }
@Override public void stop() throws Exception { if (started.compareAndSet(true, false)) { MBeanServer mbeanServer = getMBeanServer(); for (Map.Entry<ObjectName, ObjectName> entry : registeredMBeanNames.entrySet()) { ObjectName actualName = entry.getValue(); if (actualName != null && beanServer.isRegistered(actualName)) { LOG.debug("Unregistering MBean {}", actualName); mbeanServer.unregisterMBean(actualName); if (namingServiceObjectName != null && getMBeanServer().isRegistered(namingServiceObjectName)) { LOG.debug("Stopping MBean {}", namingServiceObjectName); getMBeanServer().invoke(namingServiceObjectName, "stop", null, null); LOG.debug("Unregistering MBean {}", namingServiceObjectName); getMBeanServer().unregisterMBean(namingServiceObjectName);
public ObjectInstance registerMBean(Object bean, ObjectName name) throws Exception{ ObjectInstance result = getMBeanServer().registerMBean(bean, name); this.registeredMBeanNames.add(name); return result; }
populateMBeanSuppressionMap(); getMBeanServer(); if (getMBeanServer().isRegistered(namingServiceObjectName)) { LOG.debug("Invoking start on mbean: {}", namingServiceObjectName); getMBeanServer().invoke(namingServiceObjectName, "start", null, null);
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) throws Exception{ if (name != null) { ObjectName actualName = this.registeredMBeanNames.get(name); if (actualName != null) { return getMBeanServer().queryNames(actualName, query); } } return getMBeanServer().queryNames(name, query); }
/** * Unregisters the MBean from the MBeanServer of the management context * provided at creation time. * This method is called by the TransportLogger object being managed when * the TransportLogger object is finalized, to avoid the memory leak that * would be caused if MBeans were not unregistered. */ public void unregister() { TransportLoggerView.transportLoggerViews.remove(this); try { this.managementContext.unregisterMBean(this.name); } catch (Exception e) { log.error("Could not unregister MBean for TransportLoggerView " + id + "with name " + this.name.toString() + ", reason: " + e, e); } }
/** * @throws Exception * @see org.apache.activemq.Service#stop() */ @Override public void doStop(ServiceStopper stopper) throws Exception { this.letter.stop(); if (brokerService != null && brokerService.isUseJmx()) { ObjectName brokerObjectName = brokerService.getBrokerObjectName(); brokerService.getManagementContext().unregisterMBean(createPersistenceAdapterName(brokerObjectName.toString(), toString())); } }
public Object getAttribute(ObjectName name, String attribute) throws Exception{ return getMBeanServer().getAttribute(name, attribute); }
tmp.deleteOnExit(); BrokerService brokerService = new BrokerService(); brokerService.setBrokerName("localhost"); brokerService.setDeleteAllMessagesOnStartup(true); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.setDataDirectory(tmp.getAbsolutePath()); brokerService.setPersistent(false); .addConnector("amqp://0.0.0.0:" + PORT + "?transport.transformer=jms" + "&transport.socketBufferSize=65536&ioBufferSize=8192"); connector.setName("amqp"); brokerService.start();
private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception { brokerService = new BrokerService(); brokerService.setBrokerName(BROKER_NAME); brokerService.setUseJmx(false); brokerService.setPersistent(true); brokerService.setDataDirectoryFile(fileSystem.getFile(BROCKERS_LOCATION)); brokerService.setUseShutdownHook(false); brokerService.setSchedulerSupport(false); brokerService.setBrokerId(BROKER_ID); String[] uris = {BROCKER_URI}; brokerService.setTransportConnectorURIs(uris); ManagementContext managementContext = new ManagementContext(); managementContext.setCreateConnector(false); brokerService.setManagementContext(managementContext); brokerService.setPersistenceAdapter(persistenceAdapter); BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()}; brokerService.setPlugins(brokerPlugins); String[] transportConnectorsURIs = {BROCKER_URI}; brokerService.setTransportConnectorURIs(transportConnectorsURIs); brokerService.start(); LOGGER.info("Started embedded activeMq"); } }
@Autowired public ActiveMqMessagingService(DaemonThreadStatsCollector daemonThreadStatsCollector) throws Exception { this.daemonThreadStatsCollector = daemonThreadStatsCollector; SystemEnvironment systemEnvironment = new SystemEnvironment(); broker = new BrokerService(); broker.setBrokerName(BROKER_NAME); broker.setPersistent(false); broker.setUseJmx(systemEnvironment.getActivemqUseJmx()); broker.getManagementContext().setConnectorPort(systemEnvironment.getActivemqConnectorPort()); broker.start(); factory = new ActiveMQConnectionFactory(BROKER_URL); factory.getPrefetchPolicy().setQueuePrefetch(systemEnvironment.getActivemqQueuePrefetch()); factory.setCopyMessageOnSend(false); connection = (ActiveMQConnection) factory.createConnection(); connection.start(); }
protected BrokerService createBroker(String name, boolean deleteMessagesOnStartup, Map<String, Integer> portMap) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setBrokerName(name); brokerService.setDeleteAllMessagesOnStartup(deleteMessagesOnStartup); brokerService.setUseJmx(true); brokerService.getManagementContext().setCreateConnector(false); brokerService.setDataDirectory(DATA_PARENT_DIR + File.separator + "data" + File.separator + name); brokerService.setPersistent(false); brokerService.setSchedulerSupport(false); brokerService.setAdvisorySupport(false); ArrayList<BrokerPlugin> plugins = new ArrayList<BrokerPlugin>(); BrokerPlugin authenticationPlugin = configureAuthentication(); if (authenticationPlugin != null) { plugins.add(authenticationPlugin); } if (!plugins.isEmpty()) { brokerService.setPlugins(plugins.toArray(new BrokerPlugin[0])); } addAdditionalConnectors(brokerService, portMap); return brokerService; }
//@Configuration public class TestBrokerConfig { @Bean( initMethod = "start", destroyMethod = "stop" ) public BrokerService broker() throws Exception { final BrokerService broker = new BrokerService(); broker.addConnector( "stomp://localhost:61614" ); broker.setPersistent( false ); broker.setShutdownHooks( Collections.< Runnable >singletonList( new SpringContextHook() ) ); final ManagementContext managementContext = new ManagementContext(); managementContext.setCreateConnector( true ); broker.setManagementContext( managementContext ); return broker; } }
public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException { return getMBeanServer().getObjectInstance(name); }
protected void unregisterConnectorMBean(TransportConnector connector) throws IOException { if (isUseJmx()) { try { ObjectName objectName = createConnectorObjectName(connector); getManagementContext().unregisterMBean(objectName); } catch (Throwable e) { throw IOExceptionSupport.create( "Transport Connector could not be unregistered in JMX: " + e.getMessage(), e); } } }