Created
March 20, 2013 21:23
-
-
Save danveloper/5208594 to your computer and use it in GitHub Desktop.
Registering new atmosphere mapping -- Real Time Logging Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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