| 1 |
/* |
| 2 |
* junixsocket |
| 3 |
* |
| 4 |
* Copyright 2009-2022 Christian Kohlschütter |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
*/ |
| 18 |
package org.newsclub.net.unix.demo.rmi; |
| 19 |
|
| 20 |
import java.io.IOException; |
| 21 |
import java.rmi.NotBoundException; |
| 22 |
import java.rmi.registry.Registry; |
| 23 |
|
| 24 |
import org.newsclub.net.unix.demo.rmi.services.HelloWorld; |
| 25 |
import org.newsclub.net.unix.rmi.AFUNIXNaming; |
| 26 |
import org.newsclub.net.unix.rmi.RemotePeerInfo; |
| 27 |
|
| 28 |
/** |
| 29 |
* A simple RMI client. Locates the RMI registry via AF_UNIX sockets and calls |
| 30 |
* {@link HelloWorld#hello()}. |
| 31 |
* |
| 32 |
* @author Christian Kohlschütter |
| 33 |
*/ |
| 34 |
public final class SimpleRMIClient { |
| 35 |
public static void main(String[] args) throws IOException, NotBoundException { |
| 36 |
AFUNIXNaming naming = AFUNIXNaming.getInstance(); |
| 37 |
|
| 38 |
System.out.println("Locating registry..."); |
| 39 |
final Registry registry = naming.getRegistry(); |
| 40 |
System.out.println(registry); |
| 41 |
System.out.println(); |
| 42 |
|
| 43 |
HelloWorld obj = (HelloWorld) registry.lookup("helloWorld"); |
| 44 |
System.out.println("HelloWorld instance:"); |
| 45 |
System.out.println(" " + obj); |
| 46 |
System.out.println(" " + RemotePeerInfo.remotePeerCredentials(obj)); |
| 47 |
System.out.println(); |
| 48 |
|
| 49 |
System.out.println("Calling HelloWorld..."); |
| 50 |
System.out.println(obj.hello() + " " + obj.world()); |
| 51 |
} |
| 52 |
} |