use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_0_10 method convertToStoredMessage.
private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final AMQMessage message_0_8) {
final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(message_0_8);
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 message_0_8.getMessageNumber();
}
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
return message_0_8.getContent(offset, length);
}
@Override
public int getContentSize() {
return messageMetaData_0_10.getContentSize();
}
@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_Internal_to_v0_8 method convertToStoredMessage.
private StoredMessage<MessageMetaData> convertToStoredMessage(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
Object messageBody = serverMsg.getMessageBody();
ObjectToMimeContentConverter converter = MimeContentConverterRegistry.getBestFitObjectToMimeContentConverter(messageBody);
final byte[] messageContent;
try {
messageContent = converter == null ? new byte[] {} : converter.toMimeContent(messageBody);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from Internal to 0-8 because" + " conversion of message content failed.", e);
}
String mimeType = converter == null ? null : converter.getMimeType();
mimeType = improveMimeType(serverMsg, mimeType);
final MessageMetaData messageMetaData_0_8 = convertMetaData(serverMsg, addressSpace, mimeType, messageContent.length);
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(messageContent, offset, length);
}
@Override
public int getContentSize() {
return messageContent.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 ServerSessionDelegate method messageTransfer.
@Override
public void messageTransfer(ServerSession ssn, final MessageTransfer xfr) {
try {
if (ssn.blockingTimeoutExceeded()) {
getEventLogger(ssn).message(ChannelMessages.FLOW_CONTROL_IGNORED());
ssn.close(ErrorCodes.MESSAGE_TOO_LARGE, "Session flow control was requested, but not enforced by sender");
} else if (xfr.getBodySize() > ssn.getConnection().getMaxMessageSize()) {
exception(ssn, xfr, ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED, "Message size of " + xfr.getBodySize() + " greater than allowed maximum of " + ssn.getConnection().getMaxMessageSize());
} else {
final MessageDestination destination = getDestinationForMessage(ssn, xfr);
final DeliveryProperties delvProps = xfr.getHeader() == null ? null : xfr.getHeader().getDeliveryProperties();
if (delvProps != null && delvProps.hasTtl() && !delvProps.hasExpiration()) {
delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
}
final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
final NamedAddressSpace virtualHost = getAddressSpace(ssn);
try {
ssn.getAMQPConnection().checkAuthorizedMessagePrincipal(getMessageUserId(xfr));
ssn.authorisePublish(destination, messageMetaData.getRoutingKey(), messageMetaData.isImmediate(), ssn.getAMQPConnection().getLastReadTime());
} catch (AccessControlException e) {
ExecutionErrorCode errorCode = ExecutionErrorCode.UNAUTHORIZED_ACCESS;
exception(ssn, xfr, errorCode, e.getMessage());
return;
}
final MessageStore store = virtualHost.getMessageStore();
final StoredMessage<MessageMetaData_0_10> storeMessage = createStoreMessage(xfr, messageMetaData, store);
final MessageTransferMessage message = new MessageTransferMessage(storeMessage, ssn.getReference());
MessageReference<MessageTransferMessage> reference = message.newReference();
try {
final InstanceProperties instanceProperties = new InstanceProperties() {
@Override
public Object getProperty(final Property prop) {
switch(prop) {
case EXPIRATION:
return message.getExpiration();
case IMMEDIATE:
return message.isImmediate();
case MANDATORY:
return (delvProps == null || !delvProps.getDiscardUnroutable()) && xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT;
case PERSISTENT:
return message.isPersistent();
case REDELIVERED:
return delvProps.getRedelivered();
}
return null;
}
};
RoutingResult<MessageTransferMessage> routingResult = ssn.enqueue(message, instanceProperties, destination);
boolean explictlyRejected = routingResult.containsReject(RejectType.LIMIT_EXCEEDED);
if (!routingResult.hasRoutes() || explictlyRejected) {
boolean closeWhenNoRoute = ssn.getAMQPConnection().getPort().getCloseWhenNoRoute();
boolean discardUnroutable = delvProps != null && delvProps.getDiscardUnroutable();
if (!discardUnroutable && xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT) {
RangeSet rejects = RangeSetFactory.createRangeSet();
rejects.add(xfr.getId());
MessageReject reject = new MessageReject(rejects, MessageRejectCode.UNROUTABLE, "Unroutable");
ssn.invoke(reject);
} else if (!discardUnroutable && closeWhenNoRoute && explictlyRejected) {
ExecutionErrorCode code = ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED;
String errorMessage = String.format("No route for message with destination '%s' and routing key '%s' : %s", xfr.getDestination(), message.getInitialRoutingAddress(), routingResult.getRejectReason());
ExecutionException ex = new ExecutionException();
ex.setErrorCode(code);
ex.setDescription(errorMessage);
ssn.invoke(ex);
ssn.close(ErrorCodes.RESOURCE_ERROR, errorMessage);
return;
} else {
getEventLogger(ssn).message(ExchangeMessages.DISCARDMSG(destination.getName(), messageMetaData.getRoutingKey()));
}
}
// TODO: we currently do not send MessageAccept when AcceptMode is EXPLICIT
if (ssn.isTransactional()) {
ssn.processed(xfr);
} else {
ssn.recordFuture(Futures.immediateFuture(null), new CommandProcessedAction(ssn, xfr));
}
} catch (VirtualHostUnavailableException e) {
getServerConnection(ssn).sendConnectionCloseAsync(ConnectionCloseCode.CONNECTION_FORCED, e.getMessage());
} finally {
reference.release();
}
}
} finally {
xfr.dispose();
}
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class AbstractQueue method enqueue.
// ------ Enqueue / Dequeue
@Override
public final void enqueue(ServerMessage message, Action<? super MessageInstance> action, MessageEnqueueRecord enqueueRecord) {
if (_recovering.get() != RECOVERED) {
_enqueuingWhileRecovering.incrementAndGet();
boolean addedToRecoveryQueue;
try {
if (addedToRecoveryQueue = (_recovering.get() == RECOVERING)) {
_postRecoveryQueue.add(new EnqueueRequest(message, action, enqueueRecord));
}
} finally {
_enqueuingWhileRecovering.decrementAndGet();
}
if (!addedToRecoveryQueue) {
while (_recovering.get() != RECOVERED) {
Thread.yield();
}
doEnqueue(message, action, enqueueRecord);
}
} else {
doEnqueue(message, action, enqueueRecord);
}
final StoredMessage storedMessage = message.getStoredMessage();
if ((_virtualHost.isOverTargetSize() || QpidByteBuffer.getAllocatedDirectMemorySize() > _flowToDiskThreshold) && storedMessage.isInMemory()) {
storedMessage.flowToDisk();
}
}
use of org.apache.qpid.server.store.StoredMessage in project qpid-broker-j by apache.
the class InternalMessage method createReadOnlyHandle.
private static StoredMessage<InternalMessageMetaData> createReadOnlyHandle(final long messageNumber, final boolean persistent, final InternalMessageHeader header, final Object messageBody) {
try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream()) {
try (ObjectOutputStream os = new ObjectOutputStream(bytesOut)) {
os.writeObject(messageBody);
final byte[] bytes = bytesOut.toByteArray();
final InternalMessageMetaData metaData = InternalMessageMetaData.create(persistent, header, bytes.length);
final int metadataSize = metaData.getStorableSize();
return new StoredMessage<InternalMessageMetaData>() {
@Override
public InternalMessageMetaData getMetaData() {
return metaData;
}
@Override
public long getMessageNumber() {
return messageNumber;
}
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
return QpidByteBuffer.wrap(bytes, offset, length);
}
@Override
public int getContentSize() {
return bytes.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() {
}
};
}
} catch (IOException e) {
throw new ConnectionScopedRuntimeException("Unexpected IO Exception on operation in memory", e);
}
}
Aggregations