Skip to content

Commit

Permalink
Rename pointers to javacpp MXBean object name, move check for system …
Browse files Browse the repository at this point in the history
…property org.bytedeco.javacpp.mxbean in Pointer
  • Loading branch information
digiovinazzo committed Jul 19, 2020
1 parent af46e9f commit 4153c34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/bytedeco/javacpp/Pointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.bytedeco.javacpp.annotation.Name;
import org.bytedeco.javacpp.annotation.Platform;
import org.bytedeco.javacpp.tools.Generator;
import org.bytedeco.javacpp.tools.PointerBufferPoolMXBean;
import org.bytedeco.javacpp.tools.Logger;

/**
Expand Down Expand Up @@ -510,6 +510,11 @@ public static long parseBytes(String string, long relativeMultiple) throws Numbe
} catch (Throwable t) {
logger.warn("Could not load Pointer: " + t);
}

String mx = System.getProperty("org.bytedeco.javacpp.mxbean", "false").toLowerCase();
if (mx.equals("true") || mx.equals("t") || mx.equals("")) {
PointerBufferPoolMXBean.register();
}
}

/** Clears, deallocates, and removes all garbage collected objects from the {@link #referenceQueue}. */
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/bytedeco/javacpp/tools/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ public static Logger create(Class cls) {
static {
String s = System.getProperty("org.bytedeco.javacpp.logger.debug", "false").toLowerCase();
debug = s.equals("true") || s.equals("t") || s.equals("");

String mx = System.getProperty("org.bytedeco.javacpp.mxbean", "false").toLowerCase();
if (mx.equals("true") || mx.equals("t") || mx.equals("")) {
PointersBufferPoolMXBean.register();
}
}

/** Returns the "org.bytedeco.javacpp.logger.debug" system property. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;

public class PointersBufferPoolMXBean implements BufferPoolMXBean {
public class PointerBufferPoolMXBean implements BufferPoolMXBean {

private static final Logger LOGGER = Logger.create(PointersBufferPoolMXBean.class);
private static final String POINTERS_MXBEAN_NAME = "pointers";
private static final Logger LOGGER = Logger.create(PointerBufferPoolMXBean.class);
private static final String JAVACPP_MXBEAN_NAME = "javacpp";
private static final ObjectName OBJECT_NAME;

static {
ObjectName objectName = null;
try {
objectName = new ObjectName("java.nio:type=BufferPool,name=" + POINTERS_MXBEAN_NAME);
objectName = new ObjectName("java.nio:type=BufferPool,name=" + JAVACPP_MXBEAN_NAME);
} catch (MalformedObjectNameException e) {
LOGGER.warn("Could not create OBJECT_NAME for " + POINTERS_MXBEAN_NAME);
LOGGER.warn("Could not create OBJECT_NAME for " + JAVACPP_MXBEAN_NAME);
}
OBJECT_NAME = objectName;
}

@Override
public String getName() {
return POINTERS_MXBEAN_NAME;
return JAVACPP_MXBEAN_NAME;
}

@Override
Expand All @@ -50,9 +50,9 @@ public long getMemoryUsed() {
public static void register() {
if (OBJECT_NAME != null) {
try {
ManagementFactory.getPlatformMBeanServer().registerMBean(new PointersBufferPoolMXBean(), OBJECT_NAME);
ManagementFactory.getPlatformMBeanServer().registerMBean(new PointerBufferPoolMXBean(), OBJECT_NAME);
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
LOGGER.warn("Could not register " + POINTERS_MXBEAN_NAME + " BufferPoolMXBean");
LOGGER.warn("Could not register " + JAVACPP_MXBEAN_NAME + " BufferPoolMXBean");
}
}
}
Expand Down

0 comments on commit 4153c34

Please sign in to comment.