Assign security manager if null

Info icon This preview shows pages 22–25. Sign up to view the full content.

View Full Document Right Arrow Icon
// Assign security manager if (System.getSecurityManager() == null) { System.setSecurityManager (new RMISecurityManager()); } // Call registry for PowerService PowerService service = (PowerService) Naming.lookup ("rmi://" + args[0] + "/PowerService"); To identify a service, we specify an RMI URL. The URL contains the hostname on which the service is located, and the logical name of the service. This returns a PowerService instance, which can then be used just like a local object reference. We can call the methods just as if we'd created an instance of the remote PowerServiceServer ourselves. // Call remote method System.out.println ("Answer : " + service.square(value)); // Call remote method System.out.println ("Answer : " + service.power(value,power)); Writing RMI clients is the easiest part of building distributed services. In fact, there's more code for the user interface menu in the client than there is for the RMI components! To keep things simple, there's no data validation, so be careful when entering numbers. Running the client and server Our example was extremely simple. More complex systems, however, might contain interfaces that change, or whose implementation changes. To run this article's examples, both the client and server will have a copy of the classfiles, but more advanced systems might share the code of the server on a webserver, for downloading as required. If
Image of page 22

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
DS & ADB DCET RAHEEM UNNISA 23 160317742004 your systems do this, don't forget to set the system property java.rmi.server.codebase to the web server directory in which your classes are stored! You can download all the source and class files together as a single ZIP file. Unpack the files into a directory, and then perform the following steps. 1. Start the rmiregistry To start the registry, Windows users should do the following (assuming that your java\bin directory is in the current path):- start rmiregistry To start the registry, Unix users should do the following:- rmiregistry & 2. Compile the server Compile the server, and use the rmic tool to create stub files. 3. Start the server From the directory in which the classes are located, type the following:- java PowerServiceServer 4. Start the client You can run the client locally, or from a different machine. In either case, you'll need to specify the hostname of the machine where you are running the server. If you're running it locally, use localhost as the hostname.java PowerServiceClient localhost.
Image of page 23
DS & ADB DCET RAHEEM UNNISA 24 160317742004 6. Implementation of a Remote object for an employee application having a remote method to find the employee details such as empid, ename, age, salary, and service with RMI. DATABASE TABLE: Creating Table: create table myemp(empid number(10), name varchar(20), DOJ varchar(20), service varchar(20), salary number(10)); Inserting values into table: insert into myemp values(1,’ravi’,’10 -aug- 08’,’manager’,10000); insert into myemp values(2,’boss’,’10 -sept-17 ’,’ceo’,20 000); Executing query: select * from myemp; Saving Table: commit; PROGRAM: Interface program: empint.java import java.rmi.*; public interface empint extends Remote { String getDetails(int id) throws Exception; }
Image of page 24

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 25
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern