Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.*;
- import java.rmi.registry.LocateRegistry;
- import java.rmi.registry.*;
- import java.rmi.Naming;
- import java.util.*;
- import java.io.*;
- import java.net.InetAddress;
- import java.rmi.server.UnicastRemoteObject;
- import java.rmi.registry.Registry;
- import java.rmi.registry.LocateRegistry;
- /* RMIServer:
- * Author: Dr. Nekrouf ZIANI
- * Date: November 2019
- * © Dr. Nekrouf ZIANI 2019
- */
- public class RMIServer
- {
- private static final String HOST = "localhost";
- //private static final String HOST = "CUD-M652/10.0.32.31";
- private static JDBC dbGUI;
- public JDBC getJDBC()
- {
- return dbGUI;
- }
- /* main method is called when starting
- * the server application */
- public static void main(String[] args) throws Exception
- {
- System.out.println("Start the server .....");
- System.out.println("First, server connects to Database through its Constructor() ...");
- // Database connection
- dbGUI = new JDBC();
- System.out.println("Connection DONE !");
- // Create 2 vectors: One Vector and a One Vector of Vector objects to
- // test retrieving data from the database*/
- Vector vectNum = new Vector();
- Vector<Vector<Object>> vectAllNum = new Vector();
- // Retrieve Data; One row and set of rows (whole database table)
- //through methods getOneRow() and getAlRows() of JDBC
- System.out.println();
- vectNum = dbGUI.getOneRow();
- vectAllNum = dbGUI.getAllRows();
- System.out.println("And here are the 2 vectors, One row (or record) and " + "Set of rows (whoe table):");
- System.out.println("JDBC getOneRow() method is returning: " + vectNum);
- System.out.println("and JDBC getAllRows() method is returning: " + vectAllNum);
- System.out.println();
- System.out.println("Create Object to publish in the naming service through the RemoteImpl constructor with 2 vector parameters");
- RemoteDBImpl obj = new RemoteDBImpl(vectNum, vectAllNum);
- System.out.println("DONE ...");
- System.out.println();
- /* Create the URL to publish the objects */
- String rmiRegName = "rmi://" + HOST + "/myDB";
- // or String nekrouf = "rmi://localhost/myDB";
- System.out.println("The server machine name and address is: " + rmiRegName);
- System.out.println();
- System.out.println("Let's test an RMI call and display ONE record from getRemoteRecord() : ");
- Vector a = obj.getRemoteRecord();
- System.out.println(a);
- System.out.println();
- System.out.println("Let's test an RMI call and display ALL records from getAllRecord() : ");
- Vector<Vector<Object>> b = obj.getAllRecords();
- System.out.println(b);
- InetAddress i = InetAddress.getLocalHost();
- System.out.println(i.toString());
- //"rmi://CUD-M652/10.0.32.31/myDB";
- int port = 1099;
- LocateRegistry.createRegistry(port);
- String url_1 = "rmi://localhost/myDB";
- //String url_1 = "rmi://10.0.22.27:1099/myDB";
- /* Publish the object in the naming service */
- //Naming.rebind("rmi: //localhost/myDB", obj);
- Naming.rebind(url_1, obj);
- System.out.println("Object bound to this address: " + url_1);
- System.out.println("and the object Reference obj is: " + obj);
- System.out.println();
- System.out.println("Binding success !! and server ready for requets ......");
- } // end of main()
- } // end of class RMIServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement