/** * Returns the administration view of the broker; used to create and destroy * resources such as queues and topics. Note this method returns null if JMX * is disabled. */ public BrokerView getAdminView() throws Exception { if (adminView == null) { // force lazy creation getBroker(); } return adminView; }
@Override public void start() throws Exception { super.start(); if (location == null) { location = new File(getBrokerService().getBrokerDataDirectory(), "destinations"); } importDestinations(); destinations.addAll(Arrays.asList(getBrokerService().getBroker().getDestinations())); }
/** * Returns the broker's administration connection context used for * configuring the broker at startup */ public ConnectionContext getAdminConnectionContext() throws Exception { return BrokerSupport.getConnectionContext(getBroker()); }
@Override public Broker getRoot() { try { return getBrokerService().getBroker(); } catch (Exception e) { LOG.error("Trying to get Root Broker", e); throw new RuntimeException("The broker from the BrokerService should not throw an exception"); } }
/** * Retrieve a set of all Destinations be used by the Broker * @return all Destinations */ public Set<ActiveMQDestination> getDestinations(){ Set<ActiveMQDestination> result; try { ActiveMQDestination[] destinations = brokerService.getBroker().getDestinations(); result = new HashSet<ActiveMQDestination>(); Collections.addAll(result, destinations); }catch (Exception e){ result = Collections.emptySet(); } return result; }
/** * @return the unique id of the Broker */ public String getBrokerId(){ try { return brokerService.getBroker().getBrokerId().toString(); } catch (Exception e) { return ""; } }
/** * Looks up and lazily creates if necessary the destination for the given * JMS name */ public Destination getDestination(ActiveMQDestination destination) throws Exception { return getBroker().addDestination(getAdminConnectionContext(), destination,false); }
public void startNetworkConnector(final NetworkConnector connector, final ThreadPoolExecutor networkConnectorStartExecutor) throws Exception { startNetworkConnector(connector, getBroker().getDurableDestinations(), networkConnectorStartExecutor); }
public void removeDestination(ActiveMQDestination destination) throws Exception { getBroker().removeDestination(getAdminConnectionContext(), destination, 0); }
@Override public void gc() throws Exception { brokerService.getBroker().gc(); try { brokerService.getPersistenceAdapter().checkpoint(true); } catch (IOException e) { LOG.error("Failed to checkpoint persistence adapter on gc request", e); } }
private synchronized MessageInterceptorFilter getFilter() { if (filter == null) { try { MutableBrokerFilter mutableBrokerFilter = (MutableBrokerFilter) brokerService.getBroker().getAdaptor(MutableBrokerFilter.class); Broker next = mutableBrokerFilter.getNext(); filter = new MessageInterceptorFilter(next); mutableBrokerFilter.setNext(filter); } catch (Exception e) { LOG.error("Failed to create MessageInterceptorFilter", e); } } return filter; } }
public void removeQueue(String queueName) { try { ActiveMQQueue destination = new ActiveMQQueue(queueName); ConnectionContext connectionContext = BrokerSupport.getConnectionContext(broker.getBroker()); Destination brokerDestination = broker.getDestination(destination); List<Subscription> consumers = brokerDestination.getConsumers(); for (Subscription consumer : consumers) { consumer.remove(connectionContext, brokerDestination); brokerDestination.removeSubscription(connectionContext, consumer, 0); } broker.getBroker().removeDestination(connectionContext, destination, 1000); broker.removeDestination(destination); } catch (Exception e) { throw bomb(e); } }
/** * Starts any configured destinations on startup */ protected void startDestinations() throws Exception { if (destinations != null) { ConnectionContext adminConnectionContext = getAdminConnectionContext(); for (int i = 0; i < destinations.length; i++) { ActiveMQDestination destination = destinations[i]; getBroker().addDestination(adminConnectionContext, destination,true); } } if (isUseVirtualTopics()) { startVirtualConsumerDestinations(); } }
/** * Destroys the durable subscription so that messages will no longer be * stored for this subscription */ public void destroy() throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); info.setSubscriptionName(subscriptionName); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); brokerService.getBroker().removeSubscription(context, info); }
@Override public void networkBridgeStopped(BrokerInfo brokerInfo) { try { if (brokerInfo != null) { ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setBooleanProperty("started", false); networkBridges.remove(brokerInfo); ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, brokerInfo, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("network bridge stopped", e); } }
@Override public void destroyDurableSubscriber(String clientId, String subscriberName) throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); info.setSubscriptionName(subscriberName); ConnectionContext context = getConnectionContext(); context.setBroker(safeGetBroker()); context.setClientId(clientId); brokerService.getBroker().removeSubscription(context, info); }
/** * Destroys the durable subscription so that messages will no longer be * stored for this subscription */ @Override public void destroy() throws Exception { RemoveSubscriptionInfo info = new RemoveSubscriptionInfo(); info.setClientId(clientId); info.setSubscriptionName(subscriptionInfo.getSubscriptionName()); ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setClientId(clientId); brokerService.getBroker().removeSubscription(context, info); }
@Test public void testNavigateInterceptors() throws Exception { Broker b = brokerService.getBroker(); Assert.assertTrue(b instanceof BrokerFilter); BrokerFilter bf = (BrokerFilter) b; int count = 0; while (bf != null) { Broker next = bf.getNext(); bf = next instanceof BrokerFilter ? (BrokerFilter) next : null; count++; } // a few Broker interceptors are created because of the config (i.e. AdvisoryBroker) Assert.assertTrue(count > 1); }
@Override public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) { try { if (brokerInfo != null) { ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setBooleanProperty("started", true); advisoryMessage.setBooleanProperty("createdByDuplex", createdByDuplex); advisoryMessage.setStringProperty("remoteIp", remoteIp); networkBridges.putIfAbsent(brokerInfo, advisoryMessage); ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, brokerInfo, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("network bridge started", e); } }
@Override public void nowMasterBroker() { super.nowMasterBroker(); try { ActiveMQTopic topic = AdvisorySupport.getMasterBrokerAdvisoryTopic(); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, null, null, advisoryMessage); } catch (Exception e) { handleFireFailure("now master broker", e); } }