Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
godpan
committed
Aug 28, 2017
1 parent
d89f936
commit 0632778
Showing
7 changed files
with
151 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.io.Serializable; | ||
import java.rmi.Remote; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public class JoinRmiEvt implements Remote , Serializable{ | ||
private static final long serialVersionUID = 1L; | ||
private Long id; | ||
private String name; | ||
|
||
public JoinRmiEvt(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
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,10 @@ | ||
import java.rmi.Remote; | ||
import java.rmi.RemoteException; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public interface RemoteRmi extends Remote { | ||
public void sendNoReturn(String message) throws RemoteException, InterruptedException; | ||
public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException; | ||
} |
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,22 @@ | ||
import java.net.MalformedURLException; | ||
import java.rmi.Naming; | ||
import java.rmi.NotBoundException; | ||
import java.rmi.RemoteException; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public class RemoteRmiClient { | ||
public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException, InterruptedException { | ||
System.out.println("the client has started"); | ||
String url = "rmi://127.0.0.1:2553/remote_rmi"; | ||
RemoteRmi remoteRmi = (RemoteRmi) Naming.lookup(url); | ||
Long startTime = System.currentTimeMillis(); | ||
System.out.println("the client has running"); | ||
remoteRmi.sendNoReturn("send no return"); | ||
System.out.println(remoteRmi.sendHasReturn(new JoinRmiEvt(1L,"godpan"))); | ||
Long endTime = System.currentTimeMillis(); | ||
System.out.println("the running time is " + (endTime - startTime)); | ||
System.out.println("the client has end"); | ||
} | ||
} |
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,32 @@ | ||
import java.io.Serializable; | ||
import java.rmi.Remote; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public class JoinRmiEvt implements Remote , Serializable{ | ||
private static final long serialVersionUID = 1L; | ||
private Long id; | ||
private String name; | ||
|
||
public JoinRmiEvt(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
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,20 @@ | ||
import java.net.MalformedURLException; | ||
import java.rmi.AlreadyBoundException; | ||
import java.rmi.Naming; | ||
import java.rmi.RemoteException; | ||
import java.rmi.registry.LocateRegistry; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public class RemoteRMIServer { | ||
public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException, InterruptedException { | ||
System.out.println("the RemoteRMIServer is Starting ..."); | ||
RemoteRmiImpl remoteRmi = new RemoteRmiImpl(); | ||
System.out.println("Binding server implementation to registry"); | ||
LocateRegistry.createRegistry(2553); | ||
Naming.bind("rmi://127.0.0.1:2553/remote_rmi",remoteRmi); | ||
System.out.println("the RemoteRMIServer is Started"); | ||
Thread.sleep(10000000); | ||
} | ||
} |
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,10 @@ | ||
import java.rmi.Remote; | ||
import java.rmi.RemoteException; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public interface RemoteRmi extends Remote { | ||
public void sendNoReturn(String message) throws RemoteException, InterruptedException; | ||
public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException; | ||
} |
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,25 @@ | ||
import java.rmi.RemoteException; | ||
import java.rmi.server.UnicastRemoteObject; | ||
|
||
/** | ||
* Created by panguansen on 17/8/24. | ||
*/ | ||
public class RemoteRmiImpl extends UnicastRemoteObject implements RemoteRmi { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public RemoteRmiImpl() throws RemoteException {}; | ||
|
||
@Override | ||
public void sendNoReturn(String message) throws RemoteException, InterruptedException { | ||
Thread.sleep(2000); | ||
// throw new RemoteException(); | ||
} | ||
|
||
@Override | ||
public String sendHasReturn(JoinRmiEvt joinRmiEvt) throws RemoteException { | ||
if (joinRmiEvt.getId() >= 0) | ||
return new StringBuilder("the").append(joinRmiEvt.getName()).append("has join").toString(); | ||
else return null; | ||
} | ||
} |