You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2022/07/01 16:40:08 UTC

[activemq-artemis-native] branch main created (now fa2cdbd)

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git


      at fa2cdbd  ARTEMIS-3882 Removing Logger references and its dependencies

This branch includes the following new commits:

     new fa2cdbd  ARTEMIS-3882 Removing Logger references and its dependencies

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[activemq-artemis-native] 01/01: ARTEMIS-3882 Removing Logger references and its dependencies

Posted by cl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git

commit fa2cdbd8e9d1924915feeaae2649d0ce45fe634f
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Mon May 23 16:15:44 2022 +0100

    ARTEMIS-3882 Removing Logger references and its dependencies
    
    Using simple logging with a possibility of a callback
    Using javac -h instead of javah
    Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks
    Incrementing native version to avoid missuse
    
    authored by Clebert Suconic and Robbie Gemmel
---
 pom.xml                                            | 53 ++----------------
 src/main/c/CMakeLists.txt                          |  2 +-
 ...activemq_artemis_nativo_jlibaio_LibaioContext.h |  2 +-
 .../artemis/nativo/jlibaio/LibaioContext.java      | 17 +++---
 .../artemis/nativo/jlibaio/LibaioFile.java         |  2 +-
 .../artemis/nativo/jlibaio/LoggerCallback.java     | 35 ++++++++++++
 .../artemis/nativo/jlibaio/NativeLogger.java       | 63 ++++++++++++----------
 .../artemis/nativo/jlibaio/SystemCallback.java     | 50 +++++++++++++++++
 .../artemis/nativo/jlibaio/test/LibaioTest.java    | 19 +++++--
 9 files changed, 147 insertions(+), 96 deletions(-)

diff --git a/pom.xml b/pom.xml
index bad069e..4d4a6de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -33,8 +33,8 @@
     <url />
 
     <properties>
-        <jboss.logging.version>3.3.1.Final</jboss.logging.version>
-        <jb.logmanager.version>2.0.3.Final</jb.logmanager.version>
+        <slf4j.version>1.7.36</slf4j.version>
+        <log4j.version>2.17.2</log4j.version>
 
         <version.org.jacoco>0.8.6</version.org.jacoco>
         <version.org.jacoco.plugin>0.8.6</version.org.jacoco.plugin>
@@ -50,8 +50,8 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 
         <!-- See also maven.compiler.release in the java9on profile -->
-        <maven.compiler.source>1.8</maven.compiler.source>
-        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
 
         <activemq-surefire-argline>
             -Dtest.stress.time=${test.stress.time} -Djava.library.path="${activemq.basedir}/target/lib/linux-${os.arch}"
@@ -88,7 +88,6 @@
     </issueManagement>
 
     <dependencies>
-        <!-- ## Test Dependencies -->
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
@@ -108,37 +107,6 @@
           <version>${version.org.jacoco}</version>
            <scope>test</scope>
        </dependency>
-        <!-- ### Build Time Dependencies ### -->
-        <!-- This is a build dependency of this project, but is not needed at compile or runtime by other
-        projects that depend on this project. This should be in the compiler plugin but can't because of a bug,
-        see https://issues.apache.org/jira/browse/MCOMPILER-203-->
-        <dependency>
-            <groupId>org.jboss.logging</groupId>
-            <artifactId>jboss-logging-processor</artifactId>
-            <version>2.1.0.Final</version>
-            <optional>true</optional>
-            <!-- License: LGPL-->
-        </dependency>
-        <dependency>
-            <groupId>org.jboss.logging</groupId>
-            <artifactId>jboss-logging-annotations</artifactId>
-            <version>2.1.0.Final</version>
-            <scope>provided</scope>
-            <optional>true</optional>
-            <!-- License: Apache 2.0-->
-        </dependency>
-        <dependency>
-            <groupId>org.jboss.logging</groupId>
-            <artifactId>jboss-logging</artifactId>
-            <version>${jboss.logging.version}</version>
-            <!-- License: Apache 2.0 -->
-        </dependency>
-        <dependency>
-            <groupId>org.jboss.logmanager</groupId>
-            <artifactId>jboss-logmanager</artifactId>
-            <version>${jb.logmanager.version}</version>
-            <!-- License: Apache 2.0 -->
-        </dependency>
     </dependencies>
 
     <profiles>
@@ -254,15 +222,6 @@
                 </plugins>
             </build>
         </profile>
-        <profile>
-            <id>java9on</id>
-            <activation>
-                <jdk>[9,)</jdk>
-            </activation>
-            <properties>
-                <maven.compiler.release>8</maven.compiler.release>
-            </properties>
-        </profile>
     </profiles>
 
     <build>
@@ -400,9 +359,6 @@
             </resource>
         </resources>
         <plugins>
-            <plugin>
-                <artifactId>maven-source-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-help-plugin</artifactId>
@@ -548,6 +504,7 @@
                     </execution>
                 </executions>
             </plugin>
+
         </plugins>
     </build>
 
diff --git a/src/main/c/CMakeLists.txt b/src/main/c/CMakeLists.txt
index 67275cf..631156a 100644
--- a/src/main/c/CMakeLists.txt
+++ b/src/main/c/CMakeLists.txt
@@ -72,7 +72,7 @@ INCLUDE_DIRECTORIES(. ${JNI_INCLUDE_DIRS})
 
 ADD_CUSTOM_COMMAND(
     OUTPUT org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.h
-    COMMAND javah -cp ../java/ org.apache.activemq.artemis.nativo.jlibaio.LibaioContext
+    COMMAND javac -h . ../java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java  -cp ../java/ -d ../../../target/classes-javah-compilation
     DEPENDS ../java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
 )
 
diff --git a/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.h b/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.h
index 7adfd43..e42c126 100644
--- a/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.h
+++ b/src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.h
@@ -8,7 +8,7 @@
 extern "C" {
 #endif
 #undef org_apache_activemq_artemis_nativo_jlibaio_LibaioContext_EXPECTED_NATIVE_VERSION
-#define org_apache_activemq_artemis_nativo_jlibaio_LibaioContext_EXPECTED_NATIVE_VERSION 10L
+#define org_apache_activemq_artemis_nativo_jlibaio_LibaioContext_EXPECTED_NATIVE_VERSION 11L
 /*
  * Class:     org_apache_activemq_artemis_nativo_jlibaio_LibaioContext
  * Method:    shutdownHook
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
index 794e112..d91fdbe 100644
--- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioContext.java
@@ -47,7 +47,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
    /**
     * The Native layer will look at this version.
     */
-   private static final int EXPECTED_NATIVE_VERSION = 10;
+   private static final int EXPECTED_NATIVE_VERSION = 11;
 
    private static boolean loaded = false;
 
@@ -63,13 +63,13 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
       try {
          System.loadLibrary(name);
          if (getNativeVersion() != EXPECTED_NATIVE_VERSION) {
-            NativeLogger.LOGGER.incompatibleNativeLibrary();
+            NativeLogger.incompatibleNativeLibrary();
             return false;
          } else {
             return true;
          }
       } catch (Throwable e) {
-         NativeLogger.LOGGER.debug(name + " -> error loading the native library", e);
+         NativeLogger.debug(name + " -> error loading the native library", e);
          return false;
       }
 
@@ -93,12 +93,12 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
             });
             break;
          } else {
-            NativeLogger.LOGGER.debug("Library " + library + " not found!");
+            NativeLogger.debug("Library " + library + " not found!");
          }
       }
 
       if (!loaded) {
-         NativeLogger.LOGGER.debug("Couldn't locate LibAIO Wrapper");
+         NativeLogger.debug("Couldn't locate LibAIO Wrapper");
       }
    }
 
@@ -242,7 +242,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
             try {
                ioSpace.tryAcquire(queueSize, 10, TimeUnit.SECONDS);
             } catch (Exception e) {
-               NativeLogger.LOGGER.error(e);
+               NativeLogger.warn(e.getMessage(), e);
             }
          }
          totalMaxIO.addAndGet(-queueSize);
@@ -255,11 +255,6 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
       }
    }
 
-   @Override
-   protected void finalize() throws Throwable {
-      super.finalize();
-      close();
-   }
 
    /**
     * It will open a file. If you set the direct flag = false then you won't need to use the special buffer.
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java
index 373e48c..f03ed87 100644
--- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LibaioFile.java
@@ -120,7 +120,7 @@ public final class LibaioFile<Callback extends SubmitInfo> implements AutoClosea
       try {
          LibaioContext.fill(fd, alignment, size);
       } catch (OutOfMemoryError e) {
-         NativeLogger.LOGGER.debug("Didn't have enough memory to allocate " + size + " bytes in memory, using simple fallocate");
+         NativeLogger.warn("Did not have enough memory to allocate " + size + " bytes in memory while filling the file, using simple fallocate");
          LibaioContext.fallocate(fd, size);
       }
    }
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java
new file mode 100644
index 0000000..dc41013
--- /dev/null
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java
@@ -0,0 +1,35 @@
+/*
+ * 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.activemq.artemis.nativo.jlibaio;
+
+
+/** I am keeping Artemis Native Log Free, so it will be simpler to compile it, especially on the include bits.
+ *  If you want the NativeLogger redirected to any framework you can use the method NativeLogger.setCallback(LoggerCallback) on your
+ *  usage implementation*/
+public interface LoggerCallback {
+
+   void info(String message);
+
+   void warn(String message);
+
+   void warn(String message, Throwable e);
+
+   void debug(String message);
+
+   void debug(String message, Throwable e);
+}
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java
index b32a2e6..c5ddd81 100644
--- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java
@@ -16,35 +16,40 @@
  */
 package org.apache.activemq.artemis.nativo.jlibaio;
 
-import org.jboss.logging.BasicLogger;
-import org.jboss.logging.Logger;
-import org.jboss.logging.annotations.LogMessage;
-import org.jboss.logging.annotations.Message;
-import org.jboss.logging.annotations.MessageLogger;
-
-/**
- * Logger Code 16
- *
- * each message id must be 6 digits long starting with 16, the 3rd digit denotes the level so
- *
- * INF0  1
- * WARN  2
- * DEBUG 3
- * ERROR 4
- * TRACE 5
- * FATAL 6
- *
- * so an INFO message would be 161000 to 161999
- */
-@MessageLogger(projectCode = "jlibaio")
-public interface NativeLogger extends BasicLogger {
+public class NativeLogger {
+
+   public static final String PROJECT_PREFIX = "jlibaio";
+
+   private static LoggerCallback loggerCallback = new SystemCallback();
+
+   public static void setLoggerCallback(LoggerCallback callback) {
+      loggerCallback = callback;
+   }
+
+   private static final int DIFFERENT_VERSION_ID = 163001;
+   private static final String DIFFERENT_VERSION = PROJECT_PREFIX + DIFFERENT_VERSION_ID + " You have a native library with a different version than expected";
+
+   public final static void incompatibleNativeLibrary() {
+       warn(DIFFERENT_VERSION);
+   }
+
+   public final static void info(String message) {
+      loggerCallback.info(message);
+   }
+
+   public final static void warn(String message) {
+      loggerCallback.warn(message);
+   }
+
+   public final static void warn(String message, Throwable e) {
+      loggerCallback.warn(message, e);
+   }
 
-   /**
-    * The journal logger.
-    */
-   NativeLogger LOGGER = Logger.getMessageLogger(NativeLogger.class, NativeLogger.class.getPackage().getName());
+   public final static void debug(String message) {
+      loggerCallback.debug(message);
+   }
 
-   @LogMessage(level = Logger.Level.WARN)
-   @Message(id = 163001, value = "You have a native library with a different version than expected", format = Message.Format.MESSAGE_FORMAT)
-   void incompatibleNativeLibrary();
+   public final static void debug(String message, Throwable e) {
+      loggerCallback.debug(message, e);
+   }
 }
diff --git a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java
new file mode 100644
index 0000000..b50c209
--- /dev/null
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java
@@ -0,0 +1,50 @@
+/*
+ * 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.activemq.artemis.nativo.jlibaio;
+
+/** This will use System.err for warn and System.out for info */
+public class SystemCallback implements LoggerCallback {
+
+   private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty(SystemCallback.class.getName() + ".DEBUG", "false"));
+
+   public void debug(String message, Throwable e) {
+      if (DEBUG) {
+         System.out.println("Debug from ArtemisNative: " + message);
+         e.printStackTrace(System.out);
+      }
+   }
+
+   public void debug(String message) {
+      if (DEBUG) {
+         System.out.println("Debug from ArtemisNative: " + message);
+      }
+   }
+
+   public void info(String message) {
+      System.out.println("Information from ArtemisNative: " + message);
+   }
+
+   public void warn(String message) {
+      System.err.println("Warning from ArtemisNative: " + message);
+   }
+
+   public void warn(String message, Throwable e) {
+      System.err.println("Warning from ArtemisNative: " + message);
+      e.printStackTrace(System.err);
+   }
+}
diff --git a/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java b/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
index 074597f..ec8b73d 100644
--- a/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
+++ b/src/test/java/org/apache/activemq/artemis/nativo/jlibaio/test/LibaioTest.java
@@ -20,6 +20,7 @@ package org.apache.activemq.artemis.nativo.jlibaio.test;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.lang.ref.Cleaner;
 import java.lang.ref.WeakReference;
 import java.nio.ByteBuffer;
 import java.util.concurrent.CountDownLatch;
@@ -703,13 +704,19 @@ public class LibaioTest {
 
    static class TestInfo implements SubmitInfo {
 
-      static AtomicInteger count = new AtomicInteger();
+      static final Cleaner cleaner;
 
-      @Override
-      protected void finalize() throws Throwable {
-         super.finalize();
-         count.decrementAndGet();
+      static {
+         Cleaner tempCleaner;
+         try {
+            tempCleaner = Cleaner.create();
+         } catch (Throwable e) {
+            e.printStackTrace();
+            tempCleaner = null;
+         }
+         cleaner = tempCleaner;
       }
+      static AtomicInteger count = new AtomicInteger();
 
       public static void checkLeaks() throws InterruptedException {
          for (int i = 0; count.get() != 0 && i < 50; i++) {
@@ -728,6 +735,8 @@ public class LibaioTest {
 
       TestInfo() {
          count.incrementAndGet();
+         cleaner.register(this, count::decrementAndGet);
+
       }
 
       @Override