public Cli_GUI() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) { try { MyRemote service = new MyRemoteImpl(); Naming.rebind("RemoteHello", service); } catch (Exception ex) { ex.printStackTrace(); } }
void connect(boolean requireSSL) { setConnectionState(ConnectionState.CONNECTING); try { tryConnect(requireSSL); setConnectionState(ConnectionState.CONNECTED); } catch (Exception e) { if (JConsole.isDebug()) { e.printStackTrace(); } setConnectionState(ConnectionState.DISCONNECTED); } }
public static void main(String[] args) { try { Properties props = new Properties(); props.setProperty("java.security.policy", POLICY_FILE); ActivationGroupDesc agd = new ActivationGroupDesc(props, null); ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd); ACTIVATION_DESC = new ActivationDesc(agid, CLASS_NAME, CODE_LOCATION, DATA, false); } catch (Exception e) { System.err.println("Exception: " + e); e.printStackTrace(); } setup(); }
private static void setup() { try { NotActivatableInterface rsi; // Remote server interface System.setSecurityManager(new RMISecurityManager()); rsi = (NotActivatableInterface) Activatable.register(ACTIVATION_DESC); System.out.println("Got stub for " + SERVER_OBJECT + " implementation"); Naming.rebind(SERVER_OBJECT, rsi); System.out.println("Exported " + SERVER_OBJECT + " implementation"); } catch (Exception e) { System.err.println("Exception: " + e); e.printStackTrace(); } }
public ArrayList<KeyValueServerInterface> getServersList() throws RemoteException { // ArrayList<KeyValueServerInterface> res = new ArrayList(); try { Registry registry = LocateRegistry.getRegistry(); String[] name = registry.list(); for (String str : name) { // if( str.equals(server_name) ) continue; KeyValueServerInterface obj = (KeyValueServerInterface) registry.lookup(str); res.add(obj); } } catch (Exception e) { System.out.println(e.getMessage()); } return res; }
public static void main(String args[]) { if (args.length != 2) { System.err.println("Uso: ObservadorCentralita hostregistro numPuertoRegistro"); return; } // Instancia gestor de seguridad if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { // Obtiene referencia remota del servicio de rmiregistry ServicioCentralita srv = (ServicioCentralita) Naming.lookup("//" + args[0] + ":" + args[1] + "/Centralita"); // | |-> Número de // puerto escucha // |-> Host en el que se ejecuta el // servicio String nombreServicio = "default"; while (nombreServicio == "default") { // Captura el nombre del servicio System.out.println( "Elija el servicio:\n\t[1] Bomberos\n\t[2] Sanitarios\n\t[3] Policía\n\t[4] Guardia Civil"); Scanner input = new Scanner(System.in); String tipoServicio = input.nextLine(); switch (tipoServicio) { case "1": nombreServicio = "Bomberos"; break; case "2": nombreServicio = "Sanitarios"; break; case "3": nombreServicio = "Policia"; break; case "4": nombreServicio = "Guardia Civil"; break; default: nombreServicio = "default"; break; } } // Crea nuevo observador y lo registra en la lista ObservadorImpl o = new ObservadorImpl(nombreServicio); // Llamada al método remoto 'addObservador' del servicio srv.addObservador(o, nombreServicio); // Comrpeuba el nombre del servicio para imprimir código de color if (nombreServicio.equals("Bomberos")) { System.out.println( "\u001B[31mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Sanitarios")) { System.out.println( "\u001B[35mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Policia")) { System.out.println( "\u001B[34mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Guardia Civil")) { System.out.println( "\u001B[32mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } // Se mantiene esperando hasta que se para con Ctrl+D System.out.println("Para salir, pulsar Ctrl+D\n"); Scanner sleep = new Scanner(System.in); while (sleep.hasNextInt()) {} // Elimina de la lista al observador. Llamada al método remoto 'delObservador' del servicio srv.delObservador(o, nombreServicio); System.exit(0); } // Excepción RMI catch (RemoteException e) { System.err.println("Error de comunicación: " + e.toString()); } // Excepción cliente catch (Exception e) { System.err.println("Excepción en ObservadorCentralita: "); e.printStackTrace(); } }
/** check to make sure that the output from a spawned vm is formatted/annotated properly. */ public static boolean checkAnnotations(int iteration) throws IOException { try { Thread.sleep(5000); } catch (Exception e) { System.err.println(e.getMessage()); } /** * cause the spawned vm to generate output that will be checked for proper annotation. printOut * is actually being called on an activated implementation. */ myRMI.printOut("out" + iteration); myRMI.printErr("err" + iteration); myRMI.printOut("out" + iteration); myRMI.printErr("err" + iteration); /* we have to wait for output to filter down * from children so we can read it before we * kill rmid. */ String outString = null; String errString = null; for (int i = 0; i < 5; i++) { // have to give output from rmid time to trickle down to // this process try { Thread.sleep(4000); } catch (InterruptedException e) { } outString = rmidOut.toString(); errString = rmidErr.toString(); if ((!outString.equals("")) && (!errString.equals(""))) { System.err.println("obtained annotations"); break; } System.err.println("rmid output not yet received, retrying..."); } rmidOut.reset(); rmidErr.reset(); // only test when we are annotating..., first run does not annotate if (iteration >= 0) { System.err.println("Checking annotations..."); System.err.println(outString); System.err.println(errString); StringTokenizer stOut = new StringTokenizer(outString, ":"); StringTokenizer stErr = new StringTokenizer(errString, ":"); String execErr = null; String execOut = null; String destOut = null; String destErr = null; String outTmp = null; String errTmp = null; while (stOut.hasMoreTokens()) { execOut = outTmp; outTmp = destOut; destOut = stOut.nextToken(); } while (stErr.hasMoreTokens()) { execErr = errTmp; errTmp = destErr; destErr = stErr.nextToken(); } if ((execErr == null) || (errTmp == null) || (destErr == null)) { return false; } if ((execOut == null) || (outTmp == null) || (destOut == null)) { return false; } // just make sure that last two strings are what we expect. if (execOut.equals("ExecGroup-" + iteration) && (new String(destOut.substring(0, 4)).equals("out" + iteration)) && (execErr.equals("ExecGroup-" + iteration)) && (new String(destErr.substring(0, 4)).equals("err" + iteration))) { return true; } else { return false; } } return true; }