Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#289 fix + application servers compatibility #290

Open
wants to merge 5 commits into
base: 0.7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ private/
.nb-gradle-properties
.bdb/
log4j.xml
gradle/
gradlew
gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static co.paralleluniverse.common.reflection.ClassLoaderUtil.resourceToClass;
import co.paralleluniverse.common.util.Exceptions;
import co.paralleluniverse.concurrent.util.MapUtil;
import co.paralleluniverse.common.util.SystemProperties;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import java.io.IOException;
Expand Down Expand Up @@ -77,9 +78,9 @@ public class ActorLoader extends ClassLoader implements ActorLoaderMXBean, Notif
static {
ClassLoader.registerAsParallelCapable();

instance = new ActorLoader("co.paralleluniverse:type=ActorLoader");
instance = new ActorLoader("co.paralleluniverse:type=" + SystemProperties.prefixWithName("ActorLoader"));

String moduleDirName = System.getProperty(MODULE_DIR_PROPERTY);
String moduleDirName = SystemProperties.getLocalProperty(MODULE_DIR_PROPERTY);
if (moduleDirName != null) {
Path mdir = Paths.get(moduleDirName);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import co.paralleluniverse.common.monitoring.Counter;
import co.paralleluniverse.common.monitoring.MonitoringServices;
import co.paralleluniverse.common.util.Objects;
import co.paralleluniverse.common.util.SystemProperties;
import java.lang.management.ManagementFactory;
import java.lang.ref.WeakReference;
import java.util.List;
Expand Down Expand Up @@ -73,7 +74,7 @@ public JMXActorMonitor(String name) {
}

private static String beanName(String name) {
return "co.paralleluniverse:type=quasar,monitor=actor,name=" + name;
return "co.paralleluniverse:type=quasar,monitor=actor,name=" + SystemProperties.prefixWithName(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import co.paralleluniverse.common.monitoring.Counter;
import co.paralleluniverse.common.monitoring.MonitoringServices;
import co.paralleluniverse.strands.Strand;
import co.paralleluniverse.common.util.SystemProperties;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -54,20 +55,29 @@ public static JMXActorsMonitor getInstance() {
private final Counter activeCount = new Counter();

private JMXActorsMonitor() {
this.mbeanName = "co.paralleluniverse:type=Actors";
registerMBean();
this.mbeanName = "co.paralleluniverse:type=" + SystemProperties.prefixWithName("Actors");
registerMBean(true);
lastCollectTime = nanoTime();
}

@SuppressWarnings({"CallToPrintStackTrace", "CallToThreadDumpStack"})
private void registerMBean() {
private void registerMBean(boolean retry) {
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName mxbeanName = new ObjectName(mbeanName);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
if (retry) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(mbeanName));
} catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException ex2) {
throw new AssertionError(ex);
}
registerMBean(false);
} else {
throw new RuntimeException(ex);
}
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import co.paralleluniverse.common.util.SystemProperties;
import jsr166e.ForkJoinPool;

/**
Expand All @@ -36,18 +38,27 @@ public class JMXForkJoinPoolMonitor extends ForkJoinPoolMonitor implements ForkJ
public JMXForkJoinPoolMonitor(String name, ForkJoinPool fjPool) {
super(name, fjPool);
//super(ForkJoinPoolMXBean.class, true, new NotificationBroadcasterSupport());
this.mbeanName = "co.paralleluniverse:type=ForkJoinPool,name=" + name;
registerMBean();
this.mbeanName = "co.paralleluniverse:type=ForkJoinPool,name=" + SystemProperties.prefixWithName(name);
registerMBean(true);
}

protected void registerMBean() {
protected void registerMBean(boolean retry) {
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName mxbeanName = new ObjectName(mbeanName);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
if (retry) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(mbeanName));
} catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException ex2) {
throw new AssertionError(ex);
}
registerMBean(false);
} else {
throw new RuntimeException(ex);
}
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package co.paralleluniverse.common.monitoring;

import co.paralleluniverse.common.util.SystemProperties;

import java.lang.management.ManagementFactory;
import java.util.concurrent.ForkJoinPool;
import javax.management.InstanceAlreadyExistsException;
Expand All @@ -33,18 +35,27 @@ public class JMXForkJoinPoolMonitor extends ForkJoinPoolMonitor implements ForkJ
public JMXForkJoinPoolMonitor(String name, ForkJoinPool fjPool) {
super(name, fjPool);
//super(ForkJoinPoolMXBean.class, true, new NotificationBroadcasterSupport());
this.mbeanName = "co.paralleluniverse:type=ForkJoinPool,name=" + name;
registerMBean();
this.mbeanName = "co.paralleluniverse:type=ForkJoinPool,name=" + SystemProperties.prefixWithName(name);
registerMBean(true);
}

protected void registerMBean() {
protected void registerMBean(boolean retry) {
try {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ObjectName mxbeanName = new ObjectName(mbeanName);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
if (retry) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(mbeanName));
} catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException ex2) {
throw new AssertionError(ex);
}
registerMBean(false);
} else {
throw new RuntimeException(ex);
}
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package co.paralleluniverse.common.monitoring;

import co.paralleluniverse.common.util.SystemProperties;
import co.paralleluniverse.concurrent.util.MapUtil;
import java.io.FileOutputStream;
import java.io.PrintStream;
Expand All @@ -38,10 +39,10 @@ public class FlightRecorder extends SimpleMBean implements FlightRecorderMXBean
private Object aux;

public FlightRecorder(String name) {
super(null, name, "FlightRecorder", null);
super(null, SystemProperties.prefixWithName(name), "FlightRecorder", null);
startTimestamp = System.nanoTime();
startWallTime = System.currentTimeMillis();
registerMBean();
registerMBean(true);
}

public void clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package co.paralleluniverse.common.monitoring;

import co.paralleluniverse.common.util.SystemProperties;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.Date;
Expand Down Expand Up @@ -47,7 +49,7 @@ public static MonitoringServices getInstance() {
private int structuralTimerListeners;

private MonitoringServices() {
registerMBean();
registerMBean(true);
perfTimerListeners = 0;
structuralTimerListeners = 0;

Expand All @@ -66,19 +68,28 @@ private synchronized void manageTimer() {
}
}

private void registerMBean() {
private void registerMBean(boolean retry) {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = new ObjectName("co.paralleluniverse:name=MonitoringServices");
ObjectName mxbeanName = new ObjectName("co.paralleluniverse:name=" + SystemProperties.prefixWithName("MonitoringServices"));
mbs.registerMBean(this, mxbeanName);
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
if (retry) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName("co.paralleluniverse:name=MonitoringServices"));
} catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException ex2) {
throw new AssertionError(ex);
}
registerMBean(false);
} else {
throw new RuntimeException(ex);
}
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
throw new AssertionError(ex);
} catch (MalformedObjectNameException ex) {
throw new AssertionError(ex);
throw new RuntimeException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ public SimpleMBean(String product, String name, String monitor, String kind) {
+ (kind != null ? ",kind=" + kind : "");
}

protected void registerMBean() {
protected void registerMBean(boolean retry) {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName mxbeanName = new ObjectName(name);
mbs.registerMBean(this, mxbeanName);
this.registered = true;
} catch (InstanceAlreadyExistsException ex) {
throw new RuntimeException(ex);
if (retry) {
try {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(new ObjectName(name));
} catch (InstanceNotFoundException | MalformedObjectNameException | MBeanRegistrationException ex2) {
throw new AssertionError(ex);
}
registerMBean(false);
} else {
throw new RuntimeException(ex);
}
} catch (MBeanRegistrationException ex) {
ex.printStackTrace();
} catch (NotCompliantMBeanException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class Debug {
private static final boolean debugMode = SystemProperties.isEmptyOrTrue("co.paralleluniverse.debugMode");
private static final String FLIGHT_RECORDER_DUMP_FILE = System.getProperty("co.paralleluniverse.flightRecorderDumpFile");
private static final String FLIGHT_RECORDER_DUMP_FILE = SystemProperties.getLocalProperty("co.paralleluniverse.flightRecorderDumpFile");
private static final FlightRecorder flightRecorder = (debugMode && SystemProperties.isEmptyOrTrue("co.paralleluniverse.globalFlightRecorder") ? new FlightRecorder("PUNIVERSE-FLIGHT-RECORDER") : null);
private static boolean recordStackTraces = false;
private static final boolean assertionsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,43 @@
*/
package co.paralleluniverse.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
* System properties utilities.
*
* @author pron
*/
public final class SystemProperties {
private static String PROPERTY_FILE_PATH = "/quasar.properties";
private static String PROPERTY_NAME = "co.paralleluniverse.common.util.SystemProperties.name";

static final Properties prop;
static {
URL resource = SystemProperties.class.getResource(PROPERTY_FILE_PATH);
if (resource != null) {
prop = new Properties();
try (InputStream in = resource.openStream()){
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
} else {
prop = null;
}
}

/**
* Returns the value of a system property which defaults to false.
*
* @param property the name of the system property
* @return {@code true} iff the given property is defined and has the value {@code "true"} or the empty string.
*/
public static boolean isEmptyOrTrue(String property) {
final String value = System.getProperty(property);
final String value = getLocalProperty(property);
if (value == null)
return false;
return value.isEmpty() || Boolean.parseBoolean(value);
Expand All @@ -38,7 +61,7 @@ public static boolean isEmptyOrTrue(String property) {
* @return {@code true} iff the given property is undefined, or defined and has the value {@code "true"} or the empty string.
*/
public static boolean isNotFalse(String property) {
final String value = System.getProperty(property);
final String value = getLocalProperty(property);
if (value == null)
return true;
if (value.isEmpty())
Expand All @@ -48,4 +71,24 @@ public static boolean isNotFalse(String property) {

private SystemProperties() {
}

public static String getLocalProperty(String key) {
String value = null;
if (prop != null) {
value = prop.getProperty(key);
}
if (value == null) {
value = System.getProperty(key);
}
return value;
}

public static String prefixWithName(String value) {
String name = getLocalProperty(PROPERTY_NAME);
if (name != null) {
return name + "-" + value;
} else {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package co.paralleluniverse.fibers;

import co.paralleluniverse.common.monitoring.MonitorType;
import co.paralleluniverse.common.util.SystemProperties;

import java.lang.Thread.UncaughtExceptionHandler;

/**
Expand Down Expand Up @@ -51,8 +53,8 @@ public class DefaultFiberScheduler {

// get overrides
try {
String pp = System.getProperty(PROPERTY_PARALLELISM);
String hp = System.getProperty(PROPERTY_EXCEPTION_HANDLER);
String pp = SystemProperties.getLocalProperty(PROPERTY_PARALLELISM);
String hp = SystemProperties.getLocalProperty(PROPERTY_EXCEPTION_HANDLER);
// String fp = System.getProperty(PROPERTY_THREAD_FACTORY);
// if (fp != null)
// fac = ((ForkJoinPool.ForkJoinWorkerThreadFactory) ClassLoader.getSystemClassLoader().loadClass(fp).newInstance());
Expand All @@ -68,11 +70,11 @@ public class DefaultFiberScheduler {
if (par > MAX_CAP)
par = MAX_CAP;

String mt = System.getProperty(PROPERTY_MONITOR_TYPE);
String mt = SystemProperties.getLocalProperty(PROPERTY_MONITOR_TYPE);
if (mt != null)
monitorType = MonitorType.valueOf(mt.toUpperCase());

String dfis = System.getProperty(PROPERTY_DETAILED_FIBER_INFO);
String dfis = SystemProperties.getLocalProperty(PROPERTY_DETAILED_FIBER_INFO);
if (dfis != null)
detailedFiberInfo = Boolean.valueOf(dfis);

Expand Down
Loading