@Override public void handleNewObject (Object thing) { TariffSpecification spec = (TariffSpecification)thing; // attach pending Rates ArrayList<Rate> rates = pendingRates.get(spec.getId()); if (null != rates) for (Rate rate : rates) spec.addRate(rate); tariffRepo.addSpecification(spec); } }
@Override public void handleNewObject (Object thing) { Rate rate = (Rate)thing; TariffSpecification spec = tariffRepo.findSpecificationById(rate.getTariffId()); if (null != spec) { // attach rate to spec if it's already known spec.addRate(rate); } else { // otherwise save rate for later ArrayList<Rate> rates = pendingRates.get(rate.getTariffId()); if (null == rates) { rates = new ArrayList<Rate>(); pendingRates.put(rate.getTariffId(), rates); } rates.add(rate); } } }
@Override public List<Tariff> getActiveTariffList(PowerType type) { return tariffRepo.findActiveTariffs(type); }
if (!(null == tariffRepo.findSpecificationById(spec.getId()) || tariffRepo.isRemoved(spec.getId()))) { log.warn("duplicate tariff spec from " + spec.getBroker().getUsername() + ", id = " + spec.getId()); TariffSpecification other = tariffRepo.findSpecificationById(supersede); if (null == other) { log.warn("attempt to supersede non-existent tariff " + supersede); tariffRepo.addSpecification(spec); Tariff tariff = new Tariff(spec); if (!tariff.init()) { log.warn("incomplete coverage in multi-rate tariff " + spec.getId()); tariffRepo.removeTariff(tariff); send(new TariffStatus(spec.getBroker(), spec.getId(), spec.getId(), TariffStatus.Status.invalidTariff) (spec.getPowerType().isStorage()? 2.0: 1.0), regRate.getUpRegulationPayment()); tariffRepo.addBalancingOrder(bo); new BalancingOrder(spec.getBroker(), spec, -1.0, regRate.getDownRegulationPayment()); tariffRepo.addBalancingOrder(bo);
/** * Exercises an economic control for the current timeslot. */ void exerciseEconomicControl (EconomicControlEvent event) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) { // should not happen log.error("Null tariff " + event.getTariffId() + " for economic control"); return; } List<TariffSubscription> subs = tariffSubscriptionRepo.findSubscriptionsForTariff(tariff); for (TariffSubscription sub : subs) { sub.postRatioControl(event.getCurtailmentRatio()); } }
private void revokeTariffsForDisabledBrokers () { for (Broker broker : brokerRepo.findDisabledBrokers()) { if (!disabledBrokers.contains(broker)) { // this is a new one disabledBrokers.add(broker); for (Tariff tariff : tariffRepo.findTariffsByBroker(broker)) { if (Tariff.State.KILLED != tariff.getState()) { log.info("Revoking tariff " + tariff.getId() + " from disabled broker " + broker.getUsername()); addPendingRevoke(tariff); } } } } }
/** * Publishes pending tariffs to customers and brokers */ private void publishTariffs () { List<Tariff> publishedTariffs = tariffRepo.findTariffsByState(Tariff.State.PENDING); log.info("publishing " + publishedTariffs.size() + " new tariffs"); for (Tariff tariff : publishedTariffs) { tariff.setState(Tariff.State.OFFERED); } List<TariffSpecification> publishedTariffSpecs = new ArrayList<>(); for (Tariff tariff : publishedTariffs) { TariffSpecification spec = tariff.getTariffSpecification(); publishedTariffSpecs.add(spec); log.info("publishing spec " + spec.getId() + " broker: " + spec.getBroker().getUsername() + ", exp: " + spec.getExpiration()); } for (NewTariffListener listener : registrations) { listener.publishNewTariffs(publishedTariffs); } brokerProxyService.broadcastMessages(publishedTariffSpecs); }
Collection<BalancingOrder> boc = tariffRepo.getBalancingOrders(); for (BalancingOrder order : boc) { ChargeInfo info = chargeInfoMap.get(order.getBroker());
.findRecentActiveTariffs(tariffEvalDepth, customerInfo.getPowerType()));
return; Rate rate = tariffRepo.findRateById(update.getRateId()); if (rate == null) { send(new TariffStatus(update.getBroker(),
tariffRepo.addBalancingOrder(msg);
@Override public boolean apply (TariffSubscription sub) { return (null != tariffRepo.findTariffById(sub.getTariff().getId()) && sub.getTariff().getState() == Tariff.State.KILLED && sub.getCustomersCommitted() > 0); } });
@Override public RegulationAccumulator getRegulationCapacity (BalancingOrder order) { Tariff tariff = tariffRepo.findTariffById(order.getTariffId()); if (null == tariff) { // broker error, most likely log.warn("Null tariff " + order.getTariffId() + " for balancing order"); return new RegulationAccumulator(0.0, 0.0); } RegulationAccumulator result = new RegulationAccumulator(0.0, 0.0); List<TariffSubscription> subs = tariffSubscriptionRepo.findSubscriptionsForTariff(tariff); for (TariffSubscription sub : subs) { result.add(sub.getRemainingRegulationCapacity()); } log.info("BalancingOrder " + order.getId() + " capacity = (" + result.getUpRegulationCapacity() + "," + result.getDownRegulationCapacity() + ")"); return result; }
@Override public synchronized TariffTransaction addRegulationTransaction (Tariff tariff, CustomerInfo customer, int customerCount, double kWh, double charge) { TariffTransaction.Type txType = TariffTransaction.Type.CONSUME; if (kWh > 0.0) txType = TariffTransaction.Type.PRODUCE; TariffTransaction ttx = txFactory.makeTariffTransaction(tariff.getBroker(), txType, tariffRepo.findSpecificationById(tariff.getSpecId()), customer, customerCount, kWh, charge, true); if (null == ttx.getTariffSpec()) log.error("Null tariff spec in addTariffTx()"); pendingTransactions.add(ttx); return ttx; }
Tariff tariff = tariffRepo.findTariffById(order.getTariffId()); if (null == tariff) {
@Override public synchronized TariffTransaction addTariffTransaction(TariffTransaction.Type txType, Tariff tariff, CustomerInfo customer, int customerCount, double kWh, double charge) { TariffTransaction ttx = txFactory.makeTariffTransaction(tariff.getBroker(), txType, tariffRepo.findSpecificationById(tariff.getSpecId()), customer, customerCount, kWh, charge); if (null == ttx.getTariffSpec()) log.error("Null tariff spec in addTariffTx()"); pendingTransactions.add(ttx); return ttx; }
if (null != controls) { for (EconomicControlEvent event : controls) { Tariff tariff = tariffRepo.findTariffById(event.getTariffId()); if (null == tariff) {
/** * Handles pending vru messages */ private void processPendingVrus () { for (VariableRateUpdate vru: getVruList()) { Tariff tariff = tariffRepo.findTariffById(vru.getTariffId()); if (tariff.addHourlyCharge(vru.getHourlyCharge(), vru.getRateId())) { success(vru); } else { // failed to add hourly charge send(new TariffStatus(vru.getBroker(), vru.getTariffId(), vru.getId(), TariffStatus.Status.invalidUpdate) .withMessage("update: could not add hourly charge")); } } }
private ValidationResult validateUpdate (TariffUpdate update) { Broker broker = update.getBroker(); Tariff tariff = tariffRepo.findTariffById(update.getTariffId()); if (tariff == null) { log.error("update - no such tariff " + update.getTariffId() + ", broker " + update.getBroker().getUsername()); return new ValidationResult(null, new TariffStatus(broker, update.getTariffId(), update.getId(), TariffStatus.Status.noSuchTariff)); } if (broker != tariff.getBroker()) { log.error("update - attempt by " + broker.getUsername() + " to revoke " + tariff.getBroker() + "'s tariff"); return new ValidationResult(null, new TariffStatus(broker, update.getTariffId(), update.getId(), TariffStatus.Status.invalidTariff)); } return new ValidationResult(tariff, new TariffStatus(broker, update.getTariffId(), update.getId(), TariffStatus.Status.success)); }