byte[] encode(Object value) { return serializer.encode(value); }
/** * Encodes the given object using the configured {@link #userSerializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? userSerializer.encode(object) : null; }
/** * Encodes the given object using the configured {@link #serializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? serializer.encode(object) : null; }
/** * Encodes the given object using the configured {@link #serializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ private <T> byte[] encode(T object) { return object != null ? serializer.encode(object) : null; }
/** * Encodes the given object using the configured {@link #serializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ private <T> byte[] encode(T object) { return object != null ? serializer.encode(object) : null; }
/** * Encodes the given value to a string for internal storage. * * @param value the value to encode * @return the encoded value */ private String encode(Object value) { return BaseEncoding.base16().encode(valueSerializer.encode(value)); }
/** * Encodes the given element to a string for internal storage. * * @param element the element to encode * @return the encoded element */ private String encode(Object element) { return BaseEncoding.base16().encode(elementSerializer.encode(element)); }
<T> T copy(T value) { return serializer.decode(serializer.encode(value)); }
/** * Encodes the given object using the configured {@link #serializer()}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? serializer().encode(object) : null; }
/** * Encodes the given object using the configured {@link #serializer()}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? serializer().encode(object) : null; }
@Override public <U> BackupOutput writeObject(U object) { output.writeObject(object, o -> o != null ? serializer.encode(o) : null); return this; }
protected <T, U> void registerHandler(String type, Function<T, CompletableFuture<U>> handler) { messagingService.registerHandler(type, (e, p) -> { CompletableFuture<byte[]> future = new CompletableFuture<>(); handler.apply(serializer.decode(p)).whenComplete((result, error) -> { if (error == null) { future.complete(serializer.encode(result)); } else { future.completeExceptionally(error); } }); return future; }); }
@Override public PartitionId getPartitionId(Object key) { return partitioner.partition(BaseEncoding.base16().encode(serializer.encode(key)), getPartitionIds()); } }
protected <T, U> CompletableFuture<U> sendAndReceive(MemberId memberId, String type, T request) { Address address = address(memberId); if (address == null) { return Futures.exceptionalFuture(new ConnectException()); } return messagingService.sendAndReceive(address, type, serializer.encode(request)) .thenApply(serializer::decode); }
@Override public void broadcast(String subject, byte[] payload) { if (enabled) { Message message = new Message(subject, payload); byte[] bytes = SERIALIZER.encode(message); ByteBuf buf = serverChannel.alloc().buffer(4 + bytes.length); buf.writeInt(bytes.length).writeBytes(bytes); serverChannel.writeAndFlush(new DatagramPacket(buf, groupAddress)); } }
protected CompletableFuture<Void> sendAsync(MemberId memberId, String type, Object request) { Address address = address(memberId); if (address != null) { return messagingService.sendAsync(address(memberId), type, serializer.encode(request)); } return CompletableFuture.completedFuture(null); }
/** * Unicasts the given update to the given member. * * @param member the member to which to unicast the update * @param update the update to unicast */ private void unicast(SwimMember member, ImmutableMember update) { bootstrapService.getUnicastService().unicast( member.address(), MEMBERSHIP_GOSSIP, SERIALIZER.encode(Lists.newArrayList(update))); }
@Override public void unicast(Address address, String subject, byte[] payload) { Message message = new Message(this.address, subject, payload); byte[] bytes = SERIALIZER.encode(message); ByteBuf buf = channel.alloc().buffer(4 + bytes.length); buf.writeInt(bytes.length).writeBytes(bytes); channel.writeAndFlush(new DatagramPacket(buf, new InetSocketAddress(address.address(), address.port()))); }
@Override public <M> void broadcast(String topic, M message, Function<M, byte[]> encoder) { byte[] payload = SERIALIZER.encode(new InternalMessage(InternalMessage.Type.ALL, encoder.apply(message))); getSubscriberNodes(topic).forEach(memberId -> { Member member = membershipService.getMember(memberId); if (member != null && member.isReachable()) { messagingService.sendAsync(member.address(), topic, payload); } }); }
@Override public <M, R> CompletableFuture<R> send(String topic, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder, Duration timeout) { MemberId memberId = getNextMemberId(topic); if (memberId != null) { Member member = membershipService.getMember(memberId); if (member != null && member.isReachable()) { byte[] payload = SERIALIZER.encode(new InternalMessage(InternalMessage.Type.DIRECT, encoder.apply(message))); return messagingService.sendAndReceive(member.address(), topic, payload, timeout).thenApply(decoder); } } return Futures.exceptionalFuture(new MessagingException.NoRemoteHandler()); }