Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 799258f

Browse files
committed
Finished first version of the REST API.
1 parent 16f7259 commit 799258f

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/main/scala/org/codeoverflow/chatoverflow/Launcher.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,21 @@ object Launcher extends WithLogger {
6464

6565
private def startServer(chatOverflow: ChatOverflow, port: Int): Unit = {
6666
if (server.isEmpty) {
67-
server = Some(new Server(chatOverflow, 2400))
67+
server = Some(new Server(chatOverflow, port))
6868
server.get.startAsync()
6969
}
7070
}
7171

7272
private def startREPL(chatOverflow: ChatOverflow): Unit = {
7373
new REPL(chatOverflow).run()
7474
}
75+
76+
/**
77+
* Shuts down the framework.
78+
*/
79+
def exit(): Unit = {
80+
logger info "Shutting down Chat Overflow."
81+
// TODO: Deal with running plugins, connectors, ...
82+
System.exit(0)
83+
}
7584
}

src/main/scala/org/codeoverflow/chatoverflow/instance/PluginInstance.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class PluginInstance(val instanceName: String, pluginType: PluginType) extends W
174174
// After the loop (or setup) the plugin should end
175175
plugin.get.shutdown()
176176

177+
logger info s"Stopped plugin instance '$instanceName'."
178+
177179
} catch {
178180
case e: AbstractMethodError => logger.error(s"Plugin '$instanceName' just crashed. Looks like a plugin version error.", e)
179181
case e: Exception => logger.error(s"Plugin '$instanceName' just had an exception. Might be a plugin implementation fault.", e)
@@ -225,6 +227,7 @@ class PluginInstance(val instanceName: String, pluginType: PluginType) extends W
225227
* Tells the plugin to stop its execution after the next iteration of the loop()-method and its sleeping-cycle.
226228
*/
227229
def stopPlease(): Unit = {
230+
logger info s"Requested stop of plugin instance '$instanceName'."
228231
threadStopAfterNextIteration = true
229232
}
230233

src/main/scala/org/codeoverflow/chatoverflow/ui/web/Server.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.codeoverflow.chatoverflow.ui.web
22

3-
import org.codeoverflow.chatoverflow.ChatOverflow
3+
import java.awt.Desktop
4+
import java.net.URL
5+
6+
import org.codeoverflow.chatoverflow.{ChatOverflow, WithLogger}
47
import org.eclipse.jetty.servlet.ServletHandler.Default404Servlet
58
import org.eclipse.jetty.webapp.WebAppContext
69
import org.scalatra.servlet.ScalatraListener
@@ -11,7 +14,7 @@ import org.scalatra.servlet.ScalatraListener
1114
* @param port the port to run on the localhost
1215
* @param chatOverflow the main chat overflow object
1316
*/
14-
class Server(val chatOverflow: ChatOverflow, val port: Int) {
17+
class Server(val chatOverflow: ChatOverflow, val port: Int) extends WithLogger {
1518

1619
private val server = new org.eclipse.jetty.server.Server(port)
1720
private val context = new WebAppContext()
@@ -29,6 +32,14 @@ class Server(val chatOverflow: ChatOverflow, val port: Int) {
2932
def startAsync(): Unit = {
3033
// TODO: Enable shutting down the server
3134
new Thread(() => startServer()).start()
35+
36+
// TODO: Replace this with the proper GUI, when available
37+
try {
38+
val petstoreURL = s"http://petstore.swagger.io/?url=http://localhost:$port/api-docs/swagger.json"
39+
Desktop.getDesktop.browse(new URL(petstoreURL).toURI)
40+
} catch {
41+
case _: Exception => logger debug "Unable to open GUI in browser."
42+
}
3243
}
3344

3445
private def startServer(): Unit = {

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/config/ConfigController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ConfigController(implicit val swagger: Swagger) extends JsonServlet with C
3535
// Give enough time to return success. Then bye bye
3636
new Thread(() => {
3737
Thread.sleep(500)
38-
System.exit(0)
38+
Launcher.exit()
3939
}).start()
4040
ResultMessage(success = true)
4141
}

0 commit comments

Comments
 (0)