public TradeUnit(final TradeConfiguration tradeConf, final PulsarClient client, final ProducerConfiguration producerConf, final ConsumerConfiguration consumerConf, final Map<Integer, byte[]> payloadCache) throws Exception { consumerFuture = client.subscribeAsync(tradeConf.topic, "Subscriber-" + tradeConf.topic, consumerConf); this.payload = new AtomicReference<>(); this.producerConf = producerConf; this.payloadCache = payloadCache; this.client = client; topic = tradeConf.topic; // Add a byte[] of the appropriate size if it is not already present // in the cache. this.payload.set(payloadCache.computeIfAbsent(tradeConf.size, byte[]::new)); rateLimiter = RateLimiter.create(tradeConf.rate); stop = new AtomicBoolean(false); }