Exemplo n.º 1
0
  /**
   * Returns the Registry on the local machine on port IRMI_Defs.REGISTRY_PORT, as a server would
   * require. Creates the Registry if it isn't already running. Returns null system if unable to
   * create a Registry if needed.
   *
   * @return the Registry or null if no Registry could be made or found.
   */
  @Override
  public Registry getLocalRegistry() {

    try {
      // First try to create a registry
      return LocateRegistry.createRegistry(IRMI_Defs.REGISTRY_PORT);
    } catch (RemoteException e) {
      outputCmd.apply(
          "Could not create registry: " + e + "\n", "Attempting to locate existing registry...");
      try {
        // Creating a new registry will fail if it already exists, so
        // try to find it.
        Registry registry = LocateRegistry.getRegistry(IRMI_Defs.REGISTRY_PORT);
        outputCmd.apply("RMIUtils.getLocalRegistry: Success! Found Registry: " + registry);
        return registry;
      } catch (RemoteException e2) {
        outputCmd.apply(
            "RMIUtils.getLocalRegistry: Could not get registry on port "
                + IRMI_Defs.REGISTRY_PORT
                + ". \n"
                + e);
        return null;
      }
    }
  }
Exemplo n.º 2
0
 private void checkSslConfig() throws IOException {
   // Get the reference to the RMI Registry and lookup RMIServer stub
   //
   Registry registry;
   try {
     registry =
         LocateRegistry.getRegistry(registryHostName, registryPort, sslRMIClientSocketFactory);
     try {
       stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
     sslRegistry = true;
   } catch (IOException e) {
     registry = LocateRegistry.getRegistry(registryHostName, registryPort);
     try {
       stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
     sslRegistry = false;
   }
   // Perform the checks for secure stub
   //
   try {
     checkStub(stub, rmiServerImplStubClass);
     sslStub = true;
   } catch (SecurityException e) {
     sslStub = false;
   }
 }
  public static void main(String[] args) {

    System.out.println("\nRegression test for bug 4115696\n");

    TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");

    try {
      LocateRegistry.createRegistry(REGISTRY_PORT);
    } catch (Exception e) {
      TestLibrary.bomb("creating registry", e);
    }

    RMID rmid = null;

    try {
      rmid = RMID.createRMID(true);
      rmid.addArguments(
          new String[] {
            "-C-Djava.security.policy="
                + TestParams.defaultGroupPolicy
                + " -C-Djava.security.manager=java.rmi.RMISecurityManager "
          });
      rmid.start();

      Echo[] echo = spawnAndTest();
      reactivateAndTest(echo);
    } catch (IOException e) {
      TestLibrary.bomb("creating rmid", e);
    } finally {
      if (rmid != null) rmid.destroy();
    }
  }
Exemplo n.º 4
0
  public SetupDataClient() throws RemoteException {

    try {
      // get the registry
      registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
      // look up the remote object
      rmiServer = (databaseinter) registry.lookup("Database");

      rmiServer.receiveMessage("abc");
      // starting time
      long time1 = System.currentTimeMillis();
      // call the remote method

      System.out.println("sending " + text + " to " + serverAddress + ":" + serverPort);
      // receiving time
      long time2 = System.currentTimeMillis();
      long timedelay = time2 - time1;
      System.out.println("RMI delay time: " + timedelay);
      // converting process

      // finish converting
      long time3 = System.currentTimeMillis();
      long timefinish = time3 - time1;
      System.out.println("Total time: " + timefinish);
    } catch (NotBoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("File not found");
      System.out.println(e.getMessage());
      e.printStackTrace();
    }
  }
Exemplo n.º 5
0
 /**
  * Connects to the SimpleDB server on the specified host. The method retrieves the RemoteDriver
  * stub from the RMI registry on the specified host. It then calls the connect method on that
  * stub, which in turn creates a new connection and returns the RemoteConnection stub for it. This
  * stub is wrapped in a SimpleConnection object and is returned.
  *
  * <p>The current implementation of this method ignores the properties argument.
  *
  * @see java.sql.Driver#connect(java.lang.String, Properties)
  */
 public Connection connect(String url, Properties prop) throws SQLException {
   try {
     String host = url.replace("jdbc:simpledb://", ""); // assumes no port specified
     Registry reg = LocateRegistry.getRegistry(host);
     RemoteDriver rdvr = (RemoteDriver) reg.lookup("simpledb");
     RemoteConnection rconn = rdvr.connect();
     return new SimpleConnection(rconn);
   } catch (Exception e) {
     throw new SQLException(e);
   }
 }
Exemplo n.º 6
0
 /**
  * ***************************************************************
  *
  * @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;
 }
 public RmiServer() throws RemoteException {
   try {
     address = (InetAddress.getLocalHost()).toString();
   } catch (Exception e) {
     System.out.println("can't get inet address.");
   }
   int port1 = 3232;
   System.out.println("this address=" + address + ",port=" + port1);
   try {
     registry1 = LocateRegistry.createRegistry(port1);
     registry1.rebind("rmiServer1", this);
   } catch (RemoteException e) {
     System.out.println("remote exception" + e);
   }
 }
Exemplo n.º 8
0
 public static void main(String args[]) {
   try {
     // new VINDecoderServer();
     VINDecoderImpl vd = new VINDecoderImpl();
     vd.setDB("/usr/local/vendor/bea/user_projects/matson/lib/jato_matson.jar");
     System.out.println("Decoding vin...");
     System.out.println(vd.decode("1D7HA18N32S709816", null));
     System.out.println("End Decoding vin...");
     System.out.println("Starting the rmiregistry on port 1099");
     Registry registry = LocateRegistry.createRegistry(1099);
     Naming.bind("VINDecoderService", vd);
     System.out.println("VINDecoderService bound....");
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 9
0
  /**
   * Returns the Registry on the given machine on port IRMI_Defs.REGISTRY_PORT, as a client would
   * require.
   *
   * @param host the IP address or host name of the remote machine.
   * @return The remote Registry or null if it could not be located.
   */
  @Override
  public Registry getRemoteRegistry(String host) {

    try {
      Registry registry = LocateRegistry.getRegistry(host, IRMI_Defs.REGISTRY_PORT);
      outputCmd.apply("RMIUtils.getRemoteRegistry: Success! Found Registry: " + registry);
      return registry;
    } catch (RemoteException e) {
      outputCmd.apply(
          "RMIUtils.getRemoteRegistry: Could not get registry at "
              + host
              + ":"
              + IRMI_Defs.REGISTRY_PORT
              + ". \n"
              + e);
      return null;
    }
  }
Exemplo n.º 10
0
  public static void main(String[] args) {
    try {
      String serverAddress = args[0];
      int port = Integer.parseInt(args[1]);
      String localAddress = args[2];

      /** create a httpServer */
      System.out.println("Starting HTTP server");
      HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);
      httpServer.createContext("/", new HttpFileHandler());
      httpServer.setExecutor(null);
      httpServer.start();

      System.out.println("Creating RMI Registry");
      Registry registry = LocateRegistry.createRegistry(1099);
      Reference reference =
          new javax.naming.Reference(
              "client.ExportObject", "client.ExportObject", "http://" + localAddress + "/");
      ReferenceWrapper referenceWrapper = new com.sun.jndi.rmi.registry.ReferenceWrapper(reference);
      registry.bind("Object", referenceWrapper);

      System.out.println("Connecting to server " + serverAddress + ":" + port);
      Socket socket = new Socket(serverAddress, port);
      System.out.println("Connected to server");
      String jndiAddress = "rmi://" + localAddress + ":1099/Object";

      org.springframework.transaction.jta.JtaTransactionManager object =
          new org.springframework.transaction.jta.JtaTransactionManager();
      object.setUserTransactionName(jndiAddress);

      System.out.println("Sending object to server...");
      ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
      objectOutputStream.writeObject(object);
      objectOutputStream.flush();
      /*
      while(true) {
      	Thread.sleep(1000);
      }
      */
    } catch (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[]) {

    /*
     * Create and install a security manager
     */
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new SecurityManager());
    }

    try {
      Registry registry = LocateRegistry.getRegistry(2002);
      Hello obj = (Hello) registry.lookup("Hello");
      String message = obj.sayHello();
      System.out.println(message);

    } catch (Exception e) {
      System.out.println("HelloClient exception: " + e.getMessage());
      e.printStackTrace();
    }
  }
Exemplo n.º 13
0
  /**
   * @param _port
   * @param id
   * @throws RemoteException
   * @throws UnknownHostException
   */
  public Chord(int _port, int id) throws RemoteException, UnknownHostException {
    finger = new Finger[(1 << M)]; // 1 << M = 2^(M)
    // TODO: set the fingers in the array to null
    i = id;
    port = _port;
    // TODO: determine the current IP of the machine

    predecessor = null;
    InetAddress ip = InetAddress.getLocalHost();
    successor = new Finger(ip.getHostAddress(), i, i);
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(
        new TimerTask() {
          @Override
          public void run() {
            try {
              stabilize();
            } catch (RemoteException | UnknownHostException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            fixFingers();
            checkPredecessor();
          }
        },
        500,
        500);
    try {
      // create the registry and bind the name and object.
      System.out.println("Starting RMI at port=" + port);
      registry = LocateRegistry.createRegistry(port);
      registry.rebind("Chord", this);
    } catch (RemoteException e) {
      throw e;
    }
  }