Skip to content

Commit

Permalink
Kill ApplicationLoader and Application's subclassing. All customizati…
Browse files Browse the repository at this point in the history
…on is to be done via ApplicationContextMonitor's
  • Loading branch information
shafirov committed Oct 1, 2014
1 parent 750cc3a commit 807d9d4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 64 deletions.
8 changes: 1 addition & 7 deletions src/KaraExec/src/kara/server/JettyRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ public class JettyRunner(val applicationConfig: ApplicationConfig) {
var server: Server? = null
val resourceHandlers = ArrayList<ResourceHandler>()

val application: Application;
{
val logger = Logger.getLogger(this.javaClass)!!
val applicationLoader = ApplicationLoader(applicationConfig)
applicationLoader.loaded { logger.info("Application ${it.javaClass} loaded into the jetty runner") }
application = applicationLoader.load()
}
val application: Application = Application.load(applicationConfig)

inner class Handler() : AbstractHandler() {
public override fun handle(target: String?, baseRequest: Request?, request: HttpServletRequest?, response: HttpServletResponse?) {
Expand Down
35 changes: 22 additions & 13 deletions src/KaraLib/src/kara/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.nio.file.attribute.BasicFileAttributes

/** The base Kara application class.
*/
abstract class Application(public val config: ApplicationConfig, private vararg val routes: Any) {
open class Application(public val config: ApplicationConfig) {
private var _context: ApplicationContext? = null
private val watchKeys = ArrayList<WatchKey>()
private val contextLock = Object()
Expand Down Expand Up @@ -56,21 +56,15 @@ abstract class Application(public val config: ApplicationConfig, private vararg
context!!
}

public fun requestClassloader(current: ClassLoader): ClassLoader =
if (config.isDevelopment()) {
URLClassLoader(config.classPath, current)
} else
current
public fun requestClassloader(): ClassLoader = classLoader(config)

open fun createContext(): ApplicationContext {
val classLoader = requestClassloader(javaClass.getClassLoader()!!)
val resourceTypes = if (routes.size != 0) {
scanObjects(routes, classLoader)
} else {
config.routePackages.flatMap { scanPackageForResources(it, classLoader) }
}
val classLoader = requestClassloader()
val resourceTypes = config.routePackages.flatMap { scanPackageForResources(it, classLoader) }

if (config.isDevelopment())
watchUrls(resourceTypes)

return ApplicationContext(this, config.routePackages, classLoader, resourceTypes)
}

Expand Down Expand Up @@ -129,6 +123,21 @@ abstract class Application(public val config: ApplicationConfig, private vararg
}

class object {
val logger = Logger.getLogger(this.javaClass)!!
val logger = Logger.getLogger(javaClass)!!

fun classLoader(config: ApplicationConfig): ClassLoader {
val rootClassloader = javaClass.getClassLoader()!!
val classPath = config.classPath
return when {
classPath.isEmpty() -> rootClassloader
else -> URLClassLoader(classPath, rootClassloader)
}
}

public fun load(config: ApplicationConfig): Application {
val application = Application(config)
application.start()
return application
}
}
}
3 changes: 0 additions & 3 deletions src/KaraLib/src/kara/ApplicationConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public open class ApplicationConfig() : Config() {
public val applicationPackageName: String
get() = this["kara.appPackage"]

public val applicationClassName: String
get() = tryGet("kara.appClass") ?: "$applicationPackageName.Application"

/** Directories where publicly available files (like stylesheets, scripts, and images) will go. */
public val publicDirectories: Array<String>
get() = tryGet("kara.publicDir")?.split(';') ?: array<String>()
Expand Down
40 changes: 0 additions & 40 deletions src/KaraLib/src/kara/ApplicationLoader.kt

This file was deleted.

2 changes: 1 addition & 1 deletion src/KaraLib/src/kara/internal/Servlet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open class Servlet() : HttpServlet() {
config[name] = servletContext.getInitParameter(name)!!
}

ApplicationLoader(config).load()
Application.load(config)
}


Expand Down

0 comments on commit 807d9d4

Please sign in to comment.