/** * Signals that the clock is paused due to server overrun. The pause * must be communicated to brokers. */ public void pause () { log.info("pause"); // create and post the pause message SimPause msg = new SimPause(); brokerProxyService.broadcastMessage(msg); }
@Override public String initialize (Competition competition, List<String> completedInits) { incoming.clear(); serverProps.configureMe(this); brokerProxyService.registerBrokerMessageListener(this, Order.class); super.init(); serverProps.publishConfiguration(this); return "Auctioneer"; }
void onMessage (String xml) { // validate broker's key, then strip it off String validXml = xml; if (xml.startsWith("<broker-authentication")) { // don't validate the broker-authentication messages validXml = xml; } else if (xml.startsWith("<visualizer-status")) { // visualizer ping request log.info("received visualizer ping request"); visualizerProxy.respondToPing(); return; } else { // complain if message spoofed or missing validation prefix validXml = validateBrokerPrefix(xml); if (null == validXml) { log.warn("Invalid message: ignoring " + xml); return; } } log.debug("onMessage(String) - received message:\n" + validXml); Object message = converter.fromXML(validXml); log.debug("onMessage(String) - received message of type " + message.getClass().getSimpleName()); brokerProxy.routeMessage(message); }
brokerProxyService.setDeferredBroadcast(true); if (!configurePlugins()) { log.error("failed to configure plugins"); brokerProxyService.setDeferredBroadcast(false); brokerProxyService.broadcastMessage(competition); Properties published = configService.getPublishedConfiguration(); brokerProxyService.broadcastMessage(published); if (!bootstrapMode) { log.info("Published configuration: {}", published.toString()); List<Object> bootstrapDataset = bootstrapDataRepo.getData(); brokerProxyService.broadcastMessages(bootstrapDataset); brokerProxyService.broadcastDeferredMessages(); brokerProxyService.broadcastMessage(makeTimeslotUpdate()); return true;
broker.getCashBalance()); log.info("Sending " + brokerMsg.get(broker).size() + " messages to " + broker.getUsername()); brokerProxyService.sendMessages(broker, brokerMsg.get(broker)); new DistributionReport(timeslotRepo.currentSerialNumber(), totalConsumption, totalProduction); brokerProxyService.broadcastMessage(distributionReport);
private void send (TariffMessage msg) { if (null == msg) { log.debug("null outgoing message"); } else { brokerProxyService.sendMessage(msg.getBroker(), msg); } }
/** * 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); }
log.info("Broker " + broker.getUsername() + " key: " + broker.getKey() + ", prefix: " + prefix); brokerProxyService.sendMessage(broker, new BrokerAccept(prefix, broker.getKey()));
/** * Signals that the clock is resumed. Brokers must be informed of the new * start time in order to sync their own clocks. */ public void resume (long newStart) { log.info("resume"); // create and post the resume message SimResume msg = new SimResume(new Instant(newStart)); brokerProxyService.broadcastMessage(msg); }
/** * Generates buy orders. Price is distributed exponentially with a mean value * of priceBeta. Quantity is mwh/price. */ @Override public void generateOrders (Instant now, List<Timeslot> openSlots) { log.info("generate orders for " + getUsername()); for (Timeslot slot : openSlots) { int slotNum = slot.getSerialNumber(); double price = - priceBeta * Math.log(1.0 - seed.nextDouble()); double qty = mwh / price; if (Math.abs(qty) < Competition.currentCompetition() .getMinimumOrderQuantity()) return; Order offer = new Order(this, slotNum, qty, -price); log.debug(getUsername() + " wants " + qty + " in " + slotNum + " for " + price); brokerProxyService.routeMessage(offer); } }
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; }
/** * Initializes the service in preparation for a new simulation */ public void init () { phaseRegistrations = null; // register with JMS Server if (!bootstrapMode) { jmsManagementService.initializeServerQueue(serverQueueName); jmsManagementService.registerMessageListener(serverQueueName, serverMessageReceiver); } // broker message registration for clock-control messages //brokerProxyService.registerSimListener(this); for (Class<?> messageType: Arrays.asList(BrokerAuthentication.class, PauseRequest.class, PauseRelease.class)) { brokerProxyService.registerBrokerMessageListener(this, messageType); } }
private void broadcastWeatherReports () { WeatherReport report = null; try { report = weatherReportRepo.currentWeatherReport(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Report Repo empty"); } if (report == null) { // In the event of an error return a default log.error("null weather-report for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); brokerProxyService.broadcastMessage(new WeatherReport(timeslotRepo.currentSerialNumber(), 0.0, 0.0, 0.0, 0.0)); } else { brokerProxyService.broadcastMessage(report); } }
private void submitOrder (double neededKWh, Timeslot timeslot) { double neededMWh = neededKWh / 1000.0; if (Math.abs(neededMWh) < competition.getMinimumOrderQuantity()) { // don't bother return; } Double limitPrice; MarketPosition posn = face.findMarketPositionByTimeslot(timeslot.getSerialNumber()); if (posn != null) neededMWh -= posn.getOverallBalance(); log.debug("needed mWh=" + neededMWh); if (Math.abs(neededMWh) < minMWh) { log.info("no power required in timeslot " + timeslot.getSerialNumber()); return; } else { limitPrice = computeLimitPrice(timeslot, neededMWh); } log.info("new order for " + neededMWh + " at " + limitPrice + " in timeslot " + timeslot.getSerialNumber()); Order result = new Order(face, timeslot.getSerialNumber(), neededMWh, limitPrice); lastOrder.put(timeslot, result); brokerProxyService.routeMessage(result); }
timeslotRepo.currentTimeslot().getSerialNumber()); accountingService.postBalancingControl(bce); brokerProxy.sendMessage(tariff.getBroker(), bce);
EconomicControlEvent.class, BalancingOrder.class)) { brokerProxyService.registerBrokerMessageListener(this, messageType);
private void broadcastWeatherForecasts () { WeatherForecast forecast = null; try { forecast = weatherForecastRepo.currentWeatherForecast(); } catch (PowerTacException e) { log.error("Weather Service reports Weather Forecast Repo emtpy"); } if (forecast == null) { log.error("null weather-forecast for : " + timeslotRepo.currentSerialNumber() +" " + timeslotRepo.currentTimeslot()); // In the event of an error return a default List<WeatherForecastPrediction> currentPredictions = new ArrayList<WeatherForecastPrediction>(); for (int j = 1; j <= getForecastHorizon(); j++) { currentPredictions.add( new WeatherForecastPrediction(j, 0.0, 0.0, 0.0, 0.0)); } brokerProxyService.broadcastMessage(new WeatherForecast( timeslotRepo.currentSerialNumber(), currentPredictions)); } else { brokerProxyService.broadcastMessage(forecast); } }
/** * Generates Orders in the market to sell remaining available capacity. */ public void generateOrders (Instant now, List<Timeslot> openSlots) { log.info("Generate orders for " + getUsername()); double[] tempCorrections = computeWeatherCorrections(); int i = 0; for (Timeslot slot: openSlots) { int index = slot.getSerialNumber(); MarketPosition posn = findMarketPositionByTimeslot(index); double start = 0.0; double demand = computeScaledValue(index, tempCorrections[i++]); if (posn != null) { // posn.overallBalance is negative if we have sold power in this slot start = posn.getOverallBalance(); } double needed = demand - start; Order offer = new Order(this, index, needed, null); log.info(getUsername() + " orders " + needed + " ts " + index); brokerProxyService.routeMessage(offer); } }
brokerProxyService.broadcastMessage(msg); Date ended = new Date(); long elapsed = ended.getTime() - started.getTime();
log.debug("new order (ts, qty, price): (" + slot.getSerialNumber() + ", " + (-dx) + ", " + price + ")"); brokerProxyService.routeMessage(offer); start += dx;