use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.
the class ServerPacketDecoder method decodeSessionSendMessage.
private SessionSendMessage decodeSessionSendMessage(final ActiveMQBuffer in, CoreRemotingConnection connection) {
final SessionSendMessage sendMessage;
if (connection.isVersionBeforeAddressChange()) {
sendMessage = new SessionSendMessage_1X(new CoreMessage(this.coreMessageObjectPools));
} else {
sendMessage = new SessionSendMessage(new CoreMessage(this.coreMessageObjectPools));
}
sendMessage.decode(in);
return sendMessage;
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.
the class JMSBridgeReconnectionTest method pause.
public static void pause(Packet packet) {
if (packet.getType() == PacketImpl.SESS_SEND) {
SessionSendMessage sendMessage = (SessionSendMessage) packet;
if (sendMessage.getMessage().containsProperty("__AMQ_CID") && count < 0 && !stopped) {
try {
activeMQServer.stop();
} catch (Exception e) {
e.printStackTrace();
}
stopped = true;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopLatch.countDown();
}
}
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.
the class ServerSessionPacketHandler method onSessionSend.
private void onSessionSend(Packet packet) {
this.storageManager.setContext(session.getSessionContext());
try {
Packet response = null;
boolean requiresResponse = false;
try {
final SessionSendMessage message = (SessionSendMessage) packet;
requiresResponse = message.isRequiresResponse();
this.session.send(EmbedMessageUtil.extractEmbedded(message.getMessage()), this.direct);
if (requiresResponse) {
response = new NullResponseMessage();
}
} catch (ActiveMQIOErrorException e) {
response = onActiveMQIOErrorExceptionWhileHandlePacket(e, requiresResponse, response, this.session);
} catch (ActiveMQXAException e) {
response = onActiveMQXAExceptionWhileHandlePacket(e, requiresResponse, response);
} catch (ActiveMQQueueMaxConsumerLimitReached e) {
response = onActiveMQQueueMaxConsumerLimitReachedWhileHandlePacket(e, requiresResponse, response);
} catch (ActiveMQException e) {
response = onActiveMQExceptionWhileHandlePacket(e, requiresResponse, response);
} catch (Throwable t) {
response = onCatchThrowableWhileHandlePacket(t, requiresResponse, response, this.session);
}
sendResponse(packet, response, false, false);
} finally {
this.storageManager.clearContext();
}
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.
the class MessageImplTest method internalMessageCopy.
private void internalMessageCopy() throws Exception {
final long RUNS = 2;
final CoreMessage msg = new CoreMessage(123, 18);
msg.setMessageID(RandomUtil.randomLong());
msg.setAddress(new SimpleString("Batatantkashf aksjfh aksfjh askfdjh askjfh "));
final AtomicInteger errors = new AtomicInteger(0);
int T1_number = 10;
int T2_number = 10;
final CountDownLatch latchAlign = new CountDownLatch(T1_number + T2_number);
final CountDownLatch latchReady = new CountDownLatch(1);
class T1 extends Thread {
@Override
public void run() {
latchAlign.countDown();
try {
latchReady.await();
} catch (Exception ignored) {
}
for (int i = 0; i < RUNS; i++) {
try {
Message newMsg = msg.copy();
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
}
}
final String bigString;
{
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < 500; i++) {
buffer.append(" ");
}
bigString = buffer.toString();
}
class T2 extends Thread {
@Override
public void run() {
latchAlign.countDown();
try {
latchReady.await();
} catch (Exception ignored) {
}
for (int i = 0; i < RUNS; i++) {
ActiveMQBuffer buf = null;
try {
SessionSendMessage ssm = new SessionSendMessage(msg);
buf = ssm.encode(null);
simulateRead(buf);
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
if (buf != null) {
buf.release();
}
}
}
}
}
ArrayList<Thread> threads = new ArrayList<>();
for (int i = 0; i < T1_number; i++) {
T1 t = new T1();
threads.add(t);
t.start();
}
for (int i = 0; i < T2_number; i++) {
T2 t2 = new T2();
threads.add(t2);
t2.start();
}
latchAlign.await();
latchReady.countDown();
for (Thread t : threads) {
t.join();
}
Assert.assertEquals(0, errors.get());
}
use of org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendMessage in project activemq-artemis by apache.
the class CoreMessageTest method sendThroughPackets.
/**
* The message is received, then sent to the other side untouched
*/
@Test
public void sendThroughPackets() {
CoreMessage decodedMessage = decodeMessage();
int encodeSize = decodedMessage.getEncodeSize();
Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);
SessionSendMessage sendMessage = new SessionSendMessage(decodedMessage, true, null);
sendMessage.setChannelID(777);
ActiveMQBuffer buffer = sendMessage.encode(null);
byte[] byteArray = buffer.byteBuf().array();
System.out.println("Sending " + ByteUtil.bytesToHex(buffer.toByteBuffer().array(), 1) + ", bytes = " + byteArray.length);
buffer.readerIndex(5);
SessionSendMessage sendMessageReceivedSent = new SessionSendMessage(new CoreMessage());
sendMessageReceivedSent.decode(buffer);
Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());
Assert.assertTrue(sendMessageReceivedSent.isRequiresResponse());
Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
Aggregations