forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyServer.java
More file actions
52 lines (44 loc) · 1.29 KB
/
Copy pathMyServer.java
File metadata and controls
52 lines (44 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//file: MyServer.java
import java.rmi.*;
import java.util.*;
public class MyServer
extends java.rmi.server.UnicastRemoteObject
implements RemoteServer {
public MyServer( ) throws RemoteException { }
// implement the RemoteServer interface
public Date getDate( ) throws RemoteException {
return new Date( );
}
public Object execute( WorkRequest work ) throws RemoteException {
return work.execute( );
}
public StringIterator getList() throws RemoteException {
return new MyStringIterator(
new String [] { "Foo", "Bar", "Gee" } );
}
public void asyncExecute(
final WorkRequest request, final WorkListener listener )
throws RemoteException
{
new Thread() {
public void run() {
try {
Thread.sleep(1000);
} catch ( Exception e ) { }
Object result = request.execute();
try {
listener.workCompleted( request, result );
} catch ( RemoteException e ) {
System.out.println( e ); // error calling client
}
}}.start();
}
public static void main(String args[]) {
try {
RemoteServer server = new MyServer( );
Naming.rebind("NiftyServer", server);
} catch (java.io.IOException e) {
// problem registering server
}
}
}