/** * Compute the CRC32 of a byte buffer from a given offset (relative to the buffer's current position) * * @param buffer The buffer with the underlying data * @param offset The offset relative to the current position * @param size The number of bytes beginning from the offset to include * @return The CRC32 */ public static long crc32(ByteBuffer buffer, int offset, int size) { Crc32 crc = new Crc32(); Checksums.update(crc, buffer, offset, size); return crc.getValue(); }
private BrokerConfig() { brokerName = ""; brokerRole = BrokerRole.STANDBY; brokerAddress = NetworkUtils.getLocalAddress(); masterAddress = ""; readonly = true; }
public static boolean intersection(List<byte[]> source, List<byte[]> target) { for (byte[] bytes : target) { if (contains(source, bytes)) { return true; } } return false; } }
public ConsumeParam(String subject, String group, boolean isBroadcast, boolean isConsumeMostOnce, TagType tagType, Set<String> tags, String clientId) { this.subject = subject; this.group = group; this.originSubject = RetrySubjectUtils.isRetrySubject(subject) ? RetrySubjectUtils.getRealSubject(subject) : subject; this.retrySubject = RetrySubjectUtils.buildRetrySubject(originSubject, group); this.consumerId = clientId; this.isBroadcast = isBroadcast; this.isConsumeMostOnce = isConsumeMostOnce; this.tagType = tagType; this.tags = tags; }
private void readTags(ByteBuf input, BaseMessage message, byte flag) { if (!Flags.hasTags(flag)) return; final byte tagsSize = input.readByte(); for (int i = 0; i < tagsSize; i++) { final String tag = PayloadHolderUtils.readString(input); message.addTag(tag); } }
public static void writeString(String s, ByteBuf out) { byte[] bs = CharsetUtils.toUTF8Bytes(s); out.writeShort((short) bs.length); out.writeBytes(bs); }
public void heartbeat(String consumerId, String subject, String group) { final String realSubject = RetrySubjectUtils.getRealSubject(subject); final String retrySubject = RetrySubjectUtils.buildRetrySubject(realSubject, group); refreshSubscriber(realSubject, group, consumerId); refreshSubscriber(retrySubject, group, consumerId); }
/** * Compute the CRC32 of the byte array * * @param bytes The array to compute the checksum for * @return The CRC32 */ public static long crc32(byte[] bytes) { return crc32(bytes, 0, bytes.length); }
/** * Compute the CRC32 of the segment of the byte array given by the specified size and offset * * @param bytes The bytes to checksum * @param offset the offset at which to begin checksumming * @param size the number of bytes to checksum * @return The CRC32 */ public static long crc32(byte[] bytes, int offset, int size) { Crc32 crc = new Crc32(); crc.update(bytes, offset, size); return crc.getValue(); }
private String getCurrentNode() { return NetworkUtils.getLocalHostname(); }
public static String readString(ByteBuffer in) { int len = in.getShort(); byte[] bs = new byte[len]; in.get(bs); return CharsetUtils.toUTF8String(bs); }
private static boolean matchTags(List<byte[]> messageTags, List<byte[]> requestTags, int tagTypeCode) { if (tagTypeCode == TagType.AND.getCode()) { return ListUtils.containsAll(messageTags, requestTags); } if (tagTypeCode == TagType.OR.getCode()) { return ListUtils.intersection(messageTags, requestTags); } return false; } }
/** Create a new PureJavaCrc32 object. */ public Crc32() { reset(); }
public static void update(Checksum checksum, ByteBuffer buffer, int length) { update(checksum, buffer, 0, length); }
public static String getRealSubject(final String subject) { final Optional<String> optional = getSubject(subject); if (optional.isPresent()) { return optional.get(); } return subject; }
public static void writeString(String s, ByteBuffer out) { byte[] bs = CharsetUtils.toUTF8Bytes(s); out.putShort((short) bs.length); out.put(bs); }
public static boolean containsAll(List<byte[]> source, List<byte[]> target) { if (source.size() < target.size()) return false; for (byte[] bytes : target) if (!contains(source, bytes)) { return false; } return true; }
public static String readString(ByteBuf in) { int len = in.readShort(); byte[] bs = new byte[len]; in.readBytes(bs); return CharsetUtils.toUTF8String(bs); }
private void writeString(String str, ByteBuf out) { byte[] bytes = CharsetUtils.toUTF8Bytes(str); if (bytes != null) { out.writeShort((short) bytes.length); out.writeBytes(bytes); } else { out.writeShort(0); } } }
private void writeString(String str, ByteBuf out) { byte[] bytes = CharsetUtils.toUTF8Bytes(str); if (bytes != null) { out.writeShort((short) bytes.length); out.writeBytes(bytes); } else { out.writeShort(0); } }