Пример #1
0
 public void init(List serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) {
   System.setProperty("java.io.tmpdir", serverConfig.getCachedir());
   try {
     this.serviceList = serviceList;
     this.serverConfig = serverConfig;
     this.mbeanServer = mbeanServer;
     fsManager.init();
   } catch (Exception e) {
     log.error("Unable to initialie file system: " + fsManager, e);
   }
   try {
     registry = LocateRegistry.createRegistry(Integer.parseInt(serverConfig.getRmiregistryport()));
     ic = new InitialContext();
     Context subctx = null;
     try {
       subctx = (Context) ic.lookup("java:");
     } catch (Exception ex) {
       log.error("initializing the java context", ex);
       // ex.printStackTrace();
     }
     if (subctx == null) {
       ic.createSubcontext("java:");
     }
     remoteBindingInterface = new RemoteBindingObject(ic);
     Object jndilookupobj =
         UnicastRemoteObject.exportObject(
             remoteBindingInterface, Integer.parseInt(serverConfig.getRmiregistryport()));
     registry.rebind("RemoteBindingObject", (Remote) jndilookupobj);
   } catch (Exception ex) {
     log.error("error in registring to the remote binding object", ex);
     // e1.printStackTrace();
   }
   log.info("initialized");
 }
Пример #2
0
  public void deploy(URL url, boolean master, ClassLoader cL, String remoteHost) {
    try {
      FileObject filetoScan = fsManager.resolveFile("jar:" + url.toString() + "!/");
      HashSet<Class<?>>[] classes = new HashSet[] {new HashSet()};

      VFSClassLoader jarCL;

      if (cL != null) {
        jarCL = new VFSClassLoader(new FileObject[] {filetoScan}, fsManager, cL);
      } else {
        jarCL =
            new VFSClassLoader(
                new FileObject[] {filetoScan},
                fsManager,
                Thread.currentThread().getContextClassLoader());
      }
      Class[] annot = new Class[] {DeployRMI.class};
      scanJar(filetoScan, classes, annot, jarCL);
      for (Class<?> rmiClass : classes[0]) {
        DeployRMI rmiAnnot = rmiClass.getAnnotation(DeployRMI.class);
        if (master) {
          rmiProxyHandler = new RMIProxyHandler(rmiAnnot.jndiBinding(), remoteObjects);
          rmiproxy =
              Proxy.newProxyInstance(
                  rmiClass.getClassLoader(), rmiClass.getInterfaces(), rmiProxyHandler);
          remoteobj =
              UnicastRemoteObject.exportObject(
                  (Remote) rmiproxy, Integer.parseInt(serverConfig.getRmiregistryport()));
          rmiproxyObjs.put(rmiAnnot.jndiBinding(), rmiproxy);
          rmiproxyHandler.put(rmiAnnot.jndiBinding(), rmiProxyHandler);
          remoteProxyObjs.put(rmiAnnot.jndiBinding(), remoteobj);
          ic.bind("java:/" + rmiAnnot.jndiBinding(), remoteobj);
          registry.bind(rmiAnnot.jndiBinding(), (Remote) remoteobj);
          cLMap.put(rmiAnnot.jndiBinding(), jarCL);
        } else {
          Remote remoteObj = (Remote) rmiClass.newInstance();
          remoteSlaveObjs.put(rmiAnnot.jndiBinding(), remoteObj);
          Object remoteobj =
              UnicastRemoteObject.exportObject(
                  (Remote) remoteObj, Integer.parseInt(serverConfig.getRmiregistryport()));
          ic.bind("java:/" + rmiAnnot.jndiBinding(), remoteobj);
          registry.bind(rmiAnnot.jndiBinding(), (Remote) remoteobj);
          if (remoteObjects.get(rmiAnnot.jndiBinding()) != null) {
            ConcurrentMap<String, Remote> remoteObjs = remoteObjects.get(rmiAnnot.jndiBinding());
            remoteObjs.put(remoteHost, (Remote) remoteobj);
          } else {
            ConcurrentHashMap<String, Remote> remoteObjs = new ConcurrentHashMap<String, Remote>();
            remoteObjs.put(remoteHost, (Remote) remoteobj);
            remoteObjects.put(rmiAnnot.jndiBinding(), remoteObjs);
          }
        }
      }
    } catch (Exception e) {
      log.error("unable to deploy the package " + url, e);
    }
  }