/** * Deregistra un player dal server, rendendo nuovamente disponibile il nickname ad altri player. * * @param nickname nome del player da deregistrare */ public void deregisterPlayer(String nickname) { try { server.deregister(nickname); } catch (RemoteException e) { System.out.println("Impossible to logout." + e.getMessage()); } }
/** * Create a MonitoredHostProvider instance using the given HostIdentifier. * * @param hostId the host identifier for this MonitoredHost * @throws MonitorException Thrown on any error encountered while communicating with the remote * host. */ public MonitoredHostProvider(HostIdentifier hostId) throws MonitorException { this.hostId = hostId; this.listeners = new ArrayList(); this.interval = DEFAULT_POLLING_INTERVAL; this.activeVms = new HashSet(); String rmiName; String sn = serverName; String path = hostId.getPath(); if ((path != null) && (path.length() > 0)) { sn = path; } if (hostId.getPort() != -1) { rmiName = "rmi://" + hostId.getHost() + ":" + hostId.getPort() + sn; } else { rmiName = "rmi://" + hostId.getHost() + sn; } try { remoteHost = (RemoteHost) Naming.lookup(rmiName); } catch (RemoteException e) { /* * rmi registry not available * * Access control exceptions, where the rmi server refuses a * connection based on policy file configuration, come through * here on the client side. Unfortunately, the RemoteException * doesn't contain enough information to determine the true cause * of the exception. So, we have to output a rather generic message. */ String message = "RMI Registry not available at " + hostId.getHost(); if (hostId.getPort() == -1) { message = message + ":" + java.rmi.registry.Registry.REGISTRY_PORT; } else { message = message + ":" + hostId.getPort(); } if (e.getMessage() != null) { throw new MonitorException(message + "\n" + e.getMessage(), e); } else { throw new MonitorException(message, e); } } catch (NotBoundException e) { // no server with given name String message = e.getMessage(); if (message == null) message = rmiName; throw new MonitorException("RMI Server " + message + " not available", e); } catch (MalformedURLException e) { // this is a programming problem e.printStackTrace(); throw new IllegalArgumentException("Malformed URL: " + rmiName); } this.vmManager = new RemoteVmManager(remoteHost); this.timer = new Timer(true); }
public void broadcastGaggleTuple(GaggleTuple gaggleTuple) { gaggleTuple.setSpecies(defaultSpecies); try { gaggleBoss.broadcastTuple(myGaggleName, targetGoose, gaggleTuple); } catch (RemoteException e) { System.err.println("error broadcasting network from RShellGoose " + myGaggleName); e.printStackTrace(); } }
// ---------------------------------------------------------------------------------------- public void createAndBroadcastHashMap( String title, String attributeName, String[] names, String[] values) { try { gaggleBoss.broadcastTuple( myGaggleName, targetGoose, createGaggleTupleForBroadcast(title, names, values)); } catch (RemoteException rex) { System.err.println("error broadcasting hashmap from RShellGoose " + myGaggleName); rex.printStackTrace(); } } // createAndBroadcastHashMap (String [] values)
/** * *************************************************************** * * @param ip * @param port * @return */ public ChordMessageInterface rmiChord(String ip, int port) { ChordMessageInterface chord = null; try { Registry registry = LocateRegistry.getRegistry(ip, port); chord = (ChordMessageInterface) (registry.lookup("Chord")); return chord; } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } return null; }
// ---------------------------------------------------------------------------------------- // todo update method names (make sure calls in R side match) public void createAndBroadcastHashMap( String title, String attributeName, String[] names, double[] values) { GaggleTuple gaggleTuple = new GaggleTuple(); gaggleTuple.setName(title); Tuple tuple = new Tuple(title); for (int i = 0; i <= names.length; i++) { tuple.addSingle(new Single(names[i], values[i])); } gaggleTuple.setData(tuple); gaggleTuple.setSpecies(defaultSpecies); try { gaggleBoss.broadcastTuple(myGaggleName, targetGoose, gaggleTuple); } catch (RemoteException rex) { System.err.println("error broadcasting hashmap from RShellGoose " + myGaggleName); rex.printStackTrace(); } } // createAndBroadcastHashMap (double [] values)
// ---------------------------------------------------------------------------------------- // is this called from anywhere? doesn't look like it public void createAndBroadcastNetwork( String sourceNode, String[] targetNodes, double[] weights, String[] targetTypes) { // System.out.println ("createAndBroadcastNetwork, source: " + sourceNode); Network network = new Network(); addMetaDataToNetwork(network); network.setSpecies(defaultSpecies); for (int i = 0; i < targetNodes.length; i++) { Interaction interaction = new Interaction(sourceNode, targetNodes[i], targetTypes[i]); network.add(interaction); String edgeName = sourceNode + " (" + targetTypes[i] + ") " + targetNodes[i]; // System.out.println ("adding weight " + weights [i] + " for edge " + edgeName); network.addEdgeAttribute(edgeName, "weight", weights[i]); } try { gaggleBoss.broadcastNetwork(myGaggleName, targetGoose, network); } catch (RemoteException rex) { System.err.println("error broadcasting network from RShellGoose " + myGaggleName); rex.printStackTrace(); } } // createAndBroadcastNetwork
/** * a network is a collection of (possibly degenerate) interactions. the R client should pass 3 * arrays of strings, having the following structure * * <p>edges consist of strings like "VNG0723G::VNG1233G::PhylogeneticProfile" node attributes: * "VNG1233G::commonName::pepq2" edge attributes: * "VNG0723G::VNG1233G::PhylogeneticProfile::confidence::0.533" */ public void createAndBroadcastNetwork( String[] interactionStrings, String[] nodeAttributeStrings, String[] edgeAttributeStrings, String name) { Network network = new Network(); addMetaDataToNetwork(network); network.setName(name); network.setSpecies(defaultSpecies); for (String interactionString : interactionStrings) { String[] tokens = interactionString.split("::"); int tokenCount = tokens.length; // for (int t=0; t < tokens.length; t++) // System.out.println (" edge token " + t + ": " + tokens [t]); if (tokenCount == 1 && tokens[0].trim().length() > 0) { // System.out.println ("adding one orphan node to network: " + tokens [0]); network.add(tokens[0]); } else if (tokenCount == 3) { String sourceNode = tokens[0]; String targetNode = tokens[1]; String interactionType = tokens[2]; network.add(new Interaction(sourceNode, targetNode, interactionType)); } // else: good interaction } // for i // System.out.println ("nodeAttributeStrings count: " + nodeAttributeStrings.length); for (String nodeAttributeString : nodeAttributeStrings) { // System.out.println (" " + nodeAttributeStrings [i]); String[] tokens = nodeAttributeString.split("::"); if (tokens.length == 3) { String nodeName = tokens[0].trim(); String attributeName = tokens[1].trim(); String rawValue = tokens[2].trim(); Object value = StringToObjectConverter.convert(rawValue); network.addNodeAttribute(nodeName, attributeName, value); } // if 3 tokens } // for i // System.out.println ("edgeAttributeStrings count: " + edgeAttributeStrings.length); for (String edgeAttributeString : edgeAttributeStrings) { // System.out.println (" " + edgeAttributeStrings [i]); String[] tokens = edgeAttributeString.split("::"); if (tokens.length == 5) { String sourceNode = tokens[0].trim(); String targetNode = tokens[1].trim(); String edgeType = tokens[2].trim(); String attributeName = tokens[3].trim(); String rawValue = tokens[4].trim(); Object value = StringToObjectConverter.convert(rawValue); String edgeName = sourceNode + " (" + edgeType + ") " + targetNode; network.addEdgeAttribute(edgeName, attributeName, value); } // if 5 tokens } // for i // System.out.println ("RShellGoose, about to broadcast network"); // System.out.println (" node count: " + network.getNodes().length); // System.out.println (" connected: " + network.getConnectedNodes ().size ()); // System.out.println (" orphan: " + network.getOrphanNodes().length); try { gaggleBoss.broadcastNetwork(myGaggleName, targetGoose, network); } catch (RemoteException rex) { System.err.println("error broadcasting network from RShellGoose " + myGaggleName); rex.printStackTrace(); } } // createAndBroadcastNetwork
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(); } }
public synchronized void drag_direct(VisADRay ray, boolean first, int mouseModifiers) { if (barbValues == null || ref == null || shadow == null) return; if (first) { stop = false; } else { if (stop) return; } // modify direction if mshift != 0 // modify speed if mctrl != 0 // modify speed and direction if neither int mshift = mouseModifiers & InputEvent.SHIFT_MASK; int mctrl = mouseModifiers & InputEvent.CTRL_MASK; float o_x = (float) ray.position[0]; float o_y = (float) ray.position[1]; float o_z = (float) ray.position[2]; float d_x = (float) ray.vector[0]; float d_y = (float) ray.vector[1]; float d_z = (float) ray.vector[2]; if (pickCrawlToCursor) { if (first) { offset_count = OFFSET_COUNT_INIT; } else { if (offset_count > 0) offset_count--; } if (offset_count > 0) { float mult = ((float) offset_count) / ((float) OFFSET_COUNT_INIT); o_x += mult * offsetx; o_y += mult * offsety; o_z += mult * offsetz; } } if (first || refirst) { point_x = barbValues[2]; point_y = barbValues[3]; point_z = 0.0f; line_x = 0.0f; line_y = 0.0f; line_z = 1.0f; // lineAxis == 2 in DataRenderer.drag_direct } // end if (first || refirst) float[] x = new float[3]; // x marks the spot // DirectManifoldDimension = 2 // intersect ray with plane float dot = (point_x - o_x) * line_x + (point_y - o_y) * line_y + (point_z - o_z) * line_z; float dot2 = d_x * line_x + d_y * line_y + d_z * line_z; if (dot2 == 0.0) return; dot = dot / dot2; // x is intersection x[0] = o_x + dot * d_x; x[1] = o_y + dot * d_y; x[2] = o_z + dot * d_z; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ try { Tuple data = (Tuple) link.getData(); int n = ((TupleType) data.getType()).getNumberOfRealComponents(); Real[] reals = new Real[n]; int k = 0; int m = data.getDimension(); for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { reals[k++] = (Real) component; } else if (component instanceof RealTuple) { for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { reals[k++] = (Real) ((RealTuple) component).getComponent(j); } } } if (first || refirst) { // get first Data flow vector for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; data_flow[i] = (j >= 0) ? (float) reals[j].getValue() : 0.0f; } if (coord != null) { float[][] ds = {{data_flow[0]}, {data_flow[1]}, {data_flow[2]}}; ds = coord.toReference(ds); data_flow[0] = ds[0][0]; data_flow[1] = ds[1][0]; data_flow[2] = ds[2][0]; } data_speed = (float) Math.sqrt( data_flow[0] * data_flow[0] + data_flow[1] * data_flow[1] + data_flow[2] * data_flow[2]); float barb0 = barbValues[2] - barbValues[0]; float barb1 = barbValues[3] - barbValues[1]; /* System.out.println("data_flow = " + data_flow[0] + " " + data_flow[1] + " " + data_flow[2]); System.out.println("barbValues = " + barbValues[0] + " " + barbValues[1] + " " + barbValues[2] + " " + barbValues[3]); System.out.println("data_speed = " + data_speed); */ } // end if (first || refirst) // convert x to a flow vector, and from spatial to earth if (getRealVectorTypes(which_barb) instanceof EarthVectorType) { // don't worry about vector magnitude - // data_speed & display_speed take care of that float eps = 0.0001f; // estimate derivative with a little vector float[][] spatial_locs = { {barbValues[0], barbValues[0] + eps * (x[0] - barbValues[0])}, {barbValues[1], barbValues[1] + eps * (x[1] - barbValues[1])}, {0.0f, 0.0f} }; /* System.out.println("spatial_locs = " + spatial_locs[0][0] + " " + spatial_locs[0][1] + " " + spatial_locs[1][0] + " " + spatial_locs[1][1]); */ float[][] earth_locs = spatialToEarth(spatial_locs); // WLH - 18 Aug 99 if (earth_locs == null) return; /* System.out.println("earth_locs = " + earth_locs[0][0] + " " + earth_locs[0][1] + " " + earth_locs[1][0] + " " + earth_locs[1][1]); */ x[2] = 0.0f; x[0] = (earth_locs[1][1] - earth_locs[1][0]) * ((float) Math.cos(Data.DEGREES_TO_RADIANS * earth_locs[0][0])); x[1] = earth_locs[0][1] - earth_locs[0][0]; /* System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // if (!(getRealVectorTypes(which_barb) instanceof EarthVectorType)) // convert x to vector x[0] -= barbValues[0]; x[1] -= barbValues[1]; // adjust for spatial map scalings but don't worry about vector // magnitude - data_speed & display_speed take care of that // also, spatial is Cartesian double[] ranges = getRanges(); for (int i = 0; i < 3; i++) { x[i] /= ranges[i]; } /* System.out.println("ranges = " + ranges[0] + " " + ranges[1] + " " + ranges[2]); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } // WLH 6 August 99 x[0] = -x[0]; x[1] = -x[1]; x[2] = -x[2]; /* may need to do this for performance float[] xx = {x[0], x[1], x[2]}; addPoint(xx); */ float x_speed = (float) Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); /* WLH 16 April 2002 - from Ken if (x_speed < 0.000001f) x_speed = 0.000001f; */ if (x_speed < 0.01f) x_speed = 0.01f; if (first || refirst) { display_speed = x_speed; } refirst = false; if (mshift != 0) { // only modify data_flow direction float ratio = data_speed / x_speed; x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; /* System.out.println("direction, ratio = " + ratio + " " + data_speed + " " + x_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else if (mctrl != 0) { // only modify data_flow speed float ratio = x_speed / display_speed; if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; refirst = true; } x[0] = ratio * data_flow[0]; x[1] = ratio * data_flow[1]; x[2] = ratio * data_flow[2]; /* System.out.println("speed, ratio = " + ratio + " " + x_speed + " " + display_speed); System.out.println("x = " + x[0] + " " + x[1] + " " + x[2]); */ } else { // modify data_flow speed and direction float ratio = data_speed / display_speed; /* System.out.println("data_speed = " + data_speed + " display_speed = " + display_speed + " ratio = " + ratio + " EPS = " + EPS); System.out.println("x = " + x[0] + " " + x[1] +" " + x[2] + " x_speed = " + x_speed); data_speed = 21.213203 display_speed = 0.01 ratio = 2121.3203 EPS = 0.2 x = 1.6170928E-4 1.6021729E-4 -0.0 x_speed = 0.01 wind = (0.3430372, 0.33987218) at (-35.0, 5.0) */ if (data_speed < EPS) { data_flow[0] = 2.0f * EPS; x[0] = data_flow[0]; x[1] = data_flow[1]; x[2] = data_flow[2]; refirst = true; } else { x[0] *= ratio; x[1] *= ratio; x[2] *= ratio; } } if (coord != null) { float[][] xs = {{x[0]}, {x[1]}, {x[2]}}; xs = coord.fromReference(xs); x[0] = xs[0][0]; x[1] = xs[1][0]; x[2] = xs[2][0]; } // now replace flow values Vector vect = new Vector(); for (int i = 0; i < 3; i++) { int j = flowToComponent[i]; if (j >= 0) { RealType rtype = (RealType) reals[j].getType(); reals[j] = new Real(rtype, (double) x[i], rtype.getDefaultUnit(), null); // WLH 31 Aug 2000 Real r = reals[j]; Unit overrideUnit = null; if (directMap[i] != null) { overrideUnit = directMap[i].getOverrideUnit(); } Unit rtunit = rtype.getDefaultUnit(); // units not part of Time string if (overrideUnit != null && !overrideUnit.equals(rtunit) && !RealType.Time.equals(rtype)) { double d = (float) overrideUnit.toThis((double) x[0], rtunit); r = new Real(rtype, d, overrideUnit); String valueString = r.toValueString(); vect.addElement(rtype.getName() + " = " + valueString); } else { // create location string vect.addElement(rtype.getName() + " = " + x[i]); } } } getDisplayRenderer().setCursorStringVector(vect); Data newData = null; // now build new RealTuple or Flat Tuple if (data instanceof RealTuple) { newData = new RealTuple( ((RealTupleType) data.getType()), reals, ((RealTuple) data).getCoordinateSystem()); } else { Data[] new_components = new Data[m]; k = 0; for (int i = 0; i < m; i++) { Data component = data.getComponent(i); if (component instanceof Real) { new_components[i] = reals[k++]; } else if (component instanceof RealTuple) { Real[] sub_reals = new Real[((RealTuple) component).getDimension()]; for (int j = 0; j < ((RealTuple) component).getDimension(); j++) { sub_reals[j] = reals[k++]; } new_components[i] = new RealTuple( ((RealTupleType) component.getType()), sub_reals, ((RealTuple) component).getCoordinateSystem()); } } newData = new Tuple(new_components, false); } ref.setData(newData); } catch (VisADException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } catch (RemoteException e) { // do nothing System.out.println("drag_direct " + e); e.printStackTrace(); } }