Exemplo n.º 1
0
  @Override
  public CompositeData[] browse(String filterStr) throws Exception {
    checkStarted();

    clearIO();
    try {
      int pageSize =
          addressSettingsRepository
              .getMatch(queue.getName().toString())
              .getManagementBrowsePageSize();
      int currentPageSize = 0;
      ArrayList<CompositeData> c = new ArrayList<>();
      Filter filter = FilterImpl.createFilter(filterStr);
      queue.flushExecutor();
      try (LinkedListIterator<MessageReference> iterator = queue.totalIterator()) {
        while (iterator.hasNext() && currentPageSize++ < pageSize) {
          MessageReference ref = iterator.next();
          if (filter == null || filter.match(ref.getMessage())) {
            c.add(OpenTypeSupport.convert(ref));
          }
        }
        CompositeData[] rc = new CompositeData[c.size()];
        c.toArray(rc);
        return rc;
      }
    } catch (ActiveMQException e) {
      throw new IllegalStateException(e.getMessage());
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 2
0
  @Override
  public long countMessages(final String filterStr) throws Exception {
    checkStarted();

    clearIO();
    try {
      Filter filter = FilterImpl.createFilter(filterStr);
      if (filter == null) {
        return getMessageCount();
      } else {
        try (LinkedListIterator<MessageReference> iterator = queue.totalIterator()) {
          int count = 0;
          while (iterator.hasNext()) {
            MessageReference ref = iterator.next();
            if (filter.match(ref.getMessage())) {
              count++;
            }
          }
          return count;
        }
      }
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 3
0
  @Override
  public Map<String, Object>[] listMessages(final String filterStr) throws Exception {
    checkStarted();

    clearIO();
    try {
      Filter filter = FilterImpl.createFilter(filterStr);
      List<Map<String, Object>> messages = new ArrayList<>();
      queue.flushExecutor();
      try (LinkedListIterator<MessageReference> iterator = queue.totalIterator()) {
        while (iterator.hasNext()) {
          MessageReference ref = iterator.next();
          if (filter == null || filter.match(ref.getMessage())) {
            Message message = ref.getMessage();
            messages.add(message.toMap());
          }
        }
        return messages.toArray(new Map[messages.size()]);
      }
    } catch (ActiveMQException e) {
      throw new IllegalStateException(e.getMessage());
    } finally {
      blockOnIO();
    }
  }
Exemplo n.º 4
0
  protected Map<String, Object>[] getFirstMessage() throws Exception {
    checkStarted();

    clearIO();
    try {
      List<Map<String, Object>> messages = new ArrayList<>();
      queue.flushExecutor();
      try (LinkedListIterator<MessageReference> iterator = queue.totalIterator()) {
        // returns just the first, as it's the first only
        if (iterator.hasNext()) {
          MessageReference ref = iterator.next();
          Message message = ref.getMessage();
          messages.add(message.toMap());
        }
        return messages.toArray(new Map[1]);
      }
    } finally {
      blockOnIO();
    }
  }