@Override public String toString () { return ("CI(" + broker.getUsername() + "): p1=" + balanceChargeP1 + ", p2=" + balanceChargeP2); } }
public String getBrokerName () { return broker.getUsername(); }
/** * Get a prefix based on the list of brokers * Default broker (not in the list) must have prefix == 1 */ private int getBrokerPrefix (Broker broker) { int posn = brokerNames.indexOf(broker.getUsername()); if (-1 == posn) log.error("Broker {} not found in brokerNames", broker.getUsername()); return posn + 1; }
@Override public void handleNewObject (Object thing) { Broker broker = (Broker)thing; log.info("add broker " + broker.getUsername()); brokerRepo.add(broker); } }
/** * Returns the net balancing result for a given broker. Valid only after * service activation within a given timeslot. */ @Override public double getRegulation (Broker broker) { ChargeInfo ci = balancingResults.get(broker); if (null == ci) { log.error("Null balancing result for broker " + broker.getUsername()); return 0.0; } return ci.getCurtailment(); }
/** * Allows a broker to request a pause. It may or may not be allowed. * If allowed, then the pause will take effect when the current simulation * cycle has finished, or immediately if no simulation cycle is currently * in progress. */ public synchronized void handleMessage (PauseRequest msg) { if (!brokerPauseAllowed) { log.info("Pause request by " + msg.getBroker().getUsername() + " disallowed"); return; } if (pauseRequester != null) { log.info("Pause request by " + msg.getBroker().getUsername() + " rejected; already paused by " + pauseRequester); return; } pauseRequester = msg.getBroker().getUsername(); log.info("Pause request by " + msg.getBroker().getUsername()); clock.requestPause(); }
/** * Releases a broker-initiated pause. After the clock is re-started, the * resume() method will be called to communicate a new start time. */ public synchronized void handleMessage (PauseRelease msg) { if (pauseRequester == null) { log.info("Release request by " + msg.getBroker().getUsername() + ", but no pause currently requested"); return; } if (pauseRequester != msg.getBroker().getUsername()) { log.info("Release request by " + msg.getBroker().getUsername() + ", but pause request was by " + pauseRequester); return; } log.info("Pause released by " + msg.getBroker().getUsername()); clock.releasePause(); pauseRequester = null; }
@Override public String toString () { if (null == balancingOrder) return "Dummy"; else return (balancingOrder.getBroker().getUsername() + ":" + balancingOrder.getTariffId() + ":" + price + ":" + availableCapacity + ":" + exercisedCapacity); } }
/** * Returns the difference between a broker's current market position and its * net load. Note: market position is computed in MWh and net load is computed * in kWh, conversion is needed to compute the difference in kWh. * * @return a broker's current energy balance within its market. Pos for * over-production, neg for under-production */ @Override public double getMarketBalance (Broker broker) { double result = accountingService.getCurrentMarketPosition(broker) * 1000.0 + accountingService.getCurrentNetLoad(broker); log.info("market balance for " + broker.getUsername() + ": " + result); return result; }
/** * Returns the net load for the given broker in the current timeslot. * Note that this only works AFTER the customer models have run, and * BEFORE the day's transactions have been processed. The value will be * negative if the broker's customers are consuming more than they produce * in the current timeslot. */ @Override public synchronized double getCurrentNetLoad (Broker broker) { double netLoad = 0.0; for (BrokerTransaction btx : pendingTransactions) { if (btx instanceof TariffTransaction) { TariffTransaction ttx = (TariffTransaction)btx; if (ttx.getBroker().getUsername().equals(broker.getUsername())) { if (ttx.getTxType() == TariffTransaction.Type.CONSUME || ttx.getTxType() == TariffTransaction.Type.PRODUCE) { netLoad += ttx.getKWh(); } } } } log.info("net load for " + broker.getUsername() + ": " + netLoad); return netLoad; }
private void detectAndKillHangingQueues() { Set<String> badQueues = jmsManagementService.processQueues(); if (badQueues != null && badQueues.size() > 0) { for (Broker broker : brokerRepo.list()) { if (badQueues.contains(broker.toQueueName())) { // disable broker and revoke all its tariffs log.warn("Disabling unresponsive broker " + broker.getUsername()); broker.setEnabled(false); } } if (badQueues.contains(visualizerProxyService.getVisualizerQueueName())) { visualizerProxyService.setRemoteVisualizer(false); } } }
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); }
final String text = converter.toXML(messageObject); log.debug("send " + messageObject.toString() + " to " + broker.getUsername()); log.debug("sending text: \n" + text); final String queueName = broker.toQueueName();
/** * Gets the net market position for the current timeslot. This only works on * processed transactions, but it can be used before activation in case there * can be no new market transactions for the current timeslot. This is the * normal case. The value will be positive if the broker is importing power * during the current timeslot. */ @Override public synchronized double getCurrentMarketPosition(Broker broker) { Timeslot current = timeslotRepo.currentTimeslot(); log.debug("current timeslot: " + current.getSerialNumber()); MarketPosition position = broker.findMarketPositionByTimeslot(current.getSerialNumber()); if (position == null) { log.debug("null position for ts " + current.getSerialNumber()); return 0.0; } log.info("market position for " + broker.getUsername() + ": " + position.getOverallBalance()); return position.getOverallBalance(); }
public boolean validateOrder (Order order) { if (order.getMWh().equals(Double.NaN) || order.getMWh().equals(Double.POSITIVE_INFINITY) || order.getMWh().equals(Double.NEGATIVE_INFINITY)) { log.warn("Order from " + order.getBroker().getUsername() + " with invalid quantity " + order.getMWh()); return false; } double minQuantity = Competition.currentCompetition().getMinimumOrderQuantity(); if (Math.abs(order.getMWh()) < minQuantity) { log.warn("Order from " + order.getBroker().getUsername() + " with quantity " + order.getMWh() + " < minimum quantity " + minQuantity); return false; } if (!timeslotRepo.isTimeslotEnabled(order.getTimeslot())) { OrderStatus status = new OrderStatus(order.getBroker(), order.getId()); brokerProxyService.sendMessage(order.getBroker(), status); log.warn("Order from " + order.getBroker().getUsername() +" for disabled timeslot " + order.getTimeslot()); return false; } return true; }
@Override public synchronized void postBalancingControl (BalancingControlEvent bce) { log.info("post balancing control for {}, payment={}, tariff={}, ts={}", bce.getBroker().getUsername(), bce.getPayment(), bce.getTariffId(), bce.getTimeslotIndex()); updateCash(bce.getBroker(), bce.getPayment()); }
private void constrainMarketPositions (List<OrderWrapper> bids, int ts) { HashMap<Broker, Double>remainingPosn = new HashMap<>(); for (OrderWrapper bid: bids) { if (bid.getBroker().isWholesale()) // Don't limit wholesale entities continue; double remaining = getRemaining(bid.getBroker(), remainingPosn, ts); remaining -= bid.getMWh(); if (remaining < 0.0) { // adjust bid double qty = bid.getMWh() + remaining; remaining = 0.0; log.info("Adjusting bid of {} from {} to {}", bid.getBroker().getUsername(), bid.getMWh(), qty); bid.setMWh(qty); } remainingPosn.put(bid.getBroker(), remaining); } }
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)); }
private void updateBrokerMarketPosition(MarketTransaction tx) { Broker broker = tx.getBroker(); MarketPosition mkt = broker.findMarketPositionByTimeslot(tx.getTimeslotIndex()); if (mkt == null) { mkt = new MarketPosition(broker, tx.getTimeslot(), tx.getMWh()); log.debug("New MarketPosition(" + broker.getUsername() + ", " + tx.getTimeslot().getSerialNumber() + "): " + mkt.getId()); broker.addMarketPosition(mkt, tx.getTimeslotIndex()); } else { mkt.updateBalance(tx.getMWh()); } }