Exemplo 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;
   }
 }
  /**
   * 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);
  }
 @Override
 public int replyToCoordinatingServer(int articleId, Article article, ConsistencyType type)
     throws RemoteException {
   final String method = CLASS_NAME + ".replyToCoordinatingServer()";
   LogUtil.log(
       method,
       "Server:"
           + Server.getServerId()
           + " "
           + "Replying to: "
           + articleId
           + " article : "
           + article
           + " in Coordinating server");
   try {
     TimeUtil.delay();
     return coordServerImpl.replyToCoordinatingServer(articleId, article, type);
   } catch (MalformedURLException e) {
     LogUtil.log(method, "Got exception : " + e.getMessage());
     throw new RemoteException("Got exception in connection to other servers.", e);
   } catch (InvalidArticleException e) {
     LogUtil.log(method, "Got exception : " + e.getMessage());
     throw new RemoteException("Got exception in connection to other servers.", e);
   } catch (NotBoundException e) {
     LogUtil.log(method, "Got exception : " + e.getMessage());
     throw new RemoteException("Got exception in connection to other servers.", e);
   }
 }
Exemplo n.º 4
0
  public JParSolverImpl(String host, int port) throws RemoteException {
    if (System.getSecurityManager() == null) {
      System.setSecurityManager(new RMISecurityManager());
    }

    String serverName = "JParServer";
    try {
      Registry registry = LocateRegistry.getRegistry(host, port);
      this.server = (JParServer) registry.lookup(serverName);
    } catch (AccessException e) {
      System.err.println("Solver: Java RMI AccessException: " + e.getMessage());
      return;
    } catch (RemoteException e) {
      System.err.println("Solver: Java RMI Exception: " + e.getMessage());
      return;
    } catch (NotBoundException e) {
      System.err.println("Solver: " + serverName + " lookup failed:" + e.getMessage());
      return;
    } catch (Exception e) {
      System.err.println("Solver: JParSolver Constructor:" + e.getMessage());
      e.printStackTrace();
      return;
    }

    this.taskSynchObj = new Object();
    this.pendingJob = JOB_WAITING_FOR;

    if (this.register()) {
      initialized = true;
    }
  }
Exemplo n.º 5
0
  /** Stop. */
  public void stop() {
    this.lookupTask.stop();

    if (this.stub != null) {
      try {
        this.reg.unbind(this.bindingName);

        this.dist.unexportClients();

        this.dist.unexportServer();

        UnicastRemoteObject.unexportObject(this.dist, true);
      } catch (RemoteException rex) {
        logger.warning(rex.getMessage());
      } catch (NotBoundException nbex) {
        logger.warning(nbex.getMessage());
      }
    }

    try {
      UnicastRemoteObject.unexportObject(this.reg, true);
    } catch (NoSuchObjectException ex) {
      ex.printStackTrace();
    }
  }
  /** Instanciação e Inicialização do ZonaDesembarqueRegister */
  public ZonaDesembarqueRegister() {
    super();
    canEnd = false;

    try {
      registry = LocateRegistry.getRegistry(registryHostname, registryPort);
      log = (LoggingInterface) registry.lookup("Logging");
    } catch (RemoteException e) {
      GenericIO.writelnString("Excepção na localização do Logging: " + e.getMessage() + "!");
      e.printStackTrace();
      System.exit(1);
    } catch (NotBoundException e) {
      GenericIO.writelnString("O Logging não está registado: " + e.getMessage() + "!");
      e.printStackTrace();
      System.exit(1);
    }

    desembarque = new ZonaDesembarque(log, this);
    try {
      desembarqueInterface =
          (ZonaDesembarqueInterface)
              UnicastRemoteObject.exportObject(
                  desembarque, portNumber[Globals.MON_ZONA_DESEMBARQUE]);
    } catch (RemoteException e) {
      System.exit(1);
    }
  }
Exemplo n.º 7
0
 private void checkSslConfig() throws IOException {
   // Get the reference to the RMI Registry and lookup RMIServer stub
   Registry registry;
   try {
     registry = LocateRegistry.getRegistry(this.hostName, this.port, sslRMIClientSocketFactory);
     try {
       this.stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
   } catch (IOException e) {
     registry = LocateRegistry.getRegistry(this.hostName, this.port);
     try {
       this.stub = (RMIServer) registry.lookup("jmxrmi");
     } catch (NotBoundException nbe) {
       throw (IOException) new IOException(nbe.getMessage()).initCause(nbe);
     }
   }
 }
Exemplo n.º 8
0
 private void initBL() {
   try {
     bankAccountBLService = BLFactory.getBankAccountBLService();
   } catch (MalformedURLException e) {
     System.out.println(e.getMessage());
   } catch (RemoteException e) {
     new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE);
   } catch (NotBoundException e) {
     System.out.println(e.getMessage());
   }
 }
 @Override
 public List<Article> readFromCoordinatingServer(ConsistencyType type) throws RemoteException {
   final String method = CLASS_NAME + ".readFromCoordinatingServer()";
   LogUtil.log(
       method, "Server:" + Server.getServerId() + " " + "Reading from Coordinating server");
   try {
     TimeUtil.delay();
     return coordServerImpl.readFromCoordinatingServer(type);
   } catch (MalformedURLException e) {
     LogUtil.log(method, "Got exception : " + e.getMessage());
     throw new RemoteException("Got exception in connection to other servers.", e);
   } catch (NotBoundException e) {
     LogUtil.log(method, "Got exception : " + e.getMessage());
     throw new RemoteException("Got exception in connection to other servers.", e);
   }
 }
  /** Ciclo de vida do ZonaDesembarqueRegister */
  public synchronized void run() {
    String entry = "ZonaDesembarque";
    String nameEntryBase = "RegisterHandler";
    Register register = null;

    try {
      register = (Register) registry.lookup(nameEntryBase);
    } catch (RemoteException e) {
      GenericIO.writelnString("RegisterRemoteObject lookup exception: " + e.getMessage());
      e.printStackTrace();
      System.exit(1);
    } catch (NotBoundException e) {
      GenericIO.writelnString("RegisterRemoteObject not bound exception: " + e.getMessage());
      e.printStackTrace();
      System.exit(1);
    }

    try {
      register.bind(entry, desembarqueInterface);
    } catch (RemoteException e) {
      System.exit(1);
    } catch (AlreadyBoundException e) {
      System.exit(1);
    }

    GenericIO.writelnString("O serviço ZonaDesembarque foi estabelecido!");
    GenericIO.writelnString("O servidor esta em escuta.");

    try {
      while (!canEnd) {
        wait();
      }
    } catch (InterruptedException ex) {

    }
    try {
      register.unbind(entry);
    } catch (RemoteException ex) {
      System.exit(1);
    } catch (NotBoundException ex) {
      System.exit(1);
    }
    try {
      UnicastRemoteObject.unexportObject(desembarque, false);
    } catch (NoSuchObjectException ex) {
    }
  }
Exemplo n.º 11
0
  @Override
  public void inicio() throws GenericException {
    System.out.println("Servidor->" + servidor);
    // PEGO O SERVIDOR
    String nomeServidorJogo;
    try {
      nomeServidorJogo = ClientSession.getSession().getServerPrincipal().getServidor(servidor);
      ClientSession.getSession().setNomeServidor(nomeServidorJogo);
      IServidorRmi servidorJogo =
          (IServidorRmi) ClientSession.getSession().getRServidor().lookup("IServidorRmi");
      ClientSession.getSession().setServidor(servidorJogo);
      // PEGO A MINHA REFERENCIA
      // TODO ...........
      String logado =
          ClientSession.getSession().getServidorJogo().login(nomeServidorJogo, email, senha, 0);
      ClientSession.getSession().setJogador(logado);

      // EXPORTO O MEU OBJETO REMOTO
      // prepara o objeto remoto para registro
      UnicastRemoteObject.exportObject(frameChat, 0);

      // registra o(s) objeto(s) remoto(s)
      try {
        ClientSession.getSession().getRCliente().bind("JWarServerRmi", frameChat);
      } catch (AlreadyBoundException e) {
      }

      // PEGO A REFERENCIA PRO MEU CHAT
      String nomeChat = servidorJogo.connect(nomeServidorJogo, logado, frameChat);
      ClientSession.getSession().setChatName(nomeChat);
      IChatRmi chat = (IChatRmi) ClientSession.getSession().getRServidor().lookup("IChatRmi");
      ClientSession.getSession().setChat(chat);

    } catch (RemoteException e) {
      e.printStackTrace();
      throw new GenericException(e.getMessage(), RemoteException.class);

    } catch (NotBoundException e) {
      e.printStackTrace();
      throw new GenericException(e.getMessage(), NotBoundException.class);
    } catch (LoginException e) {
      e.printStackTrace();
      throw new GenericException(e.getMessage(), LoginException.class);
    }
  }