Serializer.encode
Code IndexAdd Codota to your IDE (free)

Best code snippets using io.atomix.utils.serializer.Serializer.encode(Showing top 15 results out of 315)

origin: atomix/atomix

/**
 * Handles a heartbeat message.
 */
private byte[] handleHeartbeat(Endpoint endpoint, byte[] message) {
 ClusterHeartbeat heartbeat = SERIALIZER.decode(message);
 failureDetectors.computeIfAbsent(heartbeat.nodeId(), n -> new PhiAccrualFailureDetector()).report();
 activateNode(new StatefulNode(heartbeat.nodeId(), heartbeat.nodeType(), endpoint));
 return SERIALIZER.encode(nodes.values().stream()
   .filter(node -> node.type() == Node.Type.CLIENT)
   .collect(Collectors.toList()));
}
origin: atomix/atomix

@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(nodeId -> {
  Node node = clusterService.getNode(nodeId);
  if (node != null && node.getState() == Node.State.ACTIVE) {
   messagingService.sendAsync(node.endpoint(), topic, payload);
  }
 });
}
origin: atomix/atomix

/**
 * Handles a bootstrap request.
 */
private byte[] handleBootstrap(Endpoint endpoint, byte[] payload) {
 return SERIALIZER.encode(nodes);
}
origin: atomix/atomix

protected <T, U> CompletableFuture<U> sendAndReceive(NodeId nodeId, String type, T request) {
 Endpoint endpoint = endpoint(nodeId);
 if (endpoint == null) {
  return Futures.exceptionalFuture(new ConnectException());
 }
 return messagingService.sendAndReceive(endpoint, type, serializer.encode(request))
   .thenApply(serializer::decode);
}
origin: atomix/atomix

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;
 });
}
origin: atomix/atomix

<T> T copy(T value) {
 return serializer.decode(serializer.encode(value));
}
origin: atomix/atomix

/**
 * Activates the given node.
 */
private void activateNode(StatefulNode node) {
 StatefulNode existingNode = nodes.get(node.id());
 if (existingNode == null) {
  node.setState(State.ACTIVE);
  nodes.put(node.id(), node);
  post(new ClusterEvent(ClusterEvent.Type.NODE_ADDED, node));
  post(new ClusterEvent(ClusterEvent.Type.NODE_ACTIVATED, node));
  sendHeartbeat(node.endpoint(), SERIALIZER.encode(new ClusterHeartbeat(localNode.id(), localNode.type())));
 } else if (existingNode.getState() == State.INACTIVE) {
  existingNode.setState(State.ACTIVE);
  post(new ClusterEvent(ClusterEvent.Type.NODE_ACTIVATED, existingNode));
 }
}
origin: atomix/atomix

/**
 * Stores the current cluster configuration.
 *
 * @param configuration The current cluster configuration.
 */
public synchronized void storeConfiguration(Configuration configuration) {
 log.trace("Store configuration {}", configuration);
 byte[] bytes = serializer.encode(configuration);
 configurationBuffer.position(0)
   .writeByte(1)
   .writeInt(bytes.length)
   .write(bytes);
 configurationBuffer.flush();
}
origin: atomix/atomix

@Override
public <M, R> CompletableFuture<R> send(String topic, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder) {
 NodeId nodeId = getNextNodeId(topic);
 if (nodeId != null) {
  Node node = clusterService.getNode(nodeId);
  if (node != null && node.getState() == Node.State.ACTIVE) {
   byte[] payload = SERIALIZER.encode(new InternalMessage(InternalMessage.Type.DIRECT, encoder.apply(message)));
   return messagingService.sendAndReceive(node.endpoint(), topic, payload).thenApply(decoder);
  }
 }
 return Futures.exceptionalFuture(new MessagingException.NoRemoteHandler());
}
origin: atomix/atomix

protected CompletableFuture<Void> sendAsync(NodeId nodeId, String type, Object request) {
 Endpoint endpoint = endpoint(nodeId);
 if (endpoint != null) {
  return messagingService.sendAsync(endpoint(nodeId), type, serializer.encode(request));
 }
 return CompletableFuture.completedFuture(null);
}
origin: atomix/atomix

@Override
@SuppressWarnings("unchecked")
public <T extends E> Indexed<T> append(T entry) {
 // Store the entry index.
 final long index = getNextIndex();
 // Serialize the entry.
 final byte[] bytes = serializer.encode(entry);
 final int length = bytes.length;
 // Compute the checksum for the entry.
 final Checksum crc32 = new CRC32();
 crc32.update(bytes, 0, length);
 final long checksum = crc32.getValue();
 // Write the entry length and entry to the segment.
 buffer.writeInt(length)
   .writeUnsignedInt(checksum)
   .write(bytes);
 // Update the last entry with the correct index/term/length.
 Indexed<E> indexedEntry = new Indexed<>(index, entry, length);
 this.lastEntry = indexedEntry;
 return (Indexed<T>) indexedEntry;
}
origin: atomix/atomix

/**
 * Sends an anti-entropy advertisement to the given node.
 */
private void sendAdvertisement(Endpoint endpoint) {
 clock.increment();
 ClusterMetadataAdvertisement advertisement = new ClusterMetadataAdvertisement(
   Maps.newHashMap(Maps.transformValues(nodes, node -> new NodeDigest(node.timestamp(), node.tombstone()))));
 messagingService.sendAndReceive(endpoint, ADVERTISEMENT_MESSAGE, SERIALIZER.encode(advertisement))
   .whenComplete((response, error) -> {
    if (error == null) {
     Set<NodeId> nodes = SERIALIZER.decode(response);
     for (NodeId nodeId : nodes) {
      ReplicatedNode node = this.nodes.get(nodeId);
      if (node != null) {
       sendUpdate(endpoint, new NodeUpdate(node, clock.increment()));
      }
     }
    } else {
     log.warn("Anti-entropy advertisement to {} failed!", endpoint);
    }
   });
}
origin: atomix/atomix

@Override
public <M> CompletableFuture<Void> unicast(String topic, M message, Function<M, byte[]> encoder) {
 NodeId nodeId = getNextNodeId(topic);
 if (nodeId != null) {
  Node node = clusterService.getNode(nodeId);
  if (node != null && node.getState() == Node.State.ACTIVE) {
   byte[] payload = SERIALIZER.encode(new InternalMessage(InternalMessage.Type.DIRECT, encoder.apply(message)));
   return messagingService.sendAsync(node.endpoint(), topic, payload);
  }
 }
 return CompletableFuture.completedFuture(null);
}
origin: atomix/atomix

/**
 * Sends the given update to the given node.
 */
private void sendUpdate(Endpoint endpoint, NodeUpdate update) {
 messagingService.sendAsync(endpoint, UPDATE_MESSAGE, SERIALIZER.encode(update));
}
origin: atomix/atomix

byte[] encode(Object value) {
 return serializer.encode(value);
}
io.atomix.utils.serializerSerializerencode

Javadoc

Serialize the specified object.

Popular methods of Serializer

  • decode
    Deserialize the specified bytes.
  • using
    Creates a new Serializer instance from a Namespace.

Popular classes and methods

  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • addToBackStack (FragmentTransaction)
  • getExternalFilesDir (Context)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)