/**
  * (non-Javadoc)
  *
  * @see
  *     org.objectweb.proactive.extensions.webservices.WebServicesFactory#getWebServices(java.lang.String)
  */
 public final WebServices getWebServices(String url) throws WebServicesException {
   URI uriKey = null;
   try {
     URI uri = new URI(url);
     uriKey =
         URIBuilder.buildURI(uri.getHost(), null, uri.toURL().getProtocol(), uri.getPort(), true);
   } catch (Exception e) {
     throw new WebServicesException("An exception occured while reading the web service url", e);
   }
   WebServices ws = activatedWebServices.get(uriKey);
   if (ws != null) {
     logger.debug("Getting the WebServices instance from the hashmap");
     logger.debug(
         "the new WebServices instance has been put into the HashMap using the uri key: "
             + uriKey.toString());
     return ws;
   } else {
     logger.debug("Creating a new WebServices instance");
     ws = newWebServices(url);
     activatedWebServices.put(uriKey, ws);
     logger.debug(
         "The new WebServices instance has been put into the HashMap using the uri key: "
             + uriKey.toString());
     return ws;
   }
 }
  public InternalRemoteRemoteObject createRemoteObject(
      RemoteObject<?> remoteObject, String name, boolean rebind) throws ProActiveException {
    URI uri =
        URIBuilder.buildURI(ProActiveInet.getInstance().getHostname(), name, this.getProtocolId());
    // register the object on the register
    InternalRemoteRemoteObject irro = new InternalRemoteRemoteObjectImpl(remoteObject, uri);
    RemoteRemoteObject rmo = register(irro, uri, rebind);
    irro.setRemoteRemoteObject(rmo);

    return irro;
  }
  /* (non-Javadoc)
   * @see org.objectweb.proactive.core.remoteobject.RemoteObjectFactory#register(org.objectweb.proactive.core.remoteobject.RemoteObject, java.net.URI, boolean)
   */
  public RemoteRemoteObject register(
      InternalRemoteRemoteObject target, URI url, boolean replacePreviousBinding)
      throws ProActiveException {
    RmiRemoteObject rro = null;
    try {
      Constructor<? extends RmiRemoteObject> c =
          clRemoteObject.getConstructor(InternalRemoteRemoteObject.class);
      rro = c.newInstance(target);
    } catch (Exception e) {
      throw new ProActiveException(e);
    }

    Registry reg = null;
    try {
      reg = getRegistry(url);
    } catch (Exception e) {
      LOGGER_RO.debug("creating new rmiregistry on port : " + url.getPort());
      try {
        LocateRegistry.createRegistry(URIBuilder.getPortNumber(url));
      } catch (RemoteException e1) {
        LOGGER_RO.warn("damn cannot start a rmiregistry on port " + url.getPort());
        throw new ProActiveException(e1);
      }
    }

    try {
      if (replacePreviousBinding) {
        reg.rebind(URIBuilder.getNameFromURI(url), rro);
      } else {
        reg.bind(URIBuilder.getNameFromURI(url), rro);
      }
      LOGGER_RO.debug(" successfully bound in registry at " + url);
    } catch (java.rmi.AlreadyBoundException e) {
      LOGGER_RO.warn(url + " already bound in registry", e);
      throw new AlreadyBoundException(e);
    } catch (RemoteException e) {
      LOGGER_RO.debug(" cannot bind object at " + url);
      throw new ProActiveException(e);
    }
    return rro;
  }
 /* (non-Javadoc)
  * @see org.objectweb.proactive.core.remoteobject.RemoteObjectFactory#unregister(java.net.URI)
  */
 public void unregister(URI url) throws ProActiveException {
   try {
     Registry reg = getRegistry(url);
     reg.unbind(URIBuilder.getNameFromURI(url));
     LOGGER_RO.debug(url + " unbound in registry");
   } catch (IOException e) {
     // No need to throw an exception if an object is already unregistered
     LOGGER_RO.warn(url + " is not bound in the registry ");
   } catch (Exception e) {
     throw new ProActiveException(e);
   }
 }
  /* (non-Javadoc)
   * @see org.objectweb.proactive.core.remoteobject.RemoteObjectFactory#list(java.net.URI)
   */
  public URI[] list(URI url) throws ProActiveException {
    try {
      Registry registry = getRegistry(url);
      String[] names = registry.list();

      if (names != null) {
        URI[] uris = new URI[names.length];
        for (int i = 0; i < names.length; i++) {
          uris[i] =
              URIBuilder.buildURI(
                  URIBuilder.getHostNameFromUrl(url),
                  names[i],
                  protocolIdentifier,
                  URIBuilder.getPortNumber(url));
        }
        return uris;
      }
    } catch (Exception e) {
      throw new ProActiveException(e);
    }
    return null;
  }
 private void performTask(String information, String value) {
   if (information.equals(runtimeHostForLookup)) {
     this.lookupHost = value;
   } else {
     this.portForLookup = new Integer(value).intValue();
   }
   runtimeProperties.remove(information);
   if (!isWaitingForProperties()) {
     this.urlForLookup =
         URIBuilder.buildURI(this.lookupHost, this.name, this.lookupProtocol, this.portForLookup)
             .toString();
     activate();
   }
 }
  /* (non-Javadoc)
   * @see org.objectweb.proactive.core.remoteobject.RemoteObjectFactory#lookup(java.net.URI)
   */
  public <T> RemoteObject<T> lookup(URI uri) throws ProActiveException {
    Object o = null;

    URI modifiedURI = uri;
    if (uri.getPort() == -1) {
      LOGGER_RO.debug("No port specified, using the default one");
      modifiedURI =
          URIBuilder.buildURI(
              URIBuilder.getHostNameFromUrl(uri),
              URIBuilder.getNameFromURI(uri),
              this.protocolIdentifier);
      modifiedURI = RemoteObjectHelper.expandURI(modifiedURI);
    }

    // Try if URL is the address of a RmiRemoteBody
    try {
      Registry reg = getRegistry(modifiedURI);
      o = reg.lookup(URIBuilder.getNameFromURI(modifiedURI));
      LOGGER_RO.debug(modifiedURI.toString() + " looked up successfully");
    } catch (java.rmi.NotBoundException e) {
      // there are one rmiregistry on target computer but nothing bound to this url is not bound
      throw new ProActiveException(
          "The url " + modifiedURI + " is not bound to any known object", e);
    } catch (RemoteException e) {
      throw new ProActiveException("Registry could not be contacted, " + modifiedURI, e);
    }

    if (o instanceof RmiRemoteObject) {
      return new RemoteObjectAdapter((RmiRemoteObject) o);
    }

    throw new ProActiveException(
        "The given url does exist but doesn't point to a remote object  url="
            + modifiedURI
            + " class found is "
            + o.getClass().getName());
  }
 /** @see org.objectweb.proactive.core.descriptor.data.VirtualNodeInternal#activate() */
 public void activate() {
   if (!isActivated) {
     if (isWaitingForProperties()) {
       return;
     }
     try {
       this.urlForLookup =
           URIBuilder.buildURI(this.lookupHost, this.name, this.lookupProtocol, this.portForLookup)
               .toString();
       //		this.remoteProActiveRuntime = RuntimeFactory.getRuntime(urlForLookup,lookupProtocol);
       //		this.virtualNode = remoteProActiveRuntime.getVirtualNode(this.name);
       this.virtualNode = PADeployment.lookupVirtualNode(urlForLookup).getVirtualNodeInternal();
       isActivated = true;
     } catch (ProActiveException e) {
       e.printStackTrace();
       throw new ProActiveRuntimeException(e);
     }
   } else {
     vnLogger.debug("VirtualNode " + this.name + " already activated");
   }
 }
 // -- PRIVATE METHODS -----------------------------------------------
 //
 private static String getLocalHost() {
   return URIBuilder.getHostNameorIP(ProActiveInet.getInstance().getInetAddress());
 }