This is an automated email from the ASF dual-hosted git repository.
hepin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 391b71a3d0 chore: Rewrite ClassContext with scala (#2260)
391b71a3d0 is described below
commit 391b71a3d09370bde890dc80404f4aed04777804
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Mon Sep 22 17:16:17 2025 +0800
chore: Rewrite ClassContext with scala (#2260)
---
.../pekko/actor/typed/internal/LoggerClass.scala | 13 +++++--
.../java/org/apache/pekko/util/ClassContext.java | 41 ----------------------
2 files changed, 11 insertions(+), 43 deletions(-)
diff --git
a/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
b/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
index 555c738550..a47ba35479 100644
---
a/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
+++
b/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala
@@ -17,7 +17,7 @@ import scala.util.control.NonFatal
import org.apache.pekko
import pekko.annotation.InternalApi
-import pekko.util.{ ClassContext, OptionVal }
+import pekko.util.OptionVal
/**
* INTERNAL API
@@ -26,6 +26,15 @@ import pekko.util.{ ClassContext, OptionVal }
private[pekko] object LoggerClass {
private val defaultPrefixesToSkip = List("scala.runtime",
"org.apache.pekko.actor.typed.internal")
+ private val OPTIONS: java.util.Set[StackWalker.Option] = java.util.Set.of(
+ StackWalker.Option.RETAIN_CLASS_REFERENCE,
StackWalker.Option.SHOW_HIDDEN_FRAMES)
+ private val CLASS_STACK_WALKER: java.util.function.Function[
+ java.util.stream.Stream[StackWalker.StackFrame], Array[Class[_]]] =
+ (frames: java.util.stream.Stream[StackWalker.StackFrame]) =>
+ frames.map(frame => frame.getDeclaringClass)
+ .toArray[Class[_]]((size: Int) => new Array[Class[_]](size))
+
+ private def getClassStack: Array[Class[_]] =
StackWalker.getInstance(OPTIONS).walk(CLASS_STACK_WALKER)
/**
* Try to extract a logger class from the call stack, if not possible the
provided default is used
@@ -43,7 +52,7 @@ private[pekko] object LoggerClass {
loop(additionalPrefixesToSkip ::: defaultPrefixesToSkip)
}
- val trace = ClassContext.getClassStack
+ val trace = getClassStack
var suitableClass: OptionVal[Class[_]] = OptionVal.None
var idx = 1 // skip this method/class and right away
while (suitableClass.isEmpty && idx < trace.length) {
diff --git a/actor/src/main/java/org/apache/pekko/util/ClassContext.java
b/actor/src/main/java/org/apache/pekko/util/ClassContext.java
deleted file mode 100644
index d47d638ae5..0000000000
--- a/actor/src/main/java/org/apache/pekko/util/ClassContext.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.pekko.util;
-
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Stream;
-import org.apache.pekko.annotation.InternalApi;
-
-/** INTERNAL API */
-@InternalApi
-public final class ClassContext {
- private ClassContext() {
- throw new UnsupportedOperationException("Cannot instantiate utility
class");
- }
-
- private static final Set<StackWalker.Option> OPTIONS =
- Set.of(StackWalker.Option.RETAIN_CLASS_REFERENCE,
StackWalker.Option.SHOW_HIDDEN_FRAMES);
-
- private static final Function<Stream<StackWalker.StackFrame>, Class<?>[]>
CLASS_STACK_WALKER =
- frames ->
frames.map(StackWalker.StackFrame::getDeclaringClass).toArray(Class<?>[]::new);
-
- public static Class<?>[] getClassStack() {
- return StackWalker.getInstance(OPTIONS).walk(CLASS_STACK_WALKER);
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]