13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.8 Introducing RMI141Example 5.11 The Sessi<strong>on</strong> server implementati<strong>on</strong>package net.multitool.RMIDemo;import net.multitool.RMIDemo.*;import java.rmi.*;import java.rmi.server.*;/** Sessi<strong>on</strong>Impl is the server class for the Sessi<strong>on</strong> RMI interface.*/public classSessi<strong>on</strong>Implextends UnicastRemoteObjectimplements Sessi<strong>on</strong>{/** C<strong>on</strong>structor needed to ensure call to UnicastRemoteObject* c<strong>on</strong>structor and to thus propagate the possible excepti<strong>on</strong>.*/public Sessi<strong>on</strong>Impl() throws RemoteExcepti<strong>on</strong> {super();}}/** A static main() for the server. */public static void main(String[] arglist){if (System.getSecurityManager() == null) {System.setSecurityManager(new RMISecurityManager());}}String rmiName = "//penfold/Sessi<strong>on</strong>";try {Sessi<strong>on</strong> adder = new Sessi<strong>on</strong>Impl();Naming.rebind(rmiName, adder);} catch (Excepti<strong>on</strong> e) {e.printStackTrace();}/** Implementati<strong>on</strong> of the RMI method, add. */public int add(int x, int y) throws java.rmi.RemoteExcepti<strong>on</strong>{return x+y;}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!