Skip to content

Commit

Permalink
add ScalaBasic/ProxyDesignPattern2/, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Sep 12, 2021
1 parent b46c58f commit 82b283e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
- [Observer1](./src/main/scala/ScalaBasic/Observer1)
- Proxy
- [ProxyDesignPattern1](./src/main/scala/ScalaBasic/ProxyDesignPattern1)

- [ProxyDesignPattern2](./src/main/scala/ScalaBasic/ProxyDesignPattern2) : RMI demo

12. Scala Script example
- [DirectoryOP](./src/main/scala/ScalaBasic/DirectoryOP.scala) - Scala `Directory OP` example
Expand Down
14 changes: 14 additions & 0 deletions src/main/scala/ScalaBasic/ProxyDesignPattern2/rmi/MyRemote.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ScalaBasic.ProxyDesignPattern2.rmi

import java.rmi.{Remote, RemoteException}

// https://www.bilibili.com/video/BV12N411R726?p=267&spm_id_from=pageDriver

// a trait, will be used in local and remote
trait MyRemote extends Remote{

// method
// (an abstract method)
@throws(classOf[RemoteException])
def sayHello():String // throws RemoteException
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ScalaBasic.ProxyDesignPattern2.rmi

// https://www.bilibili.com/video/BV12N411R726?p=267&spm_id_from=pageDriver

class MyRemoteClient {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ScalaBasic.ProxyDesignPattern2.rmi

import java.rmi.Naming
import java.rmi.registry.LocateRegistry
import java.rmi.server.UnicastRemoteObject

// https://www.bilibili.com/video/BV12N411R726?p=267&spm_id_from=pageDriver

class MyRemoteImplement extends UnicastRemoteObject with MyRemote {
override def sayHello(): String = {
"hello world :p :p :p"
}
}

object MyRemoteImplement{
def main(args: Array[String]): Unit = {
val service:MyRemote = new MyRemoteImplement()
// binding the service with port 9999
//LocateRegistry.createRegistry(9999)
//Naming.rebind("RemoteHello", service)
Naming.rebind("rmi://127.0.0.1:9999/RemoteHello", service)
println("remote service launch, at 127.0.0.1 with port 9999")
}
}

0 comments on commit 82b283e

Please sign in to comment.