use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_10 method convertToStoredMessage.
private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
final byte[] convertedContent = convertedContentAndMimeType.getContent();
final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg, addressSpace, convertedContentAndMimeType.getMimeType(), convertedContent.length);
final int metadataSize = messageMetaData_0_10.getStorableSize();
return new StoredMessage<MessageMetaData_0_10>() {
@Override
public MessageMetaData_0_10 getMetaData() {
return messageMetaData_0_10;
}
@Override
public long getMessageNumber() {
return serverMsg.getMessageNumber();
}
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
return QpidByteBuffer.wrap(convertedContent, offset, length);
}
@Override
public int getContentSize() {
return convertedContent.length;
}
@Override
public int getMetadataSize() {
return metadataSize;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public boolean isInMemory() {
return true;
}
@Override
public boolean flowToDisk() {
return false;
}
@Override
public void reallocate() {
}
};
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8 method convertToStoredMessage.
private StoredMessage<MessageMetaData> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
final byte[] convertedContent = convertedContentAndMimeType.getContent();
final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg, convertedContentAndMimeType.getMimeType(), convertedContent.length, addressSpace);
final int metadataSize = messageMetaData_0_8.getStorableSize();
return new StoredMessage<MessageMetaData>() {
@Override
public MessageMetaData getMetaData() {
return messageMetaData_0_8;
}
@Override
public long getMessageNumber() {
return serverMsg.getMessageNumber();
}
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
return QpidByteBuffer.wrap(convertedContent, offset, length);
}
@Override
public int getContentSize() {
return convertedContent.length;
}
@Override
public int getMetadataSize() {
return metadataSize;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public boolean isInMemory() {
return true;
}
@Override
public boolean flowToDisk() {
return false;
}
@Override
public void reallocate() {
}
};
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class MessageStoreSerializer_v1 method deserialize.
@Override
public void deserialize(final Map<String, UUID> queueMap, final MessageStore store, final InputStream inputStream) throws IOException {
final Deserializer deserializer = new Deserializer(inputStream);
Map<Long, StoredMessage<?>> messageMap = new HashMap<>();
Map<UUID, UUID> queueIdMap = new HashMap<>();
Record nextRecord = deserializer.readRecord();
switch(nextRecord.getType()) {
case VERSION:
break;
default:
throw new IllegalArgumentException("Unexpected record type: " + nextRecord.getType() + " expecting VERSION");
}
nextRecord = deserializer.readRecord();
nextRecord = deserializeQueueMappings(queueMap, queueIdMap, deserializer, nextRecord);
nextRecord = deserializeMessages(messageMap, store, deserializer, nextRecord);
nextRecord = deserializeMessageInstances(store, queueIdMap, messageMap, deserializer, nextRecord);
nextRecord = deserializeDistributedTransactions(store, queueIdMap, messageMap, deserializer, nextRecord);
if (nextRecord.getType() != RecordType.DIGEST) {
throw new IllegalArgumentException("Unexpected record type '" + nextRecord.getType() + "' expecting DIGEST");
}
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecoverer method recover.
@Override
public ListenableFuture<Void> recover(QueueManagingVirtualHost<?> virtualHost) {
EventLogger eventLogger = virtualHost.getEventLogger();
MessageStore store = virtualHost.getMessageStore();
MessageStore.MessageStoreReader storeReader = store.newMessageStoreReader();
MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
Map<Queue<?>, Integer> queueRecoveries = new TreeMap<>();
Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
Map<Long, StoredMessage<?>> unusedMessages = new TreeMap<>();
Map<UUID, Integer> unknownQueuesWithMessages = new HashMap<>();
Map<Queue<?>, Integer> queuesWithUnknownMessages = new HashMap<>();
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
storeReader.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
try {
storeReader.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries, recoveredMessages, unusedMessages, unknownQueuesWithMessages, queuesWithUnknownMessages));
} finally {
if (!unknownQueuesWithMessages.isEmpty()) {
unknownQueuesWithMessages.forEach((queueId, count) -> {
LOGGER.info("Discarded {} entry(s) associated with queue id '{}' as a queue with this " + "id does not appear in the configuration.", count, queueId);
});
}
if (!queuesWithUnknownMessages.isEmpty()) {
queuesWithUnknownMessages.forEach((queue, count) -> {
LOGGER.info("Discarded {} entry(s) associated with queue '{}' as the referenced message " + "does not exist.", count, queue.getName());
});
}
}
for (Map.Entry<Queue<?>, Integer> entry : queueRecoveries.entrySet()) {
Queue<?> queue = entry.getKey();
Integer deliveredCount = entry.getValue();
eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(deliveredCount, queue.getName()));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(queue.getName(), true));
queue.completeRecovery();
}
for (Queue<?> q : virtualHost.getChildren(Queue.class)) {
if (!queueRecoveries.containsKey(q)) {
q.completeRecovery();
}
}
storeReader.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, eventLogger, logSubject, recoveredMessages, unusedMessages));
for (StoredMessage<?> m : unusedMessages.values()) {
LOGGER.debug("Message id '{}' is orphaned, removing", m.getMessageNumber());
m.remove();
}
if (unusedMessages.size() > 0) {
LOGGER.info("Discarded {} orphaned message(s).", unusedMessages.size());
}
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
eventLogger.message(logSubject, MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
return Futures.immediateFuture(null);
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class AsynchronousMessageStoreRecovererTest method testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted.
public void testRecoveryWhenLastRecoveryMessageIsConsumedBeforeRecoveryCompleted() throws Exception {
Queue<?> queue = mock(Queue.class);
when(queue.getId()).thenReturn(UUID.randomUUID());
when(_virtualHost.getChildren(eq(Queue.class))).thenReturn(Collections.singleton(queue));
when(_store.getNextMessageId()).thenReturn(3L);
when(_store.newTransaction()).thenReturn(mock(Transaction.class));
final List<StoredMessage<?>> testMessages = new ArrayList<>();
StoredMessage<?> storedMessage = createTestMessage(1L);
testMessages.add(storedMessage);
StoredMessage<?> orphanedMessage = createTestMessage(2L);
testMessages.add(orphanedMessage);
StoredMessage newMessage = createTestMessage(4L);
testMessages.add(newMessage);
final MessageEnqueueRecord messageEnqueueRecord = mock(MessageEnqueueRecord.class);
UUID id = queue.getId();
when(messageEnqueueRecord.getQueueId()).thenReturn(id);
when(messageEnqueueRecord.getMessageNumber()).thenReturn(1L);
MockStoreReader storeReader = new MockStoreReader(Collections.singletonList(messageEnqueueRecord), testMessages);
when(_store.newMessageStoreReader()).thenReturn(storeReader);
AsynchronousMessageStoreRecoverer recoverer = new AsynchronousMessageStoreRecoverer();
ListenableFuture<Void> result = recoverer.recover(_virtualHost);
assertNull(result.get());
verify(orphanedMessage, times(1)).remove();
verify(newMessage, times(0)).remove();
verify(queue).recover(argThat(new ArgumentMatcher<ServerMessage>() {
@Override
public boolean matches(final Object argument) {
if (argument instanceof ServerMessage) {
ServerMessage serverMessage = (ServerMessage) argument;
return serverMessage.getMessageNumber() == storedMessage.getMessageNumber();
}
return false;
}
}), same(messageEnqueueRecord));
}
Aggregations