--- /dev/null
+package net.rizon.moo;
+
+import com.google.inject.Inject;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
+import org.slf4j.Logger;
+
+/**
+ * Reports any errors when a future operation is completed and is not completed
+ * successfully or canceled.
+ * <p>
+ * @author Orillion {@literal <orillion@rizon.net>}
+ */
+public class FutureExceptionListener<T> implements FutureListener<T>
+{
+ @Inject
+ private static Logger logger;
+
+ @Override
+ public void operationComplete(Future<T> future) throws Exception
+ {
+ if (future.isSuccess() || future.isCancelled())
+ {
+ return;
+ }
+
+ Throwable t = future.cause();
+
+ logger.error("Scheduled operation failed: " + t.toString(), t);
+ }
+
+}
public static ScheduledFuture schedule(Runnable r, long t, TimeUnit unit)
{
- return moo.group.schedule(r, t, unit);
+ ScheduledFuture future = moo.group.schedule(r, t, unit);
+
+ future.addListener(Moo.injector.getInstance(FutureExceptionListener.class));
+
+ return future;
}
public void buildInjector()
import com.google.inject.Provides;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
-import com.google.inject.util.Providers;
import net.rizon.moo.conf.Config;
import net.rizon.moo.events.EventListener;
import net.rizon.moo.injectors.logger.LogTypeListener;
bind(ServerManager.class).toInstance(serverManager);
bind(DatabaseTimer.class).toInstance(new DatabaseTimer());
bind(PluginManager.class).toInstance(pluginManager);
+ bind(FutureExceptionListener.class);
bindListener(Matchers.any(), new LogTypeListener());