本文整理汇总了Java中org.apache.activemq.artemis.api.core.ActiveMQBuffer类的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQBuffer类的具体用法?Java ActiveMQBuffer怎么用?Java ActiveMQBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActiveMQBuffer类属于org.apache.activemq.artemis.api.core包,在下文中一共展示了ActiveMQBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initMocks
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
protected void initMocks() throws ActiveMQException {
CoreQueueConfiguration q = new CoreQueueConfiguration();
q.setName("q");
ClientSession sesh = mock(ClientSession.class);
producer = mock(ClientProducer.class);
when(sesh.createProducer(q.getAddress())).thenReturn(producer);
msgToQueue = mock(ClientMessage.class);
boolean durable = true;
when(sesh.createMessage(durable)).thenReturn(msgToQueue);
msgBody = mock(ActiveMQBuffer.class);
when(msgToQueue.getBodyBuffer()).thenReturn(msgBody);
connector = new ArtemisQConnector(q, sesh);
}
示例2: broadcastConnectors
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public synchronized void broadcastConnectors() throws Exception {
ActiveMQBuffer buff = ActiveMQBuffers.dynamicBuffer(4096);
buff.writeString(nodeManager.getNodeId().toString());
buff.writeString(uniqueID);
buff.writeInt(connectors.size());
for (TransportConfiguration tcConfig : connectors) {
tcConfig.encode(buff);
}
// Only send as many bytes as we need.
byte[] data = new byte[buff.readableBytes()];
buff.getBytes(buff.readerIndex(), data);
endpoint.broadcast(data);
}
示例3: encode
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public void encode(final ActiveMQBuffer buffer) {
buffer.writeLong(transactionID);
boolean isLargeMessage = isLargeMessage();
buffer.writeBoolean(isLargeMessage);
if (isLargeMessage) {
buffer.writeInt(LargeMessagePersister.getInstance().getEncodeSize((LargeServerMessage)message));
LargeMessagePersister.getInstance().encode(buffer, (LargeServerMessage) message);
} else {
message.getPersister().encode(buffer, message);
}
buffer.writeInt(queueIDs.length);
for (long queueID : queueIDs) {
buffer.writeLong(queueID);
}
}
示例4: failedTransaction
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public void failedTransaction(final long transactionID,
final List<RecordInfo> records,
final List<RecordInfo> recordsToDelete) {
for (RecordInfo record : records) {
if (record.userRecordType == ADD_LARGE_MESSAGE) {
byte[] data = record.data;
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(data);
try {
LargeServerMessage serverMessage = journalStorageManager.parseLargeMessage(messages, buff);
serverMessage.decrementDelayDeletionCount();
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.journalError(e);
}
}
}
}
示例5: testBadProtocol
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Test
public void testBadProtocol() throws Exception {
BufferHandler handler = new BufferHandler() {
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
}
};
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true);
params.put(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME, "myBadProtocol");
NettyConnector connector = new NettyConnector(params, handler, listener, Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()), Executors.newScheduledThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory()));
connector.start();
Assert.assertTrue(connector.isStarted());
Assert.assertNull(connector.createConnection());
connector.close();
Assert.assertFalse(connector.isStarted());
}
示例6: encodeRest
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public void encodeRest(final ActiveMQBuffer buffer) {
buffer.writeString(nodeID);
buffer.writeNullableString(backupGroupName);
buffer.writeBoolean(backup);
buffer.writeLong(currentEventID);
if (connector != null) {
buffer.writeBoolean(true);
connector.encode(buffer);
} else {
buffer.writeBoolean(false);
}
if (backupConnector != null) {
buffer.writeBoolean(true);
backupConnector.encode(buffer);
} else {
buffer.writeBoolean(false);
}
buffer.writeNullableString(scaleDownGroupName);
}
示例7: bufferReceived
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) {
ConnectionEntry conn = connections.get(connectionID);
if (conn != null) {
try {
conn.connection.bufferReceived(connectionID, buffer);
} catch (RuntimeException e) {
ActiveMQServerLogger.LOGGER.disconnectCritical("Error decoding buffer", e);
conn.connection.fail(new ActiveMQException(e.getMessage()));
}
} else {
if (logger.isTraceEnabled()) {
logger.trace("ConnectionID = " + connectionID + " was already closed, so ignoring packet");
}
}
}
示例8: decode
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public Packet decode(final ActiveMQBuffer in, CoreRemotingConnection connection) {
final byte packetType = in.readByte();
//optimized for the most common cases: hottest and commons methods will be inlined and this::decode too due to the byte code size
switch (packetType) {
case SESS_SEND:
return decodeSessionSendMessage(in, connection);
case SESS_ACKNOWLEDGE:
return decodeSessionAcknowledgeMessage(in, connection);
case SESS_PRODUCER_REQUEST_CREDITS:
return decodeRequestProducerCreditsMessage(in, connection);
case SESS_FLOWTOKEN:
return decodeSessionConsumerFlowCreditMessage(in, connection);
default:
return slowPathDecode(in, packetType, connection);
}
}
示例9: streamReadBytes
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
/**
* Utility for reading bytes out of streaming.
* It will return remainingBytes, bytesRead
*
* @param remainingBytes remaining Bytes from previous read. Send it to 0 if it was the first call for the message
* @param buff
* @return a pair of remaining bytes and bytes read
*/
public static Pair<Integer, Integer> streamReadBytes(ActiveMQBuffer buff, int remainingBytes, byte[] value) {
if (remainingBytes == -1) {
return new Pair<>(0, -1);
} else if (remainingBytes == 0) {
byte type = buff.readByte();
if (type != DataConstants.BYTES) {
throw new IllegalStateException("Invalid conversion");
}
remainingBytes = buff.readInt();
}
int read = Math.min(value.length, remainingBytes);
buff.readBytes(value, 0, read);
remainingBytes -= read;
if (remainingBytes == 0) {
remainingBytes = -1;
}
return new Pair<>(remainingBytes, read);
}
示例10: passMessageToClientProducer
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Test
public void passMessageToClientProducer() throws Exception {
ClientMessage msg = mock(ClientMessage.class);
ArtemisMessage adapter = new ArtemisMessage(msg);
when(mockMsgFactory.durableMessage()).thenReturn(adapter);
when(msg.getBodyBuffer()).thenReturn(mock(ActiveMQBuffer.class));
target.sendMessage(QMsgFactory::durableMessage, out -> {});
verify(mockProducer, times(1)).send(any());
}
示例11: onMessageForwardsToMessageHandler
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Test
public void onMessageForwardsToMessageHandler() {
ClientMessage msg = mock(ClientMessage.class);
when(msg.getBodyBuffer()).thenReturn(mock(ActiveMQBuffer.class));
target.onMessage(msg);
assertNotNull(receivedMessage);
assertNotNull(receivedBody);
}
示例12: mockMsgToRead
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
private void mockMsgToRead(int serializedValueLen, byte[] serializedValue) {
ActiveMQBuffer buf = msgMock.getBodyBuffer();
when(buf.readInt()).thenReturn(serializedValueLen);
doAnswer(invocation -> {
byte[] passedInBuffer = (byte[])invocation.getArguments()[0];
System.arraycopy(serializedValue, 0,
passedInBuffer, 0, passedInBuffer.length);
return null;
}).when(buf).readBytes((byte[])any());
}
示例13: receiveMessage
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Test
public void receiveMessage() throws Exception {
String msgData = "msg";
DequeueTask<ArtemisMessage, String> task = newTask(msgData);
ClientMessage qMsg = mock(ClientMessage.class);
ActiveMQBuffer buf = mock(ActiveMQBuffer.class);
when(qMsg.getBodyBuffer()).thenReturn(buf);
ArtemisQConsumer qConsumer = (ArtemisQConsumer) task.receiver();
qConsumer.onMessage(qMsg);
assertThat(receivedMsg.message(), is(qMsg));
assertThat(receivedData, is(msgData));
}
示例14: getFields
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
@Override
public Map<String, Object> getFields(MessageReference ref) throws OpenDataException {
Map<String, Object> rc = super.getFields(ref);
ICoreMessage m = ref.getMessage().toCore();
if (!m.isLargeMessage()) {
ActiveMQBuffer bodyCopy = m.getReadOnlyBodyBuffer();
byte[] bytes = new byte[bodyCopy.readableBytes()];
bodyCopy.readBytes(bytes);
rc.put(CompositeDataConstants.BODY, bytes);
} else {
rc.put(CompositeDataConstants.BODY, new byte[0]);
}
return rc;
}
示例15: readLine
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入依赖的package包/类
public static String readLine(ActiveMQBuffer buffer) {
StringBuilder sb = new StringBuilder("");
char c = buffer.readChar();
while (c != '\n') {
sb.append(c);
c = buffer.readChar();
}
return sb.toString();
}