ServerImpl.java revision 0
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes/*
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes *
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * This code is free software; you can redistribute it and/or modify it
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * under the terms of the GNU General Public License version 2 only, as
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * published by the Free Software Foundation.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes *
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * This code is distributed in the hope that it will be useful, but WITHOUT
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * version 2 for more details (a copy is included in the LICENSE file that
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * accompanied this code).
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes *
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * You should have received a copy of the GNU General Public License version
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * 2 along with this work; if not, write to the Free Software Foundation,
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes *
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * CA 95054 USA or visit www.sun.com if you need additional information or
16b55a35cff91315d261d1baa776138af465c4e4fuankg * have any questions.
16b55a35cff91315d261d1baa776138af465c4e4fuankg */
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesimport java.io.*;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesimport java.rmi.*;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholesimport java.rmi.server.UnicastRemoteObject;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholespublic class ServerImpl
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes extends UnicastRemoteObject
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes implements Server
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes{
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes private String name;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Callback cLocal;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes public ServerImpl(String s) throws java.rmi.RemoteException {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes super();
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes name = s;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes public String sayHello(Callback c) throws RemoteException {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.out.println("Calling Callback method from the ServerImpl");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes cLocal = c;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes new Thread(new Runnable() {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes public void run() {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.out.println(
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes "+ running a new thread in sayHello method!");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes try {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes cLocal.callback();
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes } catch(RemoteException e) {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.out.println(
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes "ServerImpl.main: exception while calling callback " +
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes "method:");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes e.printStackTrace();
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }).start();
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes return "Hello Callback!";
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes public static void main(String args[]) {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes // Create and install the security manager
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.setSecurityManager(new RMISecurityManager());
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes ServerImpl obj = null;
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes try {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes obj = new ServerImpl("ServerImpl");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes Naming.rebind("/ServerImpl", obj);
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.out.println("ServerImpl created and bound in the registry" +
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes " to the name ServerImpl");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.err.println("DTI_DoneInitializing");
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg } catch (Exception e) {
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.out.println("ServerImpl.main: an exception occurred:");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes e.printStackTrace();
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes System.err.println("DTI_Error");
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes }
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes}
3c937b528ca923d5b51e63def9f888af4a77bb40bnicholes