我正在尝试用java编写一个脉冲星客户端,但是我在记录器(Slf4j)中出现了一个错误。我认为这是因为我的PropertyConfigurator制作不好,但是即使我使用defaultConfigurator,也会得到同样长的错误.当我试图让我的PulsarClient变成这样的时候,它就坏了:
this.client = PulsarClient.builder()
.serviceUrl(config.get("target"))
.authentication(AuthenticationFactory.token(token))
.build();我所犯的错误:
main DEBUG logging.InternalLoggerFactory - Using SLF4J as the default logging framework
main DEBUG internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
main DEBUG internal.PlatformDependent0 - Java version: 11
main DEBUG internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
main DEBUG internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
main DEBUG internal.PlatformDependent0 - java.nio.Buffer.address: available
main DEBUG internal.PlatformDependent0 - direct buffer constructor: unavailable
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at org.apache.pulsar.shade.io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:233)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:227)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:247)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.<clinit>(Native.java:69)
at org.apache.pulsar.shade.io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:39)
at org.apache.pulsar.common.util.netty.EventLoopUtil.newEventLoopGroup(EventLoopUtil.java:46)
at org.apache.pulsar.client.impl.PulsarClientImpl.getEventLoopGroup(PulsarClientImpl.java:743)
at org.apache.pulsar.client.impl.PulsarClientImpl.<init>(PulsarClientImpl.java:129)
at org.apache.pulsar.client.impl.ClientBuilderImpl.build(ClientBuilderImpl.java:64)
at demo.demo_user.main(demo_user.java:34)
main DEBUG internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
main DEBUG internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @33cb5951
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Method.invoke(Method.java:558)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:347)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:338)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:247)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.<clinit>(Native.java:69)
at org.apache.pulsar.shade.io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:39)
at org.apache.pulsar.common.util.netty.EventLoopUtil.newEventLoopGroup(EventLoopUtil.java:46)
at org.apache.pulsar.client.impl.PulsarClientImpl.getEventLoopGroup(PulsarClientImpl.java:743)
at org.apache.pulsar.client.impl.PulsarClientImpl.<init>(PulsarClientImpl.java:129)
at org.apache.pulsar.client.impl.ClientBuilderImpl.build(ClientBuilderImpl.java:64)
at demo.demo_user.main(demo_user.java:34)
main DEBUG internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): unavailable
main DEBUG internal.PlatformDependent - sun.misc.Unsafe: available
main DEBUG internal.PlatformDependent - maxDirectMemory: 4148166656 bytes (maybe)
main DEBUG internal.PlatformDependent - -Dio.netty.tmpdir: /tmp (java.io.tmpdir)
main DEBUG internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model)
main DEBUG internal.PlatformDependent - -Dio.netty.maxDirectMemory: -1 bytes
main DEBUG internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1
main DEBUG internal.CleanerJava9 - java.nio.ByteBuffer.cleaner(): available
main DEBUG internal.PlatformDependent - -Dio.netty.noPreferDirect: false
main DEBUG internal.NativeLibraryLoader - -Dio.netty.native.workdir: /tmp (io.netty.tmpdir)
main DEBUG internal.NativeLibraryLoader - -Dio.netty.native.deleteLibAfterLoading: true
main DEBUG internal.NativeLibraryLoader - -Dio.netty.native.tryPatchShadedId: true
main DEBUG internal.NativeLibraryLoader - Unable to load the library 'org_apache_pulsar_shade_netty_transport_native_epoll_x86_64', trying other loading mechanism.
java.lang.UnsatisfiedLinkError: no org_apache_pulsar_shade_netty_transport_native_epoll_x86_64 in java.library.path: [/usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2673)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
at java.base/java.lang.System.loadLibrary(System.java:1873)
at org.apache.pulsar.shade.io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.pulsar.shade.io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:371)(等等)我在pom.xml中有很好的依赖关系,但我不明白客户端初始化时到底是什么破坏了.我的log4j.properties是一个基本的
log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%t %-5p %c{2} - %m%n 所以我想问是否有人知道这是怎么回事?我认为这可能是一个连接错误,但我不知道如何解决这个问题。提前谢谢你。
发布于 2022-09-24 21:04:35
经进一步调查,这些似乎是从脉冲星客户端启动时的调试级输出。
例如,带有前面消息的第一个堆栈跟踪
main DEBUG internal.PlatformDependent0 - direct buffer constructor: unavailable
java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at org.apache.pulsar.shade.io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:233)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:227)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:289)
at org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:247)
at org.apache.pulsar.shade.io.netty.channel.epoll.Native.<clinit>(Native.java:69)
at org.apache.pulsar.shade.io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:39)
at org.apache.pulsar.common.util.netty.EventLoopUtil.newEventLoopGroup(EventLoopUtil.java:46)
at org.apache.pulsar.client.impl.PulsarClientImpl.getEventLoopGroup(PulsarClientImpl.java:743)
at org.apache.pulsar.client.impl.PulsarClientImpl.<init>(PulsarClientImpl.java:129)
at org.apache.pulsar.client.impl.ClientBuilderImpl.build(ClientBuilderImpl.java:64)
at demo.demo_user.main(demo_user.java:34) if (maybeDirectBufferConstructor instanceof Constructor<?>) {
address = UNSAFE.allocateMemory(1);
// try to use the constructor now
try {
((Constructor<?>) maybeDirectBufferConstructor).newInstance(address, 1);
directBufferConstructor = (Constructor<?>) maybeDirectBufferConstructor;
logger.debug("direct buffer constructor: available");
} catch (InstantiationException e) {
directBufferConstructor = null;
} catch (IllegalAccessException e) {
directBufferConstructor = null;
} catch (InvocationTargetException e) {
directBufferConstructor = null;
}
} else {
logger.debug(
"direct buffer constructor: unavailable",
(Throwable) maybeDirectBufferConstructor);
directBufferConstructor = null;
}下面的行也是从这个类(io.netty.util.internal.PlatformDependent0)的初始化中输出的调试级别。
所有这些输出都来自奈蒂,一个Apache内部使用的库。
Netty正在测试使用过的JVM的各种特性(该特性是否可用),并相应地配置自己,使其正常工作,并具有最佳的性能。
那Reflective setAccessible(true) disabled是什么意思?
这意味着Netty试图调用java.lang.reflect.Constructor.setAccessible() (在本例中是java.nio.DirectByteBuffer的构造函数),而JVM不允许这个操作。
这最终可能意味着Netty无法在其某些操作中使用DirectByteBuffer。但是,由于这是一个已知的可能性,它将使用其他一些方法来操作,因此不需要担心。
(如果你不信任我,那么你仍然可以深入研究Apache和Netty的内部结构。但是,即使在最近的Java版本中,这两个项目也得到了积极的支持,因此,您可能应该信任这些项目的维护人员,他们会尽一切努力让它们正常工作。)
如果您不想看到这个调试输出,那么有几个选项:
log4j.rootLogger=info, stdoutlog4j.logger.org.apache.pulsar=info添加到log4.属性PlatformDependent0的调试级别输出:
将log4j.logger.org.apache.pulsar.shade.io.netty.util.internal.PlatformDependent0=info添加到log4.属性https://stackoverflow.com/questions/73839555
复制相似问题