private int getConnectionCount(EmbeddedJMS server) throws Exception {
   ManagementService managementService = server.getActiveMQServer().getManagementService();
   ActiveMQServerControl jmsControl =
       (ActiveMQServerControl) managementService.getResource(ResourceNames.BROKER);
   String[] ids = jmsControl.listConnectionIDs();
   if (ids != null) {
     return ids.length;
   }
   return 0;
 }
 @Override
 public void dropDurableSubscription(final String clientID, final String subscriptionName)
     throws Exception {
   String queueName =
       ActiveMQDestination.createQueueNameForDurableSubscription(true, clientID, subscriptionName);
   QueueControl coreQueueControl =
       (QueueControl) managementService.getResource(ResourceNames.CORE_QUEUE + queueName);
   if (coreQueueControl == null) {
     throw new IllegalArgumentException(
         "No subscriptions with name " + queueName + " for clientID " + clientID);
   }
   ActiveMQServerControl serverControl =
       (ActiveMQServerControl) managementService.getResource(ResourceNames.CORE_SERVER);
   serverControl.destroyQueue(queueName);
 }
 public StompProtocolManager(
     final StompProtocolManagerFactory factory,
     final ActiveMQServer server,
     final List<StompFrameInterceptor> incomingInterceptors,
     final List<StompFrameInterceptor> outgoingInterceptors) {
   this.factory = factory;
   this.server = server;
   this.executor = server.getExecutorFactory().getExecutor();
   ManagementService service = server.getManagementService();
   if (service != null) {
     // allow management message to pass
     destinations.add(service.getManagementAddress().toString());
     service.addNotificationListener(this);
   }
   this.incomingInterceptors = incomingInterceptors;
   this.outgoingInterceptors = outgoingInterceptors;
 }
 @Override
 public void dropAllSubscriptions() throws Exception {
   ActiveMQServerControl serverControl =
       (ActiveMQServerControl) managementService.getResource(ResourceNames.CORE_SERVER);
   String[] queues = addressControl.getQueueNames();
   for (String queue : queues) {
     // Drop all subscription shouldn't delete the dummy queue used to identify if the topic exists
     // on the core queues.
     // we will just ignore this queue
     if (!queue.equals(managedTopic.getAddress())) {
       serverControl.destroyQueue(queue);
     }
   }
 }
  @Override
  public int removeMessages(final String filterStr) throws Exception {
    String filter = JMSTopicControlImpl.createFilterFromJMSSelector(filterStr);
    int count = 0;
    String[] queues = addressControl.getQueueNames();
    for (String queue : queues) {
      QueueControl coreQueueControl =
          (QueueControl) managementService.getResource(ResourceNames.CORE_QUEUE + queue);
      if (coreQueueControl != null) {
        count += coreQueueControl.removeMessages(filter);
      }
    }

    return count;
  }
 @Override
 public int countMessagesForSubscription(
     final String clientID, final String subscriptionName, final String filterStr)
     throws Exception {
   String queueName =
       ActiveMQDestination.createQueueNameForDurableSubscription(true, clientID, subscriptionName);
   QueueControl coreQueueControl =
       (QueueControl) managementService.getResource(ResourceNames.CORE_QUEUE + queueName);
   if (coreQueueControl == null) {
     throw new IllegalArgumentException(
         "No subscriptions with name " + queueName + " for clientID " + clientID);
   }
   String filter = JMSTopicControlImpl.createFilterFromJMSSelector(filterStr);
   return coreQueueControl.listMessages(filter).length;
 }
  @Override
  public Map<String, Object>[] listMessagesForSubscription(final String queueName)
      throws Exception {
    QueueControl coreQueueControl =
        (QueueControl) managementService.getResource(ResourceNames.CORE_QUEUE + queueName);
    if (coreQueueControl == null) {
      throw new IllegalArgumentException("No subscriptions with name " + queueName);
    }

    Map<String, Object>[] coreMessages = coreQueueControl.listMessages(null);

    Map<String, Object>[] jmsMessages = new Map[coreMessages.length];

    int i = 0;

    for (Map<String, Object> coreMessage : coreMessages) {
      jmsMessages[i++] = ActiveMQMessage.coreMaptoJMSMap(coreMessage);
    }
    return jmsMessages;
  }
  private List<QueueControl> getQueues(final DurabilityType durability) {
    try {
      List<QueueControl> matchingQueues = new ArrayList<>();
      String[] queues = addressControl.getQueueNames();
      for (String queue : queues) {
        QueueControl coreQueueControl =
            (QueueControl) managementService.getResource(ResourceNames.CORE_QUEUE + queue);

        // Ignore the "special" subscription
        if (coreQueueControl != null
            && !coreQueueControl.getName().equals(addressControl.getAddress())) {
          if (durability == DurabilityType.ALL
              || durability == DurabilityType.DURABLE && coreQueueControl.isDurable()
              || durability == DurabilityType.NON_DURABLE && !coreQueueControl.isDurable()) {
            matchingQueues.add(coreQueueControl);
          }
        }
      }
      return matchingQueues;
    } catch (Exception e) {
      return Collections.emptyList();
    }
  }
  @Override
  public void initQueues(
      Map<Long, QueueBindingInfo> queueBindingInfosMap, List<QueueBindingInfo> queueBindingInfos)
      throws Exception {
    int duplicateID = 0;
    for (QueueBindingInfo queueBindingInfo : queueBindingInfos) {
      queueBindingInfosMap.put(queueBindingInfo.getId(), queueBindingInfo);

      Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());

      boolean isTopicIdentification =
          filter != null
              && filter.getFilterString() != null
              && filter
                  .getFilterString()
                  .toString()
                  .equals(ActiveMQServerImpl.GENERIC_IGNORED_FILTER);

      if (postOffice.getBinding(queueBindingInfo.getQueueName()) != null) {

        if (isTopicIdentification) {
          long tx = storageManager.generateID();
          storageManager.deleteQueueBinding(tx, queueBindingInfo.getId());
          storageManager.commitBindings(tx);
          continue;
        } else {

          SimpleString newName = queueBindingInfo.getQueueName().concat("-" + (duplicateID++));
          ActiveMQServerLogger.LOGGER.queueDuplicatedRenaming(
              queueBindingInfo.getQueueName().toString(), newName.toString());
          queueBindingInfo.replaceQueueName(newName);
        }
      }

      PageSubscription subscription = null;

      if (!isTopicIdentification) {
        subscription =
            pagingManager
                .getPageStore(queueBindingInfo.getAddress())
                .getCursorProvider()
                .createSubscription(queueBindingInfo.getId(), filter, true);
      }

      Queue queue =
          queueFactory.createQueue(
              queueBindingInfo.getId(),
              queueBindingInfo.getAddress(),
              queueBindingInfo.getQueueName(),
              filter,
              subscription,
              queueBindingInfo.getUser(),
              true,
              false,
              queueBindingInfo.isAutoCreated());

      if (queueBindingInfo.isAutoCreated()) {
        queue.setConsumersRefCount(
            new AutoCreatedQueueManagerImpl(
                ((PostOfficeImpl) postOffice).getServer().getJMSQueueDeleter(),
                queueBindingInfo.getQueueName()));
      }

      Binding binding =
          new LocalQueueBinding(queueBindingInfo.getAddress(), queue, nodeManager.getNodeId());

      queues.put(queueBindingInfo.getId(), queue);

      postOffice.addBinding(binding);

      managementService.registerAddress(queueBindingInfo.getAddress());
      managementService.registerQueue(queue, queueBindingInfo.getAddress(), storageManager);
    }
  }