Download Nueva colección ejercicios tema 4
Document related concepts
no text concepts found
Transcript
COLECCIÓN DE PROBLEMAS Y CUESTIONES SERVIDORES DE INFORMACIÓN Curso 2005-2006 Tema 4 Pregunta 1. Enumere algunos servicios CORBA Ejercicio 2. Tenemos acceso al código de un cliente Java que utiliza la invocación remota de un método mediante CORBA y es el siguiente: import HelloApp.*; import org.omg.CosNaming.*; import org.omg.CORBA.*; public class HelloClient { public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = ORB.init(args, null); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); NamingContext ncRef = NamingContextHelper.narrow(objRef); // resolve the Object Reference in Naming // make sure there are no spaces between "" NameComponent nc = new NameComponent("Hello", ""); NameComponent path[] = {nc}; Hello helloRef = HelloHelper.narrow(ncRef.resolve(path)); // call the Hello server object and print results String hello = helloRef.sayHello(); System.out.println(hello); } catch (Exception e) { System.out.println("ERROR : " + e) ; e.printStackTrace(System.out); } } } ¿Cómo definiría la interfaz del servicio remoto en IDL? 1 Sol: module HelloApp { interface Hello { string sayHello(); }; }; Pregunta 3. Al convertir IDL a Java comentar para qué se crean las clases Holder. Sol: Resuelven el problema del paso de parámetros de salida (out) y entrada/salida (inout). Idea: Para cada tipo, definir una clase que contenga un atributo de ese tipo. En Java no se puede modificar una referencia pasada como parámetro, pero sí el estado del objeto. El compilador crea un clase holder para cada tipo: Ejemplo Tipo TipoHolder Accedemos al valor a través del campo “value”. Pregunta 4. Comentar qué información contienen las referencias a objeto CORBA. Sol: 2 Pregunta 5. En un fichero de un servidor de información encontramos un fichero cuyo contenido es: grant { permission java.net.SocketPermission "*:1024-65535", "connect,accept"; permission java.io.FilePermission ".\\classes\\-", "read"; }; Comentar de qué fichero puede tratarse y para qué sirve. Problema 6. Defina la interfaz RMI de nombre “RMIExample” con un único método PostMsg que reciba como argumento un String y retorne un boolean. Sol: import java.rmi.*; public interface RMIExample extends Remote { public boolean PostMsg(String strMsg) throws RemoteException; } Problema 7. Tenemos acceso al código de un servidor RMI y es el siguiente: package messenger; import java.rmi.*; import java.rmi.server.*; public class MessengerImpl extends RemoteObject implements Messenger { public MessengerImpl() throws RemoteException { super(); } public String getMessage() { return("Wilma"); } public static void main(String args[]) { if (System.getSecurityManager()==null) { System.setSecurityManager(new RMISecurityManager()); } System.out.println("Created security manager."); try { 3 MessengerImpl mess = new MessengerImpl(); Naming.rebind("//grace.evergreen.edu/MessengerService",mess); } catch (Exception e) { System.out.println("Messenger Server error:" + e.getMessage()); e.printStackTrace(); } } } Pero encontramos un problema. ¿Podría decir cual es? Sol: La clase debe extender UnicastRemoteObject no RemoteObject Notar la presencia del constructor y cómo este se declara para poder lanzar RemoteExceptions. 4