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:20:28 UTC

[activemq-artemis-native] branch new-logging updated (a4adf10 -> 291b77f)

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

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


    from a4adf10  add note about removing finalize usage
     new 8e33669  Removing Logger references and its dependencies
     new 0bb8a2e  Using javac -h instead of javah
     new 291b77f  Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks

The 3 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.


Summary of changes:
 pom.xml                                            | 31 ++------------
 src/main/c/CMakeLists.txt                          |  2 +-
 .../artemis/nativo/jlibaio/LibaioContext.java      | 17 ++------
 .../artemis/nativo/jlibaio/LibaioFile.java         |  7 +--
 .../{SubmitInfo.java => LoggerCallback.java}       | 16 +++++--
 .../artemis/nativo/jlibaio/NativeLogger.java       | 36 ++++++++++++----
 .../artemis/nativo/jlibaio/SystemCallback.java     | 50 ++++++++++++++++++++++
 .../artemis/nativo/jlibaio/test/LibaioTest.java    | 19 +++++---
 8 files changed, 113 insertions(+), 65 deletions(-)
 copy src/main/java/org/apache/activemq/artemis/nativo/jlibaio/{SubmitInfo.java => LoggerCallback.java} (63%)
 create mode 100644 src/main/java/org/apache/activemq/artemis/nativo/jlibaio/SystemCallback.java


[activemq-artemis-native] 03/03: Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks

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

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

commit 291b77ffc1af88f6cb5858a8a3af0fa8ceebecad
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Jul 1 11:39:12 2022 -0400

    Removing finalize calls, using Java11, Using Cleaner API in some tests that are validating leaks
---
 pom.xml                                               | 17 +++--------------
 .../artemis/nativo/jlibaio/LibaioContext.java         |  5 -----
 .../artemis/nativo/jlibaio/test/LibaioTest.java       | 19 ++++++++++++++-----
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/pom.xml b/pom.xml
index 16b4602..4d4a6de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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}"
@@ -222,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>
@@ -368,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>
@@ -516,6 +504,7 @@
                     </execution>
                 </executions>
             </plugin>
+
         </plugins>
     </build>
 
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 bdde812..fe90410 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
@@ -255,11 +255,6 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
       }
    }
 
-   @Override
-   protected void finalize() throws Throwable { //TODO: remove?
-      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/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


[activemq-artemis-native] 01/03: 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 new-logging
in repository https://gitbox.apache.org/repos/asf/activemq-artemis-native.git

commit 8e3366952a3265b3fa8148024c2f24f7758da500
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Jul 1 10:24:41 2022 -0400

    Removing Logger references and its dependencies
---
 pom.xml                                            | 14 ------
 .../artemis/nativo/jlibaio/LibaioContext.java      | 12 ++----
 .../artemis/nativo/jlibaio/LibaioFile.java         |  7 +--
 .../{NativeLogger.java => LoggerCallback.java}     | 24 +++++------
 .../artemis/nativo/jlibaio/NativeLogger.java       | 36 ++++++++++++----
 .../artemis/nativo/jlibaio/SystemCallback.java     | 50 ++++++++++++++++++++++
 6 files changed, 93 insertions(+), 50 deletions(-)

diff --git a/pom.xml b/pom.xml
index 44ebcf5..16b4602 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,20 +88,6 @@
     </issueManagement>
 
     <dependencies>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-            <version>${slf4j.version}</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <!-- ## Test Dependencies -->
-        <dependency>
-            <groupId>org.apache.logging.log4j</groupId>
-            <artifactId>log4j-slf4j-impl</artifactId>
-            <version>${log4j.version}</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
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 c53f0fa..bdde812 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
@@ -26,9 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * This class is used as an aggregator for the {@link LibaioFile}.
  * <br>
@@ -45,7 +42,6 @@ import org.slf4j.LoggerFactory;
  */
 public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
 
-   private static final Logger logger = LoggerFactory.getLogger(LibaioContext.class);
    private static final AtomicLong totalMaxIO = new AtomicLong(0);
 
    /**
@@ -73,7 +69,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
             return true;
          }
       } catch (Throwable e) {
-         logger.debug(name + " -> error loading the native library", e);
+         NativeLogger.debug(name + " -> error loading the native library", e);
          return false;
       }
 
@@ -97,12 +93,12 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
             });
             break;
          } else {
-            logger.debug("Library " + library + " not found!");
+            NativeLogger.debug("Library " + library + " not found!");
          }
       }
 
       if (!loaded) {
-         logger.debug("Couldn't locate LibAIO Wrapper");
+         NativeLogger.debug("Couldn't locate LibAIO Wrapper");
       }
    }
 
@@ -246,7 +242,7 @@ public class LibaioContext<Callback extends SubmitInfo> implements Closeable {
             try {
                ioSpace.tryAcquire(queueSize, 10, TimeUnit.SECONDS);
             } catch (Exception e) {
-               logger.error(e.getMessage(), e);
+               NativeLogger.warn(e.getMessage(), e);
             }
          }
          totalMaxIO.addAndGet(-queueSize);
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 febe26a..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
@@ -19,16 +19,11 @@ package org.apache.activemq.artemis.nativo.jlibaio;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * This is an extension to use libaio.
  */
 public final class LibaioFile<Callback extends SubmitInfo> implements AutoCloseable {
 
-   private static final Logger logger = LoggerFactory.getLogger(LibaioFile.class);
-
    protected boolean open;
    /**
     * This represents a structure allocated on the native
@@ -125,7 +120,7 @@ public final class LibaioFile<Callback extends SubmitInfo> implements AutoClosea
       try {
          LibaioContext.fill(fd, alignment, size);
       } catch (OutOfMemoryError e) {
-         logger.debug("Didn't have enough memory to allocate {} bytes in memory, using simple fallocate", size);
+         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/NativeLogger.java b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java
similarity index 58%
copy from src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java
copy to src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java
index f24c214..dc41013 100644
--- a/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/NativeLogger.java
+++ b/src/main/java/org/apache/activemq/artemis/nativo/jlibaio/LoggerCallback.java
@@ -14,24 +14,22 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.activemq.artemis.nativo.jlibaio;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-/**
- * Logger Code 16
- */
-public class NativeLogger {
+/** 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);
 
-   private static final Logger logger = LoggerFactory.getLogger(NativeLogger.class.getPackage().getName());
+   void warn(String message);
 
-   public static final String PROJECT_PREFIX = "jlibaio";
+   void warn(String message, Throwable e);
 
-   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";
+   void debug(String message);
 
-   public final static void incompatibleNativeLibrary() {
-       logger.warn(DIFFERENT_VERSION);
-   }
+   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 f24c214..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,22 +16,40 @@
  */
 package org.apache.activemq.artemis.nativo.jlibaio;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Logger Code 16
- */
 public class NativeLogger {
 
-   private static final Logger logger = LoggerFactory.getLogger(NativeLogger.class.getPackage().getName());
-
    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() {
-       logger.warn(DIFFERENT_VERSION);
+       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);
+   }
+
+   public final static void debug(String message) {
+      loggerCallback.debug(message);
+   }
+
+   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);
+   }
+}


[activemq-artemis-native] 02/03: Using javac -h instead of javah

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

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

commit 0bb8a2e629e0aaf128b8c9673e7796c262ee5165
Author: clebert <cl...@gmail.com>
AuthorDate: Fri Jul 1 10:50:41 2022 -0400

    Using javac -h instead of javah
---
 src/main/c/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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
 )