private static Echo[] spawnAndTest() {

    System.err.println("\nCreate Test-->");

    Echo[] echo = new Echo[protocol.length];

    for (int i = 0; i < protocol.length; i++) {

      JavaVM serverVM =
          new JavaVM("EchoImpl", "-Djava.security.policy=" + TestParams.defaultPolicy, protocol[i]);

      System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i]));

      try {
        /* spawn VM for EchoServer */
        serverVM.start();

        /* lookup server */
        int tries = 12; // need enough tries for slow machine.
        echo[i] = null;
        do {
          try {
            echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT + "/EchoServer");
            break;
          } catch (NotBoundException e) {
            try {
              Thread.sleep(2000);
            } catch (Exception ignore) {
            }
            continue;
          }
        } while (--tries > 0);

        if (echo[i] == null) TestLibrary.bomb("server not bound in 12 tries", null);

        /* invoke remote method and print result*/
        System.err.println("Bound to " + echo[i]);
        byte[] data = ("Greetings, citizen " + System.getProperty("user.name") + "!").getBytes();
        byte[] result = echo[i].echoNot(data);
        for (int j = 0; j < result.length; j++) result[j] = (byte) ~result[j];
        System.err.println("Result: " + new String(result));
        echo[i].shutdown();

      } catch (Exception e) {
        TestLibrary.bomb("test failed", e);

      } finally {
        serverVM.destroy();
        try {
          Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
        } catch (Exception e) {
          TestLibrary.bomb("unbinding EchoServer", e);
        }
      }
    }
    return echo;
  }
Exemple #2
0
  public static void main(String[] args) {
    if (args.length != 1) {
      System.out.println("Usage : java Client <machine du Serveur:port du rmiregistry>");
      System.exit(0);
    }
    try {
      int[][] a = {{1, 0, 0}, {0, 2, 0}, {0, 0, 3}};
      int[][] b = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};

      int[][] res;

      OpMatrice op = (OpMatrice) Naming.lookup("rmi://" + args[0] + "/Matrice");
      res = op.multiplicationMatrice(a, b);
      op.AffichageMatrice(res);
    } catch (NotBoundException re) {
      System.out.println(re);
    } catch (RemoteException re) {
      System.out.println(re);
    } catch (MalformedURLException e) {
      System.out.println(e);
    }
  }
  /**
   * Instantiates an event handler for forwarding events from a specific object.
   *
   * @param receiverAddress The address of the RMI service to be called when the notification is
   *     forwarded.
   * @param rmiConnectorServer The Rmi connector Server
   */
  public RmiNotificationForwarder(
      RmiConnectorAddress receiverAddress, RmiConnectorServer rmiConnectorServer)
      throws RemoteException, IllegalAccessException {

    this.receiverAddress = receiverAddress;
    this.rmiConnectorServer = rmiConnectorServer;

    // ---------------------------
    // build the RMI url
    // ---------------------------
    String receiverName =
        new String(
            "rmi://"
                + receiverAddress.getHost()
                + ":"
                + receiverAddress.getPort()
                + "/"
                + receiverAddress.getName());
    if (logger.finestOn()) {
      logger.finest("Constructor", "looking for " + receiverName);
    }

    // ---------------------------
    // We are going to try to get a reference on the receiver
    // ---------------------------
    try {
      this.rmiNotificationReceiver = (RmiNotificationReceiver) Naming.lookup(receiverName);
      connected = true;
      if (this.rmiNotificationReceiver == null) {
        if (logger.finestOn()) {
          logger.finest("handleEvent", "receiver is null");
        }
        throw new RemoteException(
            "Can't contact RMI Notification receive server at " + receiverName);
      }
    } catch (Exception x) {
      throw new RemoteException("Can't contact RMI Notification receive server at " + receiverName);
    }
  }
Exemple #4
0
 public static void main(String[] args) throws Exception {
   servPolling contRemoto = new servPolling();
   Naming.bind("Servidor_Polling", contRemoto);
   System.out.println("Servidor Remoto Preparado");
 }
Exemple #5
0
  public static void main(String[] args) {
    Ping obj = null;
    Registry registry = null;

    try {
      /*
       * create registry
       */
      TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");

      System.err.println("creating Registry...");

      registry = TestLibrary.createRegistryOnUnusedPort();
      int port = TestLibrary.getRegistryPort(registry);
      /*
       * create object with custom ref and bind in registry
       */
      System.err.println("creating UseCustomRef...");
      UseCustomRef cr = new UseCustomRef();
      RemoteRef ref = cr.getRef();
      if (!(ref instanceof CustomServerRef)) {
        TestLibrary.bomb("test failed: reference not " + "instanceof CustomServerRef");
      }

      String name = "//:" + port + "/UseCustomRef";
      //      String name = "UseCustomRef";
      System.err.println("binding object in registry...");
      Naming.rebind(name, cr);

      /*
       * look up object and invoke its ping method
       */
      System.err.println("ping object...");
      obj = (Ping) Naming.lookup(name);
      obj.ping();

      /*
       * pass object with custom ref in remote call
       */
      System.err.println("pass object in remote call...");
      obj.receiveAndPing(cr);

      /*
       * write remote object with custom ref to output stream
       */
      System.err.println("writing remote object to stream...");
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(bout);
      out.writeObject(cr);
      out.flush();
      out.close();

      /*
       * read back remote object from output stream
       */
      System.err.println("reading remote object from stream...");
      ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
      cr = (UseCustomRef) in.readObject();

      /*
       * re-export object and ping
       */
      System.err.println("re-export object read...");
      cr.exportObject();
      System.err.println("look up object again...");
      Naming.rebind(name, cr);
      System.err.println("ping object read...");
      obj = (Ping) Naming.lookup(name);
      obj.ping();
      System.err.println("TEST PASSED");
      Naming.unbind(name);
      cr = null;

    } catch (Exception e) {
      TestLibrary.bomb("test failed with exception: ", e);
    } finally {
      TestLibrary.unexport(obj);
      TestLibrary.unexport(registry);

      registry = null;
      obj = null;
    }
  }