Codota Logo
PubSubMessage.fromJSON
Code IndexAdd Codota to your IDE (free)

How to use
fromJSON
method
in
com.yahoo.bullet.pubsub.PubSubMessage

Best Java code snippets using com.yahoo.bullet.pubsub.PubSubMessage.fromJSON (Showing top 5 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
DateTime d =
  • Codota Iconnew DateTime()
  • Codota IconDateTimeFormatter formatter;String text;formatter.parseDateTime(text)
  • Codota IconObject instant;new DateTime(instant)
  • Smart code suggestions by Codota
}
origin: com.yahoo.bullet/bullet-core

@Override
public List<PubSubMessage> getMessages() {
  List<PubSubMessage> messages = new ArrayList<>();
  long currentTime = System.currentTimeMillis();
  if (currentTime - lastRequest <= minWait) {
    return messages;
  }
  lastRequest = currentTime;
  for (String url : urls) {
    try (CloseableHttpResponse response = client.execute(makeHttpGet(url))) {
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode == RESTPubSub.OK_200) {
        HttpEntity httpEntity = response.getEntity();
        String message = EntityUtils.toString(httpEntity, RESTPubSub.UTF_8);
        log.debug("Received message from url: {}. Message was {}", url, message);
        messages.add(PubSubMessage.fromJSON(message));
        EntityUtils.consume(httpEntity);
      } else if (statusCode != RESTPubSub.NO_CONTENT_204) {
        // NO_CONTENT_204 indicates there are no new messages - anything else indicates a problem
        log.error("HTTP call to {} failed with status code {} and response {}.", url, statusCode, response);
      }
    } catch (Exception e) {
      log.error("HTTP call to {} failed with error:", url, e);
    }
  }
  return messages;
}
origin: com.yahoo.bullet/bullet-storm

  private void handleResponse(String id, Response response) {
    if (response == null || response.getStatusCode() != OK_200) {
      log.error("Handling error for id {} with response {}", id, response);
      responses.offer(new PubSubMessage(id, DRPCError.CANNOT_REACH_DRPC.asJSONClip()));
      return;
    }
    log.info("Received for id {}: {} {}", response.getStatusCode(), id, response.getStatusText());
    String body = response.getResponseBody();
    PubSubMessage message = PubSubMessage.fromJSON(body);
    log.debug("Received for id {}:\n{}", message.getId(), message.getContent());
    responses.offer(message);
  }
}
origin: bullet-db/bullet-storm

  private void handleResponse(String id, Response response) {
    if (response == null || response.getStatusCode() != OK_200) {
      log.error("Handling error for id {} with response {}", id, response);
      responses.offer(new PubSubMessage(id, DRPCError.CANNOT_REACH_DRPC.asJSONClip()));
      return;
    }
    log.info("Received for id {}: {} {}", response.getStatusCode(), id, response.getStatusText());
    String body = response.getResponseBody();
    PubSubMessage message = PubSubMessage.fromJSON(body);
    log.debug("Received for id {}:\n{}", message.getId(), message.getContent());
    responses.offer(message);
  }
}
origin: com.yahoo.bullet/bullet-storm

@Override
public List<PubSubMessage> getMessages() throws PubSubException {
  // Try and read from DRPC. The DRPCSpout does a sleep for 1 ms if there are no tuples, so we don't have to do it.
  spout.nextTuple();
  if (!collector.haveOutput()) {
    return null;
  }
  // The DRPCSpout only should have emitted one tuple
  List<List<Object>> tuples = collector.reset();
  log.debug("Have a message through DRPC {}", tuples);
  List<Object> tupleAndID = tuples.get(0);
  // The first object is the actual DRPCSpout tuple and the second is the DRPC messageID.
  List<Object> tuple = (List<Object>) tupleAndID.get(0);
  Object drpcID = tupleAndID.get(1);
  // The first object in the tuple is our PubSubMessage as JSON
  String pubSubMessageJSON = (String) tuple.get(0);
  // The second object in the tuple is the serialized returnInfo added by the DRPCSpout
  String returnInfo = (String) tuple.get(1);
  log.debug("Read message\n{}\nfrom DRPC with return information {}", pubSubMessageJSON, returnInfo);
  PubSubMessage pubSubMessage = PubSubMessage.fromJSON(pubSubMessageJSON);
  // Add returnInfo as metadata. Cannot add it to pubSubMessage
  String id = pubSubMessage.getId();
  String content = pubSubMessage.getContent();
  int sequence = pubSubMessage.getSequence();
  PubSubMessage message = new PubSubMessage(id, content, new Metadata(null, returnInfo), sequence);
  emittedIDs.put(ImmutablePair.of(id, sequence), drpcID);
  return Collections.singletonList(message);
}
origin: bullet-db/bullet-storm

@Override
public List<PubSubMessage> getMessages() throws PubSubException {
  // Try and read from DRPC. The DRPCSpout does a sleep for 1 ms if there are no tuples, so we don't have to do it.
  spout.nextTuple();
  if (!collector.haveOutput()) {
    return null;
  }
  // The DRPCSpout only should have emitted one tuple
  List<List<Object>> tuples = collector.reset();
  log.debug("Have a message through DRPC {}", tuples);
  List<Object> tupleAndID = tuples.get(0);
  // The first object is the actual DRPCSpout tuple and the second is the DRPC messageID.
  List<Object> tuple = (List<Object>) tupleAndID.get(0);
  Object drpcID = tupleAndID.get(1);
  // The first object in the tuple is our PubSubMessage as JSON
  String pubSubMessageJSON = (String) tuple.get(0);
  // The second object in the tuple is the serialized returnInfo added by the DRPCSpout
  String returnInfo = (String) tuple.get(1);
  log.debug("Read message\n{}\nfrom DRPC with return information {}", pubSubMessageJSON, returnInfo);
  PubSubMessage pubSubMessage = PubSubMessage.fromJSON(pubSubMessageJSON);
  // Add returnInfo as metadata. Cannot add it to pubSubMessage
  String id = pubSubMessage.getId();
  String content = pubSubMessage.getContent();
  int sequence = pubSubMessage.getSequence();
  PubSubMessage message = new PubSubMessage(id, content, new Metadata(null, returnInfo), sequence);
  emittedIDs.put(ImmutablePair.of(id, sequence), drpcID);
  return Collections.singletonList(message);
}
com.yahoo.bullet.pubsubPubSubMessagefromJSON

Javadoc

Converts a json representation back to an instance.

Popular methods of PubSubMessage

  • <init>
    Constructor for a message having content, Metadata and a sequence number.
  • asJSON
  • getId
  • getMetadata
  • getSequence
  • getContent
  • hasMetadata
    Check if message has Metadata.
  • hasSignal
    Check if message has a given Signal.
  • setMetadata

Popular in Java

  • Updating database using SQL prepared statement
  • notifyDataSetChanged (ArrayAdapter)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • getSharedPreferences (Context)
  • BufferedInputStream (java.io)
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • URI (java.net)
    Represents a Uniform Resource Identifier (URI) reference. Aside from some minor deviations noted bel
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • HashSet (java.util)
    This class implements the Set interface, backed by a hash table (actually a HashMap instance). It m
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now