/** * Method to create a PubSubException when a required argument could not be read. * * @param name The name of the argument that could not be read. * @param cause The optional {@link Throwable} that caused the exception. * @return A PubSubException indicating failure to read a required argument. */ public static PubSubException forArgument(String name, Throwable cause) { String message = "Could not read required argument: " + name; return cause == null ? new PubSubException(message) : new PubSubException(message, cause); } }
/** * Create a PubSub instance using the class specified in the config file. * * @param config The non-null {@link BulletConfig} containing the class name and PubSub settings. * @return an instance of specified class initialized with settings from the input file and defaults. * @throws PubSubException if PubSub creation fails. */ public static PubSub from(BulletConfig config) throws PubSubException { try { return config.loadConfiguredClass(BulletConfig.PUBSUB_CLASS_NAME); } catch (RuntimeException e) { throw new PubSubException("Cannot create PubSub instance.", e.getCause()); } }
@Override public void send(PubSubMessage message) throws PubSubException { if (closed) { throw new PubSubException(""); } sent.add(message); }
@Override public PubSubMessage receive() throws PubSubException { if (queue.isEmpty()) { throw new PubSubException(""); } PubSubMessage message = queue.remove(); received.add(message); return message; }
@Override public void send(PubSubMessage message) throws PubSubException { Metadata metadata = message.getMetadata(); // Remove the content String content = metadata.getContent().toString(); log.debug("Removing metadata {} for result {}@{}: {}", content, message.getId(), message.getSequence(), message.getContent()); metadata.setContent(null); String serializedMessage = message.asJSON(); Tuple tuple = new DRPCTuple(new Values(serializedMessage, content)); // This sends the message through DRPC and not to the collector but it acks or fails accordingly. bolt.execute(tuple); if (!collector.isAcked()) { throw new PubSubException("Message not acked. Unable to send message through DRPC:\n " + serializedMessage); } // Otherwise, we're good to proceed collector.reset(); }
@Override public void send(PubSubMessage message) throws PubSubException { Metadata metadata = message.getMetadata(); // Remove the content String content = metadata.getContent().toString(); log.debug("Removing metadata {} for result {}@{}: {}", content, message.getId(), message.getSequence(), message.getContent()); metadata.setContent(null); String serializedMessage = message.asJSON(); Tuple tuple = new DRPCTuple(new Values(serializedMessage, content)); // This sends the message through DRPC and not to the collector but it acks or fails accordingly. bolt.execute(tuple); if (!collector.isAcked()) { throw new PubSubException("Message not acked. Unable to send message through DRPC:\n " + serializedMessage); } // Otherwise, we're good to proceed collector.reset(); }