@Nullable
  static ClassLoader createPluginClassLoader(
      @NotNull File[] classPath,
      @NotNull ClassLoader[] parentLoaders,
      @NotNull IdeaPluginDescriptor pluginDescriptor) {

    if (pluginDescriptor.getUseIdeaClassLoader()) {
      try {
        final ClassLoader loader = PluginManagerCore.class.getClassLoader();
        final Method addUrlMethod = getAddUrlMethod(loader);

        for (File aClassPath : classPath) {
          final File file = aClassPath.getCanonicalFile();
          addUrlMethod.invoke(loader, file.toURI().toURL());
        }

        return loader;
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }

    PluginId pluginId = pluginDescriptor.getPluginId();
    File pluginRoot = pluginDescriptor.getPath();

    // if (classPath.length == 0) return null;
    if (isUnitTestMode()) return null;
    try {
      final List<URL> urls = new ArrayList<URL>(classPath.length);
      for (File aClassPath : classPath) {
        final File file =
            aClassPath
                .getCanonicalFile(); // it is critical not to have "." and ".." in classpath
                                     // elements
        urls.add(file.toURI().toURL());
      }
      return new PluginClassLoader(
          urls, parentLoaders, pluginId, pluginDescriptor.getVersion(), pluginRoot);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
Ejemplo n.º 2
0
 /**
  * Try to execute given method on given object. Handles invocation target exceptions. XXX nearly
  * duplicates tryMethod in JGEngine.
  *
  * @return null means method does not exist or returned null/void
  */
 static Object tryMethod(Object o, String name, Object[] args) {
   try {
     Method met = JREEngine.getMethod(o.getClass(), name, args);
     if (met == null) return null;
     return met.invoke(o, args);
   } catch (InvocationTargetException ex) {
     Throwable ex_t = ex.getTargetException();
     ex_t.printStackTrace();
     return null;
   } catch (IllegalAccessException ex) {
     System.err.println("Unexpected exception:");
     ex.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 3
0
 protected synchronized Message receiveMessage() throws IOException {
   if (messageBuffer.size() > 0) {
     Message m = (Message) messageBuffer.get(0);
     messageBuffer.remove(0);
     return m;
   }
   try {
     InetSocketAddress remoteAddress = (InetSocketAddress) channel.receive(receiveBuffer);
     if (remoteAddress != null) {
       int len = receiveBuffer.position();
       receiveBuffer.rewind();
       receiveBuffer.get(buf, 0, len);
       try {
         IP address = IP.fromInetAddress(remoteAddress.getAddress());
         int port = remoteAddress.getPort();
         extractor.appendData(buf, 0, len, new SocketDescriptor(address, port));
         receiveBuffer.clear();
         extractor.updateAvailableMessages();
         return extractor.nextMessage();
       } catch (EOFException exc) {
         exc.printStackTrace();
         System.err.println(buf.length + ", " + len);
       } catch (InvocationTargetException exc) {
         exc.printStackTrace();
       } catch (IllegalAccessException exc) {
         exc.printStackTrace();
       } catch (InstantiationException exc) {
         exc.printStackTrace();
       } catch (IllegalArgumentException e) {
         e.printStackTrace();
       } catch (InvalidCompressionMethodException e) {
         e.printStackTrace();
       }
     }
   } catch (ClosedChannelException exc) {
     if (isKeepAlive()) {
       throw exc;
     }
   }
   return null;
 }
    @Override
    public void run() {
      try {
        processTime = System.currentTimeMillis();
        myPack = (Pack) ois.readObject();
        functionName = myPack.getfunctionName();
        paramTypes = myPack.getparamTypes();
        paramValues = myPack.getparamValues();
        state = myPack.getstate();
        stateDType = myPack.getstateType();
        timestamps = myPack.getTimeStamps();

        if (functionName != null && functionName.length() > 0) {
          try {

            System.out.println("Trying to load and execute");
            Class cls = Class.forName(stateDType.getName());

            timestamps.add(processTime + ",server1");

            /*System.out.println(""+stateDType.getName());

            System.out.println("functionsName: " + functionName.toLowerCase());
            System.out.println("paramTypes: " + paramTypes.toString());*/

            Method method = cls.getDeclaredMethod(functionName, paramTypes);

            try {

              /** support for caching results */

              /** cache using the parameters as key of the result can be possible */
              // boolean processed = TreeManager.getInstance().exists(paramValues[0]);

              // System.out.println("param1:" + (int[]) paramValues[0]);
              // System.out.println("param1:" + paramValues[1]);
              // System.out.println("param1:" +  paramValues[2]);

              oos.flush();
              Object result = method.invoke(state, paramValues);
              ResultPack rp = new ResultPack(result, state);

              rp.setTimeStamps(timestamps);

              // System.out.println("Size in bytes: " + sizeInBytes(rp));
              oos.flush();
              oos.writeObject(rp);
              // System.out.println("Object wrote it");
              oos.flush();
              // System.out.println("Object executed and flushed: " + (System.currentTimeMillis() -
              // processTime));

              System.out.println("Object executed and flushed:");

              // System.out.println("Object executed and flushed: " + (System.currentTimeMillis() -
              // processTime));

            } catch (IllegalAccessException ex1) {
              returnnull(oos);
              System.out.println("Hubo problema 1: " + ex1.getMessage());
            } catch (InvocationTargetException ex2) {
              returnnull(oos);
              System.out.println("Hubo problema 2: " + ex2.getCause());
            } catch (Exception ex3) {
              ResultPack rp = new ResultPack(null, state);
              oos.writeObject(rp);
              oos.flush();
              System.out.println("Hubo problema 3" + ex3.getCause());
            }

          } catch (ClassNotFoundException ex) {
            returnnull(oos);
            System.out.println("Hubo problema 4");
          } catch (IllegalArgumentException ex) {
            returnnull(oos);
            System.out.println("Hubo problema 5");
          } catch (NoSuchMethodException ex) {
            returnnull(oos);
            System.out.println("Hubo problema 6");
          } catch (SecurityException ex) {
            returnnull(oos);
            System.out.println("Hubo problema 7");
          } finally {

            oos.close();
            ois.close();

            in.close();
            out.close();

            mysocket.close();

            oos = null;
            ois = null;

            in = null;
            out = null;
            mysocket = null;
          }
        } else {
          returnnull(oos);
        }
      } catch (IOException ex) {
        returnnull(oos);
        System.out.println("Hubo problema 8");
      } catch (ClassNotFoundException ex) {
        returnnull(oos);
        System.out.println("Hubo problema 9");
        ex.printStackTrace();
      } finally {
        makeconnection();
      }
    }