Archiviert
13
0

Add a mechanism for printing debug reports.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-22 17:31:31 +01:00
Ursprung d71bea9f8a
Commit db8d08f602
8 geänderte Dateien mit 95 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,10 @@ import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.Semaphore;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PrioritizedListener;
import com.google.common.collect.MinMaxPriorityQueue;
@ -35,6 +38,8 @@ import com.google.common.collect.MinMaxPriorityQueue;
* @author Kristian
*/
class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncListenerHandler> {
public static final ReportType REPORT_GUAVA_CORRUPT_MISSING =
new ReportType("Guava is either missing or corrupt. Reverting to PriorityQueue.");
// Initial number of elements
public static final int INITIAL_CAPACITY = 64;
@ -74,8 +79,9 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
maximumSize(maximumSize).
<PacketEventHolder>create(), null);
} catch (IncompatibleClassChangeError e) {
System.out.println("[ProtocolLib] Guava is either missing or corrupt. Reverting to PriorityQueue.");
e.printStackTrace();
// Print in the console
ProtocolLibrary.getErrorReporter().reportWarning(
this, Report.newBuilder(REPORT_GUAVA_CORRUPT_MISSING).error(e));
// It's a Beta class after all
this.processingQueue = Synchronization.queue(

Datei anzeigen

@ -27,6 +27,10 @@ import java.util.concurrent.PriorityBlockingQueue;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.error.ErrorReporter;
import com.comphenix.protocol.error.Report;
import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.PlayerLoggedOutException;
import com.comphenix.protocol.reflect.FieldAccessException;
@ -36,17 +40,16 @@ import com.comphenix.protocol.reflect.FieldAccessException;
* @author Kristian
*/
abstract class PacketSendingQueue {
public static final ReportType REPORT_DROPPED_PACKET = new ReportType("Warning: Dropped packet index %s of type %s.");
public static final int INITIAL_CAPACITY = 10;
private PriorityBlockingQueue<PacketEventHolder> sendingQueue;
// Asynchronous packet sending
private Executor asynchronousSender;
// Whether or not packet transmission must occur on a specific thread
private final boolean notThreadSafe;
// Whether or not we've run the cleanup procedure
private boolean cleanedUp = false;
@ -279,10 +282,10 @@ abstract class PacketSendingQueue {
}
} catch (PlayerLoggedOutException e) {
System.out.println(String.format(
"[ProtocolLib] Warning: Dropped packet index %s of type %s",
marker.getOriginalSendingIndex(), event.getPacketType()
));
ProtocolLibrary.getErrorReporter().reportDebug(this, Report.newBuilder(REPORT_DROPPED_PACKET).
messageParam(marker.getOriginalSendingIndex(), event.getPacketType()).
callerParam(event)
);
} catch (IOException e) {
// Just print the error

Datei anzeigen

@ -45,6 +45,16 @@ public class BasicErrorReporter implements ErrorReporter {
printParameters(parameters);
}
@Override
public void reportDebug(Object sender, Report report) {
// We just have to swallow it
}
@Override
public void reportDebug(Object sender, ReportBuilder builder) {
// As above
}
@Override
public void reportWarning(Object sender, Report report) {
// Basic warning

Datei anzeigen

@ -37,6 +37,15 @@ public class DelegatedErrorReporter implements ErrorReporter {
delegated.reportMinimal(sender, methodName, error, parameters);
}
@Override
public void reportDebug(Object sender, Report report) {
Report transformed = filterReport(sender, report, false);
if (transformed != null) {
delegated.reportDebug(sender, transformed);
}
}
@Override
public void reportWarning(Object sender, Report report) {
Report transformed = filterReport(sender, report, false);
@ -77,4 +86,9 @@ public class DelegatedErrorReporter implements ErrorReporter {
public void reportDetailed(Object sender, ReportBuilder reportBuilder) {
reportDetailed(sender, reportBuilder.build());
}
@Override
public void reportDebug(Object sender, ReportBuilder builder) {
reportDebug(sender, builder.build());
}
}

Datei anzeigen

@ -37,6 +37,7 @@ import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.error.Report.ReportBuilder;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.reflect.PrettyPrinter;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Primitives;
/**
@ -144,7 +145,7 @@ public class DetailedErrorReporter implements ErrorReporter {
public void setDetailedReporting(boolean detailedReporting) {
this.detailedReporting = detailedReporting;
}
@Override
public void reportMinimal(Plugin sender, String methodName, Throwable error, Object... parameters) {
if (reportMinimalNoSpam(sender, methodName, error)) {
@ -210,6 +211,18 @@ public class DetailedErrorReporter implements ErrorReporter {
return (number & (number - 1)) == 0;
}
@Override
public void reportDebug(Object sender, ReportBuilder builder) {
reportDebug(sender, Preconditions.checkNotNull(builder, "builder cannot be NULL").build());
}
@Override
public void reportDebug(Object sender, Report report) {
if (logger.isLoggable(Level.FINE)) {
reportLevel(Level.FINE, sender, report);
}
}
@Override
public void reportWarning(Object sender, ReportBuilder reportBuilder) {
if (reportBuilder == null)
@ -220,24 +233,30 @@ public class DetailedErrorReporter implements ErrorReporter {
@Override
public void reportWarning(Object sender, Report report) {
if (logger.isLoggable(Level.WARNING)) {
reportLevel(Level.WARNING, sender, report);
}
}
private void reportLevel(Level level, Object sender, Report report) {
String message = "[" + pluginName + "] [" + getSenderName(sender) + "] " + report.getReportMessage();
// Print the main warning
if (report.getException() != null) {
logger.log(Level.WARNING, message, report.getException());
logger.log(level, message, report.getException());
} else {
logger.log(Level.WARNING, message);
logger.log(level, message);
// Remember the call stack
if (detailedReporting) {
printCallStack(Level.WARNING, logger);
printCallStack(level, logger);
}
}
// Parameters?
if (report.hasCallerParameters()) {
// Write it
logger.log(Level.WARNING, printParameters(report.getCallerParameters()));
logger.log(level, printParameters(report.getCallerParameters()));
}
}

Datei anzeigen

@ -44,6 +44,22 @@ public interface ErrorReporter {
*/
public abstract void reportMinimal(Plugin sender, String methodName, Throwable error, Object... parameters);
/**
* Prints a debug message from the current sender.
* <p>
* Most users will not see this message.
* @param sender - the sender.
* @param report - the report.
*/
public abstract void reportDebug(Object sender, Report report);
/**
* Prints a debug message from the current sender.
* @param sender - the sender.
* @param report - the report builder.
*/
public abstract void reportDebug(Object sender, ReportBuilder builder);
/**
* Prints a warning message from the current plugin.
* @param sender - the object containing the caller method.

Datei anzeigen

@ -21,6 +21,16 @@ public class RethrowErrorReporter implements ErrorReporter {
"Minimal error by " + sender + " in " + methodName + " with " + Joiner.on(",").join(parameters), error);
}
@Override
public void reportDebug(Object sender, Report report) {
// Do nothing - this is just a debug
}
@Override
public void reportDebug(Object sender, ReportBuilder builder) {
// As above
}
@Override
public void reportWarning(Object sender, ReportBuilder reportBuilder) {
reportWarning(sender, reportBuilder.build());

Datei anzeigen

@ -20,6 +20,7 @@ import com.google.common.util.concurrent.Futures;
public class PacketFilterBuilder {
public static final ReportType REPORT_TEMPORARY_EVENT_ERROR = new ReportType("Unable to register or handle temporary event.");
public static final ReportType REPORT_SPIGOT_IS_DELAYING_INJECTOR = new ReportType("Delaying due to Spigot.");
private ClassLoader classLoader;
private Server server;
@ -218,8 +219,8 @@ public class PacketFilterBuilder {
}
});
System.out.println("Delaying due to Spigot");
reporter.reportWarning(this, Report.newBuilder(REPORT_SPIGOT_IS_DELAYING_INJECTOR));
// Let plugins use this version instead
return delayed;
} else {