HpccClassLoader.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. package com.HPCCSystems;
  14. import java.net.*;
  15. import java.util.Hashtable;
  16. public class HpccClassLoader extends java.net.URLClassLoader
  17. {
  18. private long bytecode;
  19. private int bytecodeLen;
  20. private native Class defineClassForEmbed(int bytecodeLen, long bytecode, String name);
  21. private Hashtable<String, Class> classes = new Hashtable<>();
  22. private HpccClassLoader(java.net.URL [] urls, ClassLoader parent, int _bytecodeLen, long _bytecode, String dllname)
  23. {
  24. super(urls, parent);
  25. System.load(dllname);
  26. bytecodeLen = _bytecodeLen;
  27. bytecode = _bytecode;
  28. }
  29. public synchronized Class<?> findClass(String className) throws ClassNotFoundException
  30. {
  31. Class result = (Class) classes.get(className);
  32. if (result == null)
  33. {
  34. result = defineClassForEmbed(bytecodeLen, bytecode, className.replace(".","/"));
  35. classes.put(className, result);
  36. }
  37. return result;
  38. }
  39. public static HpccClassLoader newInstance(java.net.URL [] urls, ClassLoader parent, int _bytecodeLen, long _bytecode, String dllname)
  40. {
  41. return new HpccClassLoader(urls, parent, _bytecodeLen, _bytecode, dllname);
  42. }
  43. }