Archiviert
13
0

Update asynchronous manager and handle static senders in reports.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-07-06 07:51:02 +02:00
Ursprung 6847283fb3
Commit a4f81e5e9f
6 geänderte Dateien mit 623 neuen und 582 gelöschten Zeilen

Datei anzeigen

@ -217,7 +217,7 @@ public class ProtocolLibrary extends JavaPlugin {
@Override @Override
protected Report filterReport(Object sender, Report report, boolean detailed) { protected Report filterReport(Object sender, Report report, boolean detailed) {
String canonicalName = ReportType.getReportName(sender.getClass(), report.getType()); String canonicalName = ReportType.getReportName(sender, report.getType());
String reportName = Iterables.getLast(Splitter.on("#").split(canonicalName)).toUpperCase(); String reportName = Iterables.getLast(Splitter.on("#").split(canonicalName)).toUpperCase();
if (config != null && config.getModificationCount() != lastModCount) { if (config != null && config.getModificationCount() != lastModCount) {

Datei anzeigen

@ -59,7 +59,7 @@ public class DelegatedErrorReporter implements ErrorReporter {
* Invoked before an error report is passed on to the underlying error reporter. * Invoked before an error report is passed on to the underlying error reporter.
* <p> * <p>
* To cancel a report, return NULL. * To cancel a report, return NULL.
* @param sender - the sender component. * @param sender - the sender instance or class.
* @param report - the error report. * @param report - the error report.
* @param detailed - whether or not the report will be displayed in detail. * @param detailed - whether or not the report will be displayed in detail.
* @return The report to pass on, or NULL to cancel it. * @return The report to pass on, or NULL to cancel it.

Datei anzeigen

@ -224,7 +224,7 @@ public class DetailedErrorReporter implements ErrorReporter {
*/ */
private String getSenderName(Object sender) { private String getSenderName(Object sender) {
if (sender != null) if (sender != null)
return sender.getClass().getSimpleName(); return ReportType.getSenderClass(sender).getSimpleName();
else else
return "NULL"; return "NULL";
} }
@ -345,7 +345,7 @@ public class DetailedErrorReporter implements ErrorReporter {
// We can't only rely on toString. // We can't only rely on toString.
if (value == null) { if (value == null) {
return "[NULL]"; return "[NULL]";
} if (isSimpleType(value)) { } if (isSimpleType(value) || value instanceof Class<?>) {
return value.toString(); return value.toString();
} else { } else {
try { try {

Datei anzeigen

@ -46,6 +46,39 @@ public class ReportType {
return errorFormat; return errorFormat;
} }
/**
* Retrieve the class of the given sender.
* <p>
* If the sender is already a Class, we return it.
* @param sender - the sender to look up.
* @return The class of the sender.
*/
public static Class<?> getSenderClass(Object sender) {
if (sender == null)
throw new IllegalArgumentException("sender cannot be NUll.");
else if (sender instanceof Class<?>)
return (Class<?>) sender;
else
return sender.getClass();
}
/**
* Retrieve the full canonical name of a given report type.
* <p>
* Note that the sender may be a class (for static callers), in which
* case it will be used directly instead of its getClass() method.
* <p>
* It is thus not advisable for class classes to report reports.
* @param sender - the sender, or its class.
* @param type - the report type.
* @return The full canonical name.
*/
public static String getReportName(Object sender, ReportType type) {
if (sender == null)
throw new IllegalArgumentException("sender cannot be NUll.");
return getReportName(getSenderClass(sender), type);
}
/** /**
* Retrieve the full canonical name of a given report type. * Retrieve the full canonical name of a given report type.
* <p> * <p>
@ -54,7 +87,7 @@ public class ReportType {
* @param type - the report instance. * @param type - the report instance.
* @return The full canonical name. * @return The full canonical name.
*/ */
public static String getReportName(Class<?> sender, ReportType type) { private static String getReportName(Class<?> sender, ReportType type) {
if (sender == null) if (sender == null)
throw new IllegalArgumentException("sender cannot be NUll."); throw new IllegalArgumentException("sender cannot be NUll.");

Datei anzeigen

@ -362,6 +362,10 @@ public class DelayedPacketManager implements ProtocolManager, InternalManager {
return asyncManager; return asyncManager;
} }
/**
* Update the asynchronous manager. This must be set.
* @param asyncManager - the asynchronous manager.
*/
public void setAsynchronousManager(AsynchronousManager asyncManager) { public void setAsynchronousManager(AsynchronousManager asyncManager) {
this.asyncManager = asyncManager; this.asyncManager = asyncManager;
} }

Datei anzeigen

@ -268,6 +268,10 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
// We need to delay this until we know if Netty is enabled // We need to delay this until we know if Netty is enabled
final DelayedPacketManager delayed = new DelayedPacketManager(reporter); final DelayedPacketManager delayed = new DelayedPacketManager(reporter);
// They must reference each other
delayed.setAsynchronousManager(asyncManager);
asyncManager.setManager(delayed);
Futures.addCallback(BukkitFutures.nextEvent(library, WorldInitEvent.class), new FutureCallback<WorldInitEvent>() { Futures.addCallback(BukkitFutures.nextEvent(library, WorldInitEvent.class), new FutureCallback<WorldInitEvent>() {
@Override @Override
public void onSuccess(WorldInitEvent event) { public void onSuccess(WorldInitEvent event) {
@ -297,7 +301,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
@Override @Override
public void onFailure(Throwable error) { public void onFailure(Throwable error) {
reporter.reportWarning(this, Report.newBuilder(REPORT_TEMPORARY_EVENT_ERROR).error(error)); reporter.reportWarning(PacketFilterManager.class, Report.newBuilder(REPORT_TEMPORARY_EVENT_ERROR).error(error));
} }
}); });