-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JMX debug connector as first part of automated mod testing
- Loading branch information
1 parent
13a54eb
commit f5359cb
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jmt.mcmt.jmx; | ||
|
||
import java.lang.management.ManagementFactory; | ||
|
||
import javax.management.InstanceAlreadyExistsException; | ||
import javax.management.MBeanRegistrationException; | ||
import javax.management.MBeanServer; | ||
import javax.management.MalformedObjectNameException; | ||
import javax.management.NotCompliantMBeanException; | ||
import javax.management.ObjectName; | ||
|
||
public class JMXRegistration { | ||
|
||
public static void register() { | ||
try { | ||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
ObjectName debugName = new ObjectName("org.jmt.mcmt:type=MCMTDebug"); | ||
MCMTDebug debugBean = new MCMTDebug(); | ||
mbs.registerMBean(debugBean, debugName); | ||
} catch (MalformedObjectNameException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (InstanceAlreadyExistsException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (MBeanRegistrationException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (NotCompliantMBeanException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.jmt.mcmt.jmx; | ||
|
||
import javax.management.AttributeChangeNotification; | ||
import javax.management.MBeanNotificationInfo; | ||
import javax.management.NotificationBroadcasterSupport; | ||
|
||
import org.jmt.mcmt.asmdest.DebugHookTerminator; | ||
|
||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraftforge.fml.ModList; | ||
|
||
/** | ||
* MBean for debugging modlaunching issues | ||
* | ||
* @author jediminer543 | ||
* | ||
*/ | ||
public class MCMTDebug extends NotificationBroadcasterSupport implements MCMTDebugMBean { | ||
|
||
ClassLoader ccl = null; | ||
|
||
public MCMTDebug() { | ||
// needed because classloading issues; classload all TRANSFORMER classes before stuff | ||
ccl = Thread.currentThread().getContextClassLoader(); | ||
} | ||
|
||
@Override | ||
public String[] getLoadedMods() { | ||
Thread.currentThread().setContextClassLoader(ccl); | ||
return ModList.get().applyForEachModContainer(mc -> mc.getModId()+":"+mc.getModInfo().getVersion().toString()).toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public String getMainChunkLoadStatus() { | ||
Thread.currentThread().setContextClassLoader(ccl); | ||
return DebugHookTerminator.mainThreadChunkLoad.get() + ":" + DebugHookTerminator.mainThreadChunkLoadCount.get(); | ||
} | ||
|
||
@Override | ||
public String[] getBrokenChunkList() { | ||
Thread.currentThread().setContextClassLoader(ccl); | ||
return DebugHookTerminator.breaks.stream().map(bcl -> new ChunkPos(bcl.getChunkPos()).toString()).toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public MBeanNotificationInfo[] getNotificationInfo() { | ||
String[] types = new String[]{ | ||
AttributeChangeNotification.ATTRIBUTE_CHANGE | ||
}; | ||
|
||
String name = AttributeChangeNotification.class.getName(); | ||
String description = "An attribute of this MBean has changed"; | ||
MBeanNotificationInfo info = | ||
new MBeanNotificationInfo(types, name, description); | ||
return new MBeanNotificationInfo[]{info}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.jmt.mcmt.jmx; | ||
|
||
public interface MCMTDebugMBean { | ||
|
||
public String[] getLoadedMods(); | ||
|
||
public String getMainChunkLoadStatus(); | ||
|
||
public String[] getBrokenChunkList(); | ||
|
||
} |