-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ScalaBasic/ProxyDesignPattern2/, update readme
- Loading branch information
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/scala/ScalaBasic/ProxyDesignPattern2/rmi/MyRemote.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/scala/ScalaBasic/ProxyDesignPattern2/rmi/MyRemoteClient.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/scala/ScalaBasic/ProxyDesignPattern2/rmi/MyRemoteImplement.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |