Updated documentation for GuavaEventBusHijacker and ReportingEventBus

This commit is contained in:
OLEGSHA 2021-03-25 17:15:03 +03:00
parent f28c765e3f
commit ef572c43c7
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
2 changed files with 26 additions and 11 deletions

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.windcorp.progressia.common.hacks;
import java.lang.reflect.Constructor;
@ -29,15 +29,14 @@ import com.google.common.util.concurrent.MoreExecutors;
import ru.windcorp.progressia.common.util.crash.CrashReports;
/**
* This class had to be written because there is not legal way to instantiate a
* non-async
* {@link EventBus} with both a custom identifier and a custom exception
* handler. Which
* is a shame. Guava maintainers know about the issue but have rejected
* solutions multiple
* times <em>without a clearly stated reason</em>; looks like some dirty
* reflection will
* have to do.
* This class had to be written because there is no legal way to instantiate a
* non-async {@link EventBus} with both a custom identifier and a custom
* exception handler. Which is a shame. Guava maintainers know about the issue
* but have rejected solutions multiple times <em>without a clearly stated
* reason</em>; looks like some dirty reflection will have to do.
* <p>
* When explicitly referencing this class, please mention its usage in
* implementation notes because it is unreliable long-term.
*
* @author javapony
*/

View File

@ -15,18 +15,34 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ru.windcorp.progressia.common.util.crash;
import com.google.common.eventbus.EventBus;
import ru.windcorp.progressia.common.hacks.GuavaEventBusHijacker;
/**
* A utility for creating Guava's {@link EventBus}es that
* {@linkplain CrashReports report} exceptions instead of suppressing them.
*
* @author javapony
*/
public class ReportingEventBus {
private ReportingEventBus() {
}
/**
* Instantiates a new {@link EventBus} with the provided identifier that
* reports any unhandled exceptions with {@link CrashReports}.
*
* @param identifier the identifier of the new bus
* @return the created event bus
* @implNote This implementation relies on {@link GuavaEventBusHijacker} for
* creating buses with custom identifiers and uncaught exception
* handlers. It may break suddenly with a Guava update.
*/
public static EventBus create(String identifier) {
return GuavaEventBusHijacker.newEventBus(
identifier,