use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class ChannelImpl method doWrite.
private void doWrite(final Packet packet) {
final ActiveMQBuffer buffer = packet.encode(connection);
connection.getTransportConnection().write(buffer, false, false);
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class ChannelImpl method send.
// This must never called by more than one thread concurrently
private boolean send(final Packet packet, final int reconnectID, final boolean flush, final boolean batch) {
if (invokeInterceptors(packet, interceptors, connection) != null) {
return false;
}
synchronized (sendLock) {
packet.setChannelID(id);
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending packet nonblocking " + packet + " on channelID=" + id);
}
ActiveMQBuffer buffer = packet.encode(connection);
lock.lock();
try {
if (failingOver) {
waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on non-blocking send");
}
// Sanity check
if (transferring) {
throw ActiveMQClientMessageBundle.BUNDLE.cannotSendPacketDuringFailover();
}
if (resendCache != null && packet.isRequiresConfirmations()) {
addResendPacket(packet);
}
} finally {
lock.unlock();
}
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Writing buffer for channelID=" + id);
}
checkReconnectID(reconnectID);
// The actual send must be outside the lock, or with OIO transport, the write can block if the tcp
// buffer is full, preventing any incoming buffers being handled and blocking failover
connection.getTransportConnection().write(buffer, flush, batch);
return true;
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class ClientConsumerImpl method handleCompressedMessage.
/**
* This method deals with messages arrived as regular message but its contents are compressed.
* Such messages come from message senders who are configured to compress large messages, and
* if some of the messages are compressed below the min-large-message-size limit, they are sent
* as regular messages.
* <br>
* However when decompressing the message, we are not sure how large the message could be..
* for that reason we fake a large message controller that will deal with the message as it was a large message
* <br>
* Say that you sent a 1G message full of spaces. That could be just bellow 100K compressed but you wouldn't have
* enough memory to decompress it
*/
private void handleCompressedMessage(final ClientMessageInternal clMessage) throws Exception {
ClientLargeMessageImpl largeMessage = new ClientLargeMessageImpl();
largeMessage.retrieveExistingData(clMessage);
File largeMessageCache = null;
if (session.isCacheLargeMessageClient()) {
largeMessageCache = File.createTempFile("tmp-large-message-" + largeMessage.getMessageID() + "-", ".tmp");
largeMessageCache.deleteOnExit();
}
ClientSessionFactory sf = session.getSessionFactory();
ServerLocator locator = sf.getServerLocator();
long callTimeout = locator.getCallTimeout();
currentLargeMessageController = new LargeMessageControllerImpl(this, largeMessage.getLargeMessageSize(), callTimeout, largeMessageCache);
currentLargeMessageController.setLocal(true);
// sets the packet
ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer();
int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
final byte[] body = ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer());
largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
currentLargeMessageController.addPacket(body, body.length, false);
handleRegularMessage(largeMessage);
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class AbstractJournalStorageManager method loadBindingJournal.
@Override
public JournalLoadInformation loadBindingJournal(final List<QueueBindingInfo> queueBindingInfos, final List<GroupingInfo> groupingInfos, final List<AddressBindingInfo> addressBindingInfos) throws Exception {
List<RecordInfo> records = new ArrayList<>();
List<PreparedTransactionInfo> preparedTransactions = new ArrayList<>();
JournalLoadInformation bindingsInfo = bindingsJournal.load(records, preparedTransactions, null);
HashMap<Long, PersistentQueueBindingEncoding> mapBindings = new HashMap<>();
for (RecordInfo record : records) {
long id = record.id;
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(record.data);
byte rec = record.getUserRecordType();
if (rec == JournalRecordIds.QUEUE_BINDING_RECORD) {
PersistentQueueBindingEncoding bindingEncoding = newQueueBindingEncoding(id, buffer);
mapBindings.put(bindingEncoding.getId(), bindingEncoding);
} else if (rec == JournalRecordIds.ID_COUNTER_RECORD) {
idGenerator.loadState(record.id, buffer);
} else if (rec == JournalRecordIds.ADDRESS_BINDING_RECORD) {
PersistentAddressBindingEncoding bindingEncoding = newAddressBindingEncoding(id, buffer);
addressBindingInfos.add(bindingEncoding);
} else if (rec == JournalRecordIds.GROUP_RECORD) {
GroupingEncoding encoding = newGroupEncoding(id, buffer);
groupingInfos.add(encoding);
} else if (rec == JournalRecordIds.ADDRESS_SETTING_RECORD) {
PersistedAddressSetting setting = newAddressEncoding(id, buffer);
mapPersistedAddressSettings.put(setting.getAddressMatch(), setting);
} else if (rec == JournalRecordIds.SECURITY_RECORD) {
PersistedRoles roles = newSecurityRecord(id, buffer);
mapPersistedRoles.put(roles.getAddressMatch(), roles);
} else if (rec == JournalRecordIds.QUEUE_STATUS_RECORD) {
QueueStatusEncoding statusEncoding = newQueueStatusEncoding(id, buffer);
PersistentQueueBindingEncoding queueBindingEncoding = mapBindings.get(statusEncoding.queueID);
if (queueBindingEncoding != null) {
queueBindingEncoding.addQueueStatusEncoding(statusEncoding);
} else {
// unlikely to happen, so I didn't bother about the Logger method
ActiveMQServerLogger.LOGGER.infoNoQueueWithID(statusEncoding.queueID, statusEncoding.getId());
this.deleteQueueStatus(statusEncoding.getId());
}
} else {
// unlikely to happen
ActiveMQServerLogger.LOGGER.invalidRecordType(rec, new Exception("invalid record type " + rec));
}
}
for (PersistentQueueBindingEncoding queue : mapBindings.values()) {
queueBindingInfos.add(queue);
}
// just to give a hand to GC
mapBindings.clear();
// This will instruct the IDGenerator to beforeStop old records
idGenerator.cleanup();
return bindingsInfo;
}
use of org.apache.activemq.artemis.api.core.ActiveMQBuffer in project activemq-artemis by apache.
the class UTF8Test method testValidateUTFOnDataInputStream.
private void testValidateUTFOnDataInputStream(final String str, final ActiveMQBuffer wrap) throws Exception {
UTF8Util.saveUTF(wrap.byteBuf(), str);
DataInputStream data = new DataInputStream(new ByteArrayInputStream(wrap.toByteBuffer().array()));
String newStr = data.readUTF();
Assert.assertEquals(str, newStr);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream outData = new DataOutputStream(byteOut);
outData.writeUTF(str);
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(byteOut.toByteArray());
newStr = UTF8Util.readUTF(buffer);
Assert.assertEquals(str, newStr);
}
Aggregations