Remote Access to IKS Data using Java RMI | Ayurvedic Herb Knowledge Base Example

Remote Access to IKS Data using RMI

🌿 Remote Access to IKS Data using RMI

Remote Method Invocation (RMI) in Java allows us to access methods on a remote server object as if they were local. This can be used in Indian Knowledge System (IKS) applications such as Ayurvedic herb knowledge bases or Sanskrit glossaries.

✨ Example: Herb Knowledge Base with Java RMI

We will create an RMI application where a client can request details about an Ayurvedic herb from a remote server.

1. Remote Interface


import java.rmi.Remote;
import java.rmi.RemoteException;

public interface HerbInfo extends Remote {
    String getHerbDetails(String herbName) throws RemoteException;
}
  

2. Implementation Class (Server-side)


import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.util.HashMap;

public class HerbInfoImpl extends UnicastRemoteObject implements HerbInfo {
    private HashMap<String, String> herbs;

    protected HerbInfoImpl() throws RemoteException {
        super();
        herbs = new HashMap<>();
        herbs.put("Tulsi", "Tulsi is used to boost immunity and treat colds.");
        herbs.put("Neem", "Neem is known for antibacterial properties.");
        herbs.put("Ashwagandha", "Ashwagandha helps in stress relief.");
    }

    public String getHerbDetails(String herbName) throws RemoteException {
        return herbs.getOrDefault(herbName, "Herb not found in database.");
    }
}
  

3. Server Program


import java.rmi.Naming;

public class HerbServer {
    public static void main(String[] args) {
        try {
            HerbInfoImpl herbService = new HerbInfoImpl();
            Naming.rebind("HerbInfoService", herbService);
            System.out.println("HerbInfo RMI Server is running...");
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
  

4. Client Program


import java.rmi.Naming;

public class HerbClient {
    public static void main(String[] args) {
        try {
            HerbInfo herbService = (HerbInfo) Naming.lookup("rmi://localhost/HerbInfoService");
            System.out.println("Details: " + herbService.getHerbDetails("Neem"));
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
  

🚀 How to Run

  • Compile all Java files.
  • Start rmiregistry.
  • Run HerbServer.
  • Run HerbClient to fetch herb details remotely.

✅ This example shows how IKS data such as Ayurvedic herbs can be accessed remotely using RMI.


Post a Comment

Thanks for comment.

Previous Post Next Post