27 lines
907 B
Kotlin
27 lines
907 B
Kotlin
package drills.drill03.exercise2
|
|
|
|
import java.net.MalformedURLException
|
|
import java.rmi.AccessException
|
|
import java.rmi.AlreadyBoundException
|
|
import java.rmi.Naming
|
|
import java.rmi.RemoteException
|
|
import java.rmi.registry.LocateRegistry
|
|
|
|
fun main(args: Array<String>) {
|
|
try {
|
|
if (args[0] == "0")
|
|
LocateRegistry.createRegistry(4242)
|
|
|
|
val container: AgentContainer = AgentContainerImpl()
|
|
Naming.rebind("rmi://localhost:4242/container-${args[0]}", container)
|
|
} catch (e: AccessException) {
|
|
System.err.println("Bind operation not permitted $e")
|
|
} catch (e: RemoteException) {
|
|
System.err.println("Registry could not be contacted $e")
|
|
} catch (e: MalformedURLException) {
|
|
System.err.println("Wrong URL for binding $e")
|
|
} catch (e: AlreadyBoundException) {
|
|
System.err.println("Object alreay bound to the registry $e")
|
|
}
|
|
}
|