fix drill-01 exercise-4
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
The server executes the factorial asynchronously
This commit is contained in:
parent
d822faab60
commit
a6ae9aa30f
@ -19,6 +19,7 @@ group = "it.norangeb.unisannio"
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
|
||||
testCompile("junit", "junit", "4.12")
|
||||
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.7.0-beta2")
|
||||
}
|
||||
|
@ -20,4 +20,7 @@ val clientHandler = {
|
||||
sps.print("The factorial of $n is $fact")
|
||||
|
||||
math.getFactOf(n, aps)
|
||||
|
||||
for (i in 0 until 500)
|
||||
println("other work...")
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package drills.drill01.exercise4
|
||||
|
||||
import drills.drill01.exercise2.PrintService
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.rmi.Remote
|
||||
import java.rmi.RemoteException
|
||||
import java.rmi.server.UnicastRemoteObject
|
||||
@ -17,7 +19,9 @@ class MathImpl : Math, UnicastRemoteObject() {
|
||||
override fun getFactOf(n: Int): Long = fact(n)
|
||||
|
||||
override fun getFactOf(n: Int, ps: PrintService) {
|
||||
ps.print("The factorial of $n is ${fact(n)}")
|
||||
GlobalScope.launch {
|
||||
ps.print("The factorial of $n is ${fact(n)}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun fact(n: Int): Long {
|
||||
|
@ -4,8 +4,7 @@ import util.rmi.Server
|
||||
|
||||
fun main() {
|
||||
Server {
|
||||
val math: Math =
|
||||
MathImpl()
|
||||
val math: Math = MathImpl()
|
||||
Server.bind(math, "math")
|
||||
}.start()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user