use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueControlImpl method convertMessagesToMaps.
/**
* @param refs
* @return
*/
private Map<String, Object>[] convertMessagesToMaps(List<MessageReference> refs) throws ActiveMQException {
Map<String, Object>[] messages = new Map[refs.size()];
int i = 0;
for (MessageReference ref : refs) {
Message message = ref.getMessage();
messages[i++] = message.toMap();
}
return messages;
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueControlImpl method countMessages.
@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.browserIterator()) {
int count = 0;
try {
while (iterator.hasNext()) {
MessageReference ref = iterator.next();
if (filter.match(ref.getMessage())) {
count++;
}
}
} catch (NoSuchElementException ignored) {
// this could happen through paging browsing
}
return count;
}
}
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueControlImpl method listMessages.
@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.browserIterator()) {
try {
while (iterator.hasNext()) {
MessageReference ref = iterator.next();
if (filter == null || filter.match(ref.getMessage())) {
Message message = ref.getMessage();
messages.add(message.toMap());
}
}
} catch (NoSuchElementException ignored) {
// this could happen through paging browsing
}
return messages.toArray(new Map[messages.size()]);
}
} catch (ActiveMQException e) {
throw new IllegalStateException(e.getMessage());
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueControlImpl method browse.
@Override
public CompositeData[] browse(int page, int pageSize) throws Exception {
String filter = null;
checkStarted();
clearIO();
try {
long index = 0;
long start = (page - 1) * pageSize;
long end = Math.min(page * pageSize, queue.getMessageCount());
ArrayList<CompositeData> c = new ArrayList<>();
Filter thefilter = FilterImpl.createFilter(filter);
queue.flushExecutor();
try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
try {
while (iterator.hasNext() && index < end) {
MessageReference ref = iterator.next();
if (thefilter == null || thefilter.match(ref.getMessage())) {
if (index >= start) {
c.add(OpenTypeSupport.convert(ref));
}
}
index++;
}
} catch (NoSuchElementException ignored) {
// this could happen through paging browsing
}
CompositeData[] rc = new CompositeData[c.size()];
c.toArray(rc);
return rc;
}
} catch (ActiveMQException e) {
throw new IllegalStateException(e.getMessage());
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class QueueControlImpl method getFirstMessage.
protected Map<String, Object>[] getFirstMessage() throws Exception {
checkStarted();
clearIO();
try {
List<Map<String, Object>> messages = new ArrayList<>();
queue.flushExecutor();
try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
// 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();
}
}
Aggregations