public synchronized void checkTooLateToCancel(String orderId) throws Exception {
    String message = "Too Late to Cancel";
    boolean containsOrder = false;

    for (Price p : oldEntries.keySet()) {
      for (Tradable t : oldEntries.get(p)) {
        if (t.getId().equals(orderId)) {
          CancelMessage cm =
              new CancelMessage(
                  t.getUser(),
                  t.getProduct(),
                  t.getPrice(),
                  t.getRemainingVolume(),
                  message,
                  t.getSide(),
                  t.getId());

          MessagePublisher.getInstance().publishCancel(cm);
          containsOrder = true;
        }
      }
    }

    if (containsOrder == false) throw new OrderNotFoundException("Order cannot be found.");
  }
  private synchronized void addToBook(BookSide side, Tradable trd) throws Exception {
    if (ProductService.getInstance().getMarketState().equals(MarketState.PREOPEN)) {
      switch (side) {
        case BUY:
          buySide.addToBook(trd);
          break;
        case SELL:
          sellSide.addToBook(trd);
          break;
      }
    } else {
      HashMap<String, FillMessage> allFills = null;

      switch (side) {
        case BUY:
          allFills = sellSide.tryTrade(trd);
          break;
        case SELL:
          allFills = buySide.tryTrade(trd);
          break;
      }

      if (allFills != null && !allFills.isEmpty()) {
        this.updateCurrentMarket();
        int difference = trd.getOriginalVolume() - trd.getRemainingVolume();
        Price lastSalePrice = this.determineLastSalePrice(allFills);
        LastSalePublisher.getInstance()
            .publishLastSale(this.productSymbol, lastSalePrice, difference);
      }

      if (trd.getRemainingVolume() > 0) {
        if (trd.getPrice().isMarket()) {
          CancelMessage cm =
              new CancelMessage(
                  trd.getUser(),
                  trd.getProduct(),
                  trd.getPrice(),
                  trd.getRemainingVolume(),
                  "Cancelled",
                  trd.getSide(),
                  trd.getId());

          MessagePublisher.getInstance().publishCancel(cm);
        } else {
          switch (side) {
            case BUY:
              buySide.addToBook(trd);
              break;
            case SELL:
              sellSide.addToBook(trd);
              break;
          }
        }
      }
    }
  }