Ejemplo n.º 1
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;
   }
 }
Ejemplo n.º 2
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 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;
  }
Ejemplo n.º 4
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;
    }
  }