tac team mailing list archive
-
tac team
-
Mailing list archive
-
Message #00036
[Merge] lp:~danielschnurr/tacenergy/oneQueuePerUser into lp:tacenergy
Daniel Schnurr has proposed merging lp:~danielschnurr/tacenergy/oneQueuePerUser into lp:tacenergy.
Requested reviews:
TAC (tac)
Refactored TopicManagementService using one Queue instead of multiple topics.
--
https://code.launchpad.net/~danielschnurr/tacenergy/oneQueuePerUser/+merge/25052
Your team TAC is requested to review the proposed merge of lp:~danielschnurr/tacenergy/oneQueuePerUser into lp:tacenergy.
=== modified file 'grails-app/domain/edu/kit/iism/cdamarket/Competition.groovy'
--- grails-app/domain/edu/kit/iism/cdamarket/Competition.groovy 2010-05-02 14:36:56 +0000
+++ grails-app/domain/edu/kit/iism/cdamarket/Competition.groovy 2010-05-11 10:54:30 +0000
@@ -41,6 +41,7 @@
Date lastUpdated = new Date()
BigDecimal balancingCostOver = 0
BigDecimal balancingCostUnder = 0
+ String queueNames
static constraints = {
name(unique: true, blank: false)
@@ -65,6 +66,7 @@
lastUpdated(nullable: false)
balancingCostOver(nullable: false, scale: 2)
balancingCostUnder(nullable: false, scale: 2)
+ queueNames(nullable: true)
}
public String toString() {
=== modified file 'grails-app/services/edu/kit/iism/cdamarket/CompetitionControlService.groovy'
--- grails-app/services/edu/kit/iism/cdamarket/CompetitionControlService.groovy 2010-05-06 15:33:28 +0000
+++ grails-app/services/edu/kit/iism/cdamarket/CompetitionControlService.groovy 2010-05-11 10:54:30 +0000
@@ -45,6 +45,7 @@
competition.save(flush: true)
productManagementService.initProducts(competition) //initialize products (Timeslots) for this competition
createParticipants(competition)
+ setQueueNames(competition)
forecastGenerationService.initForecasts(competition)
jmsBrokerManagementService.initTopicsAndQueues()
return competition
@@ -163,6 +164,19 @@
}
}
+ private void setQueueNames(Competition competition) throws CompetitionNotFoundException {
+ if (!competition) throw new CompetitionNotFoundException("Cannot set queue names for competition ${competition}")
+ def users = Person.findAllByCompetition(competition)
+ String queueNames = ""
+ users.each { person ->
+ person.username
+ queueNames = queueNames + "users.${person.username}.outputQueue,"
+ }
+ competition.queueNames = queueNames
+ competition.save()
+ log.debug "Generated String containing all queueNames: ${competition.queueNames} and saved to domain competition"
+ }
+
private void createParticipants(Competition competition) throws PersonCreationException, CompetitionNotFoundException {
if (!competition) throw new CompetitionNotFoundException("Cannot create participants for ${competition}")
for (i in 1..competition?.participantCount) {
=== modified file 'grails-app/services/edu/kit/iism/cdamarket/JmsBrokerManagementService.groovy'
--- grails-app/services/edu/kit/iism/cdamarket/JmsBrokerManagementService.groovy 2010-05-02 14:36:56 +0000
+++ grails-app/services/edu/kit/iism/cdamarket/JmsBrokerManagementService.groovy 2010-05-11 10:54:30 +0000
@@ -84,11 +84,13 @@
def initTopicsAndQueues() throws JMSException {
try {
BrokerViewMBean mbean = getMBean()
+ /*
mbean.addQueue ('public.ClientAnnounce')
mbean.addQueue ('public.ShoutInputQueue')
mbean.addTopic ('public.CompetitionAnnounce')
mbean.addTopic ('public.TimeAnnounce')
mbean.addTopic ('public.Products')
+ */
} catch (Exception e) {
throw new JMSException("Failed to initialize topics and queues: ${e.getMessage()}, ${e.getCause()}")
}
=== modified file 'grails-app/services/edu/kit/iism/cdamarket/QueueOutputService.groovy'
--- grails-app/services/edu/kit/iism/cdamarket/QueueOutputService.groovy 2010-05-02 14:36:56 +0000
+++ grails-app/services/edu/kit/iism/cdamarket/QueueOutputService.groovy 2010-05-11 10:54:30 +0000
@@ -26,33 +26,35 @@
def sendOrderstatus(Shout shout) throws ShoutNotFoundException {
if (!shout) throw new ShoutNotFoundException ("Cannot send shout '${shout}' to jms.")
- sendToQueue("users.${shout.person.username}.Orderstatus", shout.toShoutNotificationXml())
+ sendToQueues(shout.toShoutNotificationXml())
return null
}
def sendCash(CashPosition cashPosition) throws CashPositionNotFoundException {
if (!cashPosition) throw new CashPositionNotFoundException("Cannot send cashPosition ${cashPosition} to jms.")
- sendToQueue("users.${cashPosition.person.username}.Cash", cashPosition.toCashPositionNotificationXml())
+ sendToQueues(cashPosition.toCashPositionNotificationXml())
return null
}
def sendDepot(DepotPosition depotPosition) throws DepotPositionNotFoundException {
if (!depotPosition) throw new DepotPositionNotFoundException("Cannot send depotPosition ${depotPosition} to jms.")
- sendToQueue("users.${depotPosition.person.username}.Depot", depotPosition.toDepotPositionNotificationXml())
+ sendToQueues(depotPosition.toDepotPositionNotificationXml())
return null
}
def sendForecast(Forecast forecast) throws ForecastNotFoundException {
if (!forecast) throw new ForecastNotFoundException("Cannot send forecast ${forecast} to jms.")
- sendToQueue("users.${forecast.person.username}.Forecast", forecast.toForecastNotificationXml())
+ sendToQueues(forecast.toForecastNotificationXml())
return null
}
- def sendToQueue(queueName, object) {
+
+ def sendToQueues(String xmlString) {
+ String queueNames = Competition.findByCurrent(true).queueNames
try {
- sendQueueJMSMessage(queueName, object)
+ sendQueueJMSMessage(queueNames, xmlString)
} catch (Exception e) {
- log.error("Failed to send '${object}' to queue ${queueName}. ", e)
+ log.error("Failed to send object '${object}' to topic ${topicName}.", e)
}
return null
}
=== modified file 'grails-app/services/edu/kit/iism/cdamarket/TopicManagementService.groovy'
--- grails-app/services/edu/kit/iism/cdamarket/TopicManagementService.groovy 2010-05-02 14:36:56 +0000
+++ grails-app/services/edu/kit/iism/cdamarket/TopicManagementService.groovy 2010-05-11 10:54:30 +0000
@@ -19,20 +19,21 @@
package edu.kit.iism.cdamarket
import grails.converters.*
+import org.apache.activemq.command.ActiveMQQueue
class TopicManagementService {
boolean transactional = false
- static pubSub = true
def sendCompetitionNotification(Competition competition, ActionType actionType) throws CompetitionNotFoundException {
if (!competition) throw new CompetitionNotFoundException("Cannot send system notification for competition ${competition} to jms.")
def competitionNotification = competition.toCompetitionNotification()
if (actionType) competitionNotification.action = actionType
String xmlString = competitionNotification as XML
- sendToTopic("public.CompetitionAnnounce", xmlString)
+ sendToQueues(xmlString)
log.info "Competition announcement sent: ${xmlString}"
return null
+
}
//send a product product notification of current product status ("Product opened" | "Product closed") and properties of respective product object
@@ -41,7 +42,7 @@
def productNotification = product.toProductNotification()
if (actionType) productNotification.action = actionType
String xmlString = productNotification as XML
- sendToTopic("public.Products", xmlString)
+ sendToQueues(xmlString)
log.info "Product announcement sent: ${xmlString}"
return null
}
@@ -52,7 +53,7 @@
def sendQuoteNotification(TransactionLog quote) throws QuoteNotFoundException {
if (!quote) throw new QuoteNotFoundException ("Cannot send quote ${quote} to jms.")
String xmlString = quote.toQuoteLogNotificationXml()
- sendToTopic("public.Quote", xmlString)
+ sendToQueues(xmlString)
log.info "Quote announcement sent: ${xmlString}"
return null
}
@@ -60,7 +61,7 @@
def sendTradeNotification(TransactionLog trade) throws TradeNotFoundException {
if (!trade) throw new TradeNotFoundException ("Cannot send quote ${trade} to jms.")
String xmlString = trade.toTradeLogNotificationXml()
- sendToTopic("public.Trade", xmlString)
+ sendToQueues(xmlString)
log.info "Trade announcement sent: ${xmlString}"
return null
}
@@ -68,14 +69,15 @@
def sendOrderbookNotification(Orderbook orderbook) throws OrderbookException {
if (!orderbook) throw new OrderbookException("Cannot send Orderbook ${orderbook} to jms.")
String xmlString = orderbook.toOrderbookNotificationXml()
- sendToTopic("public.Orderbook", xmlString)
+ sendToQueues(xmlString)
log.info "Ordebook announcement sent: ${xmlString}"
return null
}
- def sendToTopic(topicName, object) {
+ def sendToQueues(String xmlString) {
+ String queueNames = Competition.findByCurrent(true).queueNames
try {
- sendPubSubJMSMessage(topicName, object)
+ sendQueueJMSMessage(queueNames, xmlString)
} catch (Exception e) {
log.error("Failed to send object '${object}' to topic ${topicName}.", e)
}