Amazon Kinesis Data Streams
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

第 6 步:(可选) 扩展使用者

此处显示的应用程序可能已足以达到您的目的。本可选部分将演示您可能希望如何针对更为复杂的场景扩展使用者代码。

若要了解每分钟的最大销售订单数,您需要对 StockStats 类进行三处修改以适应此新的优先级。

扩展使用者

  1. 添加新实例变量:

    // Ticker symbol of the stock that had the largest quantity of shares sold private String largestSellOrderStock; // Quantity of shares for the largest sell order trade private long largestSellOrderQuantity;
  2. 将以下代码添加到 addStockTrade

    if (type == TradeType.SELL) { if (largestSellOrderStock == null || trade.getQuantity() > largestSellOrderQuantity) { largestSellOrderStock = trade.getTickerSymbol(); largestSellOrderQuantity = trade.getQuantity(); } }
  3. 修改 toString 方法以打印其他信息:

    public String toString() { return String.format( "Most popular stock being bought: %s, %d buys.%n" + "Most popular stock being sold: %s, %d sells.%n" + "Largest sell order: %d shares of %s.", getMostPopularStock(TradeType.BUY), getMostPopularStockCount(TradeType.BUY), getMostPopularStock(TradeType.SELL), getMostPopularStockCount(TradeType.SELL), largestSellOrderQuantity, largestSellOrderStock); }

如果您现在运行使用者(请记住同时运行创建器),则应看到类似于以下内容的输出:

****** Shard shardId-000000000001 stats for last 1 minute ****** Most popular stock being bought: WMT, 27 buys. Most popular stock being sold: PTR, 14 sells. Largest sell order: 996 shares of BUD. ****************************************************************