jclasses.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef LIBHDFS_JCLASSES_H
  19. #define LIBHDFS_JCLASSES_H
  20. #include <jni.h>
  21. /**
  22. * Encapsulates logic to cache jclass objects so they can re-used across
  23. * calls to FindClass. Creating jclass objects every time libhdfs has to
  24. * invoke a method can hurt performance. By cacheing jclass objects we avoid
  25. * this overhead.
  26. *
  27. * We use the term "cached" here loosely; jclasses are not truly cached,
  28. * instead they are created once during JVM load and are kept alive until the
  29. * process shutdowns. There is no eviction of jclass objects.
  30. *
  31. * @see https://www.ibm.com/developerworks/library/j-jni/index.html#notc
  32. */
  33. /**
  34. * Each enum value represents one jclass that is cached. Enum values should
  35. * be passed to getJclass or getName to get the jclass object or class name
  36. * represented by the enum value.
  37. */
  38. typedef enum {
  39. JC_CONFIGURATION,
  40. JC_PATH,
  41. JC_FILE_SYSTEM,
  42. JC_FS_STATUS,
  43. JC_FILE_UTIL,
  44. JC_BLOCK_LOCATION,
  45. JC_DFS_HEDGED_READ_METRICS,
  46. JC_DISTRIBUTED_FILE_SYSTEM,
  47. JC_FS_DATA_INPUT_STREAM,
  48. JC_FS_DATA_OUTPUT_STREAM,
  49. JC_FILE_STATUS,
  50. JC_FS_PERMISSION,
  51. JC_READ_STATISTICS,
  52. JC_HDFS_DATA_INPUT_STREAM,
  53. JC_FUTURE_DATA_IS_BUILDER,
  54. JC_DOMAIN_SOCKET,
  55. JC_URI,
  56. JC_BYTE_BUFFER,
  57. JC_ENUM_SET,
  58. JC_EXCEPTION_UTILS,
  59. JC_CFUTURE,
  60. // A special marker enum that counts the number of cached jclasses
  61. NUM_CACHED_CLASSES
  62. } CachedJavaClass;
  63. /**
  64. * Internally initializes all jclass objects listed in the CachedJavaClass
  65. * enum. This method is idempotent and thread-safe.
  66. */
  67. jthrowable initCachedClasses(JNIEnv* env);
  68. /**
  69. * Return the jclass object represented by the given CachedJavaClass
  70. */
  71. jclass getJclass(CachedJavaClass cachedJavaClass);
  72. /**
  73. * Return the class name represented by the given CachedJavaClass
  74. */
  75. const char *getClassName(CachedJavaClass cachedJavaClass);
  76. /* Some frequently used HDFS class names */
  77. #define HADOOP_CONF "org/apache/hadoop/conf/Configuration"
  78. #define HADOOP_PATH "org/apache/hadoop/fs/Path"
  79. #define HADOOP_LOCALFS "org/apache/hadoop/fs/LocalFileSystem"
  80. #define HADOOP_FS "org/apache/hadoop/fs/FileSystem"
  81. #define HADOOP_FSSTATUS "org/apache/hadoop/fs/FsStatus"
  82. #define HADOOP_FILEUTIL "org/apache/hadoop/fs/FileUtil"
  83. #define HADOOP_BLK_LOC "org/apache/hadoop/fs/BlockLocation"
  84. #define HADOOP_DFS_HRM "org/apache/hadoop/hdfs/DFSHedgedReadMetrics"
  85. #define HADOOP_DFS "org/apache/hadoop/hdfs/DistributedFileSystem"
  86. #define HADOOP_FSDISTRM "org/apache/hadoop/fs/FSDataInputStream"
  87. #define HADOOP_FSDOSTRM "org/apache/hadoop/fs/FSDataOutputStream"
  88. #define HADOOP_FILESTAT "org/apache/hadoop/fs/FileStatus"
  89. #define HADOOP_FSPERM "org/apache/hadoop/fs/permission/FsPermission"
  90. #define HADOOP_RSTAT "org/apache/hadoop/hdfs/ReadStatistics"
  91. #define HADOOP_HDISTRM "org/apache/hadoop/hdfs/client/HdfsDataInputStream"
  92. #define HADOOP_FDISB "org/apache/hadoop/fs/FutureDataInputStreamBuilder"
  93. #define HADOOP_FS_BLDR "org/apache/hadoop/fs/FSBuilder"
  94. #define HADOOP_RO "org/apache/hadoop/fs/ReadOption"
  95. #define HADOOP_DS "org/apache/hadoop/net/unix/DomainSocket"
  96. /* Some frequently used Java class names */
  97. #define JAVA_NET_ISA "java/net/InetSocketAddress"
  98. #define JAVA_NET_URI "java/net/URI"
  99. #define JAVA_BYTEBUFFER "java/nio/ByteBuffer"
  100. #define JAVA_STRING "java/lang/String"
  101. #define JAVA_ENUMSET "java/util/EnumSet"
  102. #define JAVA_CFUTURE "java/util/concurrent/CompletableFuture"
  103. #define JAVA_TIMEUNIT "java/util/concurrent/TimeUnit"
  104. #define JAVA_OBJECT "java/lang/Object"
  105. /* Some frequently used third-party class names */
  106. #define EXCEPTION_UTILS "org/apache/commons/lang3/exception/ExceptionUtils"
  107. #endif /*LIBHDFS_JCLASSES_H*/