Skip to content

Instantly share code, notes, and snippets.

@danveloper
Created March 20, 2013 21:23
Show Gist options
  • Save danveloper/5208594 to your computer and use it in GitHub Desktop.
Save danveloper/5208594 to your computer and use it in GitHub Desktop.
Registering new atmosphere mapping -- Real Time Logging Project
// Registering an application's logging instance either means creating a new mapping for it.
// If a mapping already exists, update its "latest update time" property.
private def registerApplicationInstance(String ipAddress, String hostname, String appName) {
if (!applications[appName]) {
applications[appName] = []
}
def existing = findApplicationObject(appName, ipAddress, hostname)
if (!existing) {
// Register the new application and create a unique mapping for it.
applications[appName] << [ipAddress: ipAddress, hostname: hostname, lastUpdateTime: new LocalDateTime()]
addAtmosphereHandler("$MAPPING_URI/logchannel/${appName}/${ipAddress}/${hostname}")
// Broadcast to the default channel, letting the UI know that we have new loggers
broadcaster["$MAPPING_URI/all"].broadcast( (applications as JSON).toString(true) )
} else {
existing.lastUpdateTime = new LocalDateTime()
}
}
private void addAtmosphereHandler(String mapping) {
// Extract the stratosphere servlet from the servlet context
StratosphereServlet stratosphereServlet = grailsApplication.mainContext.servletContext[com.odelia.grails.plugins.atmosphere.StratosphereServlet.ATMOSPHERE_PLUGIN_ATMOSPHERE_SERVLET]
// Register the new mapping with the stratosphere servlet, this will let the UI have a unique endpoint for each specific application logging instance
def atmosphereHandler = new GrailsHandler(targetService: this, servletContext: grailsApplication.mainContext.servletContext)
stratosphereServlet.addAtmosphereHandler(mapping, atmosphereHandler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment