当前位置: 首页>>代码示例>>Java>>正文


Java ActiveMQBuffer.readerIndex方法代码示例

本文整理汇总了Java中org.apache.activemq.artemis.api.core.ActiveMQBuffer.readerIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQBuffer.readerIndex方法的具体用法?Java ActiveMQBuffer.readerIndex怎么用?Java ActiveMQBuffer.readerIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.artemis.api.core.ActiveMQBuffer的用法示例。


在下文中一共展示了ActiveMQBuffer.readerIndex方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTransportConfiguration

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Test
public void testTransportConfiguration() throws Exception {
   Map<String, Object> params = new HashMap<>();
   params.put(TransportConstants.PORT_PROP_NAME, 5665);
   params.put(TransportConstants.HOST_PROP_NAME, RandomUtil.randomString());
   TransportConfiguration config = new TransportConfiguration(NettyConnectorFactory.class.getName(), params);

   ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(TransportConfigurationEncodingSupport.getEncodeSize(config));
   TransportConfigurationEncodingSupport.encode(buffer, config);

   assertEquals(buffer.capacity(), buffer.writerIndex());
   buffer.readerIndex(0);

   TransportConfiguration decoded = TransportConfigurationEncodingSupport.decode(buffer);
   assertNotNull(decoded);

   assertEquals(config.getName(), decoded.getName());
   assertEquals(config.getFactoryClassName(), decoded.getFactoryClassName());
   assertEquals(config.getParams().size(), decoded.getParams().size());
   for (String key : config.getParams().keySet()) {
      assertEquals(config.getParams().get(key).toString(), decoded.getParams().get(key).toString());
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:24,代码来源:TransportConfigurationEncodingSupportTest.java

示例2: streamReadByte

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
public static byte streamReadByte(ActiveMQBuffer buff) {
   int index = buff.readerIndex();
   try {
      byte type = buff.readByte();
      switch (type) {
         case DataConstants.BYTE:
            return buff.readByte();
         case DataConstants.STRING:
            String s = buff.readNullableString();
            return Byte.parseByte(s);
         default:
            throw new IllegalStateException("Invalid conversion");
      }
   } catch (NumberFormatException e) {
      buff.readerIndex(index);
      throw e;
   }

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:StreamMessageUtil.java

示例3: testTransportConfigurations

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Test
public void testTransportConfigurations() throws Exception {
   List<Pair<TransportConfiguration, TransportConfiguration>> connectorConfigs = new ArrayList<>();
   Map<String, Object> liveParams = new HashMap<>();
   liveParams.put(TransportConstants.PORT_PROP_NAME, 5665);
   TransportConfiguration live1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams);
   Map<String, Object> backupParams = new HashMap<>();
   backupParams.put(TransportConstants.PORT_PROP_NAME, 5775);
   TransportConfiguration backup1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), backupParams);
   Map<String, Object> liveParams2 = new HashMap<>();
   liveParams2.put(TransportConstants.PORT_PROP_NAME, 6665);
   TransportConfiguration live2 = new TransportConfiguration(NettyConnectorFactory.class.getName(), liveParams2);

   connectorConfigs.add(new Pair<>(live1, backup1));
   connectorConfigs.add(new Pair<TransportConfiguration, TransportConfiguration>(live2, null));

   ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(TransportConfigurationEncodingSupport.getEncodeSize(connectorConfigs));
   TransportConfigurationEncodingSupport.encodeConfigs(buffer, connectorConfigs);

   assertEquals(buffer.capacity(), buffer.writerIndex());
   buffer.readerIndex(0);

   List<Pair<TransportConfiguration, TransportConfiguration>> decodedConfigs = TransportConfigurationEncodingSupport.decodeConfigs(buffer);
   assertNotNull(decodedConfigs);
   assertEquals(2, decodedConfigs.size());

   assertEquivalent(connectorConfigs.get(0).getA(), decodedConfigs.get(0).getA());
   assertEquivalent(connectorConfigs.get(0).getB(), decodedConfigs.get(0).getB());
   assertEquivalent(connectorConfigs.get(1).getA(), decodedConfigs.get(1).getA());
   assertNull(decodedConfigs.get(1).getB());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:32,代码来源:TransportConfigurationEncodingSupportTest.java

示例4: transform

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Override
public Message transform(final Message messageParameter) {
   ICoreMessage message = messageParameter.toCore();
   SimpleString oldProp = (SimpleString) message.getObjectProperty(new SimpleString("wibble"));

   if (!oldProp.equals(new SimpleString("bing"))) {
      throw new IllegalStateException("Wrong property value!!");
   }

   // Change a property
   message.putStringProperty(new SimpleString("wibble"), new SimpleString("bong"));

   // Change the body
   ActiveMQBuffer buffer = message.getBodyBuffer();

   buffer.readerIndex(0);

   String str = buffer.readString();

   if (!str.equals("doo be doo be doo be doo")) {
      throw new IllegalStateException("Wrong body!!");
   }

   buffer.clear();

   buffer.writeString("dee be dee be dee be dee");

   return message;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:30,代码来源:SimpleTransformer.java

示例5: write

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Override
public void write(final ActiveMQBuffer bytes, final boolean sync, final IOCallback callback) throws Exception {
   bytes.writerIndex(bytes.capacity());
   bytes.readerIndex(0);
   writeDirect(bytes.toByteBuffer(), sync, callback);

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:8,代码来源:FakeSequentialFileFactory.java

示例6: decode

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Override
public void decode(final ActiveMQBuffer buffer) {
   channelID = buffer.readLong();

   decodeRest(buffer);

   size = buffer.readerIndex();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:9,代码来源:PacketImpl.java

示例7: decodeRest

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Override
public void decodeRest(final ActiveMQBuffer buffer) {
   // Buffer comes in after having read standard headers and positioned at Beginning of body part

   receiveMessage(copyMessageBuffer(buffer.byteBuf(), DataConstants.SIZE_LONG + DataConstants.SIZE_INT));

   buffer.readerIndex(buffer.capacity() - DataConstants.SIZE_LONG - DataConstants.SIZE_INT);
   this.consumerID = buffer.readLong();
   this.deliveryCount = buffer.readInt();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:11,代码来源:SessionReceiveMessage.java

示例8: handleCompressedMessage

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:41,代码来源:ClientConsumerImpl.java

示例9: read

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
private int read(StorageManager storage, ActiveMQBuffer fileBuffer, List<PagedMessage> messages) {
   int readMessages = 0;
   while (fileBuffer.readable()) {
      final int position = fileBuffer.readerIndex();

      byte byteRead = fileBuffer.readByte();

      if (byteRead == Page.START_BYTE) {
         if (fileBuffer.readerIndex() + DataConstants.SIZE_INT < fileBuffer.capacity()) {
            int messageSize = fileBuffer.readInt();
            int oldPos = fileBuffer.readerIndex();
            if (fileBuffer.readerIndex() + messageSize < fileBuffer.capacity() && fileBuffer.getByte(oldPos + messageSize) == Page.END_BYTE) {
               PagedMessage msg = new PagedMessageImpl(storageManager);
               msg.decode(fileBuffer);
               byte b = fileBuffer.readByte();
               if (b != Page.END_BYTE) {
                  // Sanity Check: This would only happen if there is a bug on decode or any internal code, as
                  // this
                  // constraint was already checked
                  throw new IllegalStateException("Internal error, it wasn't possible to locate END_BYTE " + b);
               }
               msg.initMessage(storage);
               if (logger.isTraceEnabled()) {
                  logger.trace("Reading message " + msg + " on pageId=" + this.pageId + " for address=" + storeName);
               }
               readMessages++;
               messages.add(msg);
            } else {
               markFileAsSuspect(file.getFileName(), position, messages.size());
               break;
            }
         }
      } else {
         markFileAsSuspect(file.getFileName(), position, messages.size());
         break;
      }
   }
   return readMessages;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:40,代码来源:Page.java

示例10: assertEqualsBuffers

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
public static void assertEqualsBuffers(final int size, final ActiveMQBuffer expected, final ActiveMQBuffer actual) {
   // assertEquals(expected.length, actual.length);
   expected.readerIndex(0);
   actual.readerIndex(0);

   for (int i = 0; i < size; i++) {
      byte b1 = expected.readByte();
      byte b2 = actual.readByte();
      Assert.assertEquals("byte at index " + i, b1, b2);
   }
   expected.resetReaderIndex();
   actual.resetReaderIndex();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:14,代码来源:ActiveMQTestBase.java

示例11: decodeRest

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
@Override
public void decodeRest(final ActiveMQBuffer buffer) {
   // Buffer comes in after having read standard headers and positioned at Beginning of body part

   ByteBuf messageBuffer = copyMessageBuffer(buffer.byteBuf(), 1);
   receiveMessage(messageBuffer);

   buffer.readerIndex(buffer.capacity() - 1);

   requiresResponse = buffer.readBoolean();

}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:SessionSendMessage.java

示例12: sendThroughPackets

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
/** 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());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:CoreMessageTest.java

示例13: sendThroughPacketsClient

import org.apache.activemq.artemis.api.core.ActiveMQBuffer; //导入方法依赖的package包/类
/** The message is received, then sent to the other side untouched */
@Test
public void sendThroughPacketsClient() {
   CoreMessage decodedMessage = decodeMessage();

   int encodeSize = decodedMessage.getEncodeSize();
   Assert.assertEquals(BYTE_ENCODE.capacity(), encodeSize);

   SessionReceiveMessage sendMessage = new SessionReceiveMessage(33, decodedMessage, 7);
   sendMessage.setChannelID(777);

   ActiveMQBuffer buffer = sendMessage.encode(null);

   buffer.readerIndex(5);

   SessionReceiveMessage sendMessageReceivedSent = new SessionReceiveMessage(new CoreMessage());

   sendMessageReceivedSent.decode(buffer);

   Assert.assertEquals(33, sendMessageReceivedSent.getConsumerID());

   Assert.assertEquals(7, sendMessageReceivedSent.getDeliveryCount());

   Assert.assertEquals(encodeSize, sendMessageReceivedSent.getMessage().getEncodeSize());

   Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(sendMessageReceivedSent.getMessage().getReadOnlyBodyBuffer()).toString());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:28,代码来源:CoreMessageTest.java


注:本文中的org.apache.activemq.artemis.api.core.ActiveMQBuffer.readerIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。