java.rmi.dgc


1. Simple RMI Server with DGC

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.dgc.*;

public class RMIServer {

    private RMIServerImpl impl;

    public RMIServer() throws RemoteException {
        impl = new RMIServerImpl();
        UnicastRemoteObject.exportObject(impl, 0);
    }

    public static void main(String[] args) {
        try {
            RMIServer server = new RMIServer();
            System.out.println("Server started");
            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                try {
                    UnicastRemoteObject.unexportObject(server.impl, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

class RMIServerImpl implements RMIInterface {

    @Override
    public String getMessage() {
        return "Hello from the server";
    }

}

2. Client with DGC Lease Checking

3. Server with DGC Cleaner

4. Client with Custom Remote Reference

5. Server with Custom DGC Server

6. Client with Custom Invocation Handler

7. Server with Custom Socket Factory

8. Client with Custom Object Input Stream