private void storeSubscription (TariffSubscription subscription, CustomerInfo customer, Tariff tariff) { if (tariffMap.get(tariff) == null) tariffMap.put(tariff, new ArrayList<TariffSubscription>()); tariffMap.get(tariff).add(subscription); if (customerMap.get(customer) == null) customerMap.put(customer, new ArrayList<TariffSubscription>()); customerMap.get(customer).add(subscription); Broker broker = tariff.getBroker(); if (brokerMap.get(broker) == null) brokerMap.put(broker, new ArrayList<TariffSubscription>()); brokerMap.get(broker).add(subscription); } }
/** * Removes all subscriptions for the given tariff. Presumably this is done * when the tariff has been revoked and all revocation processing is complete. */ public void removeSubscriptionsForTariff (Tariff tariff) { List<TariffSubscription> subs = tariffMap.get(tariff); if (null == subs) return; // first, remove the subscriptions from the customer map and broker map for (TariffSubscription sub : subs) { customerMap.get(sub.getCustomer()).remove(sub); } for (TariffSubscription sub : subs) { brokerMap.get(sub.getTariff().getBroker()).remove(sub); } // then clear out the tariff entry tariffMap.remove(tariff); }
@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; }
@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; }
log.info("Revoke tariff " + tariff.getId()); TariffRevoke msg = new TariffRevoke(tariff.getBroker(), tariff.getTariffSpecification()); brokerProxyService.broadcastMessage(msg);
timeslotRepo.currentTimeslot().getSerialNumber()); accountingService.postBalancingControl(bce); brokerProxy.sendMessage(tariff.getBroker(), bce);
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)); }