public void ejecutar(String[] s) { long op1 = Long.valueOf(s[0]); long op2 = Long.parseLong(s[1]); escribirResultado.mostrarResultado( "El resultado de " + operacion.getOpNombre() + op1 + " y " + op2 + " es " + operacion.operar(op1, op2)); escribirResultado.mostrarResultado( "Si se quiere multiplicar " + op1 + " y " + op2 + " el resultado es " + operacionX.operar(op1, op2)); }
@Override public void run() { respuestas = new ArrayList<String>(); System.out.println("Connection successful"); System.out.println("Waiting ....."); PrintWriter out = null; BufferedReader in = null; try { out = new PrintWriter(clientSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println("Input : " + inputLine); String[] a = inputLine.split(" "); String tipo = a[0]; if (tipo.equalsIgnoreCase("server")) { String nombre = a[1]; String direccion = a[2]; int puerto = Integer.parseInt(a[3]); Proceso p = new Proceso(nombre, direccion, puerto); directorio.add(p); } else if (tipo.equalsIgnoreCase("client")) { List<Thread> lt = new ArrayList<Thread>(); lo = new ArrayList<Operacion>(); for (int i = 1; i < a.length; i++) { String nombre = a[i]; if (nombre.equalsIgnoreCase("historial")) { List<Operacion> op = new ArrayList<Operacion>(); op = leer(); String s = "HISTORIAL::::::"; for (Operacion o : op) { s += "------- Operacion: " + o.getOperacion() + " Respuesta: " + o.getRespuesta(); } out.println(s); continue; } else { i++; String operacion = a[i]; for (Proceso p : directorio) { if (p.getNombre().equalsIgnoreCase(nombre)) { Operacion o = new Operacion(p.getDireccion(), p.getPuerto(), operacion); lo.add(o); Thread t1 = new Thread(o); t1.start(); lt.add(t1); break; } } serializar(); } } int i = 0; for (Thread t : lt) { t.join(); // out.println(((Operacion)((Object)(t.getContextClassLoader()))).getRespuesta()); out.println(lo.get(i).getRespuesta()); i++; } } if (inputLine.equals("Bye.")) break; } } catch (IOException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { out.close(); in.close(); clientSocket.close(); clientSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }