Search in sources :

Example 36 with Subscribe

use of com.google.common.eventbus.Subscribe in project buck by facebook.

the class ChromeTraceBuildListener method processResourceConsumption.

@Subscribe
public void processResourceConsumption(ProcessTracker.ProcessResourceConsumptionEvent event) {
    Optional<ProcessResourceConsumption> resourceConsumption = event.getResourceConsumption();
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.put("executable", event.getExecutableName());
    if (event.getContext().isPresent()) {
        builder.put("context", event.getContext().get().toString());
    }
    if (resourceConsumption.isPresent()) {
        ProcessResourceConsumption res = resourceConsumption.get();
        builder.put("mem_size_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getMemSize())));
        builder.put("mem_resident_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getMemResident())));
        builder.put("cpu_real_ms", Long.toString(res.getCpuReal()));
        builder.put("cpu_user_ms", Long.toString(res.getCpuUser()));
        builder.put("cpu_sys_ms", Long.toString(res.getCpuSys()));
        builder.put("bytes_read_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getIoBytesRead())));
        builder.put("bytes_written_mb", Long.toString(SizeUnit.BYTES.toMegabytes(res.getIoBytesWritten())));
    }
    writeChromeTraceEvent("perf", "process", ChromeTraceEvent.Phase.COUNTER, builder.build(), event);
}
Also used : ProcessResourceConsumption(com.facebook.buck.util.ProcessResourceConsumption) ImmutableMap(com.google.common.collect.ImmutableMap) Subscribe(com.google.common.eventbus.Subscribe)

Example 37 with Subscribe

use of com.google.common.eventbus.Subscribe in project killbill by killbill.

the class PushNotificationListener method triggerPushNotifications.

@AllowConcurrentEvents
@Subscribe
public void triggerPushNotifications(final ExtBusEvent event) {
    final TenantContext context = contextFactory.createTenantContext(event.getTenantId());
    try {
        final List<String> callbacks = getCallbacksForTenant(context);
        if (callbacks.isEmpty()) {
            // Optimization - see https://github.com/killbill/killbill/issues/297
            return;
        }
        dispatchCallback(event.getTenantId(), event, callbacks);
    } catch (final TenantApiException e) {
        log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
    } catch (final IOException e) {
        log.warn("Failed to retrieve push notification callback for tenant {}", event.getTenantId());
    }
}
Also used : TenantApiException(org.killbill.billing.tenant.api.TenantApiException) InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) TenantContext(org.killbill.billing.util.callcontext.TenantContext) IOException(java.io.IOException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 38 with Subscribe

use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.

the class ForgeModContainer method modConstruction.

@Subscribe
public void modConstruction(FMLConstructionEvent evt) {
    List<String> all = Lists.newArrayList();
    for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashReportDetail.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    for (ASMData asm : evt.getASMHarvestedData().getAll(ICrashCallable.class.getName().replace('.', '/'))) all.add(asm.getClassName());
    Iterator<String> itr = all.iterator();
    while (itr.hasNext()) {
        String cls = itr.next();
        if (!cls.startsWith("net/minecraft/") && !cls.startsWith("net/minecraftforge/"))
            itr.remove();
    }
    FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "Preloading CrashReport Classes");
    //Sort it because I like pretty output ;)
    Collections.sort(all);
    for (String name : all) {
        FMLLog.log(ForgeVersion.MOD_ID, Level.DEBUG, "\t" + name);
        try {
            Class.forName(name.replace('/', '.'), false, MinecraftForge.class.getClassLoader());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    NetworkRegistry.INSTANCE.register(this, this.getClass(), "*", evt.getASMHarvestedData());
    ForgeNetworkHandler.registerChannel(this, evt.getSide());
    ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
}
Also used : ASMData(net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData) MalformedURLException(java.net.MalformedURLException) Subscribe(com.google.common.eventbus.Subscribe)

Example 39 with Subscribe

use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.

the class FMLModContainer method constructMod.

@Subscribe
public void constructMod(FMLConstructionEvent event) {
    try {
        BlamingTransformer.addClasses(getModId(), candidate.getClassList());
        ModClassLoader modClassLoader = event.getModClassLoader();
        modClassLoader.addFile(source);
        modClassLoader.clearNegativeCacheFor(candidate.getClassList());
        //Only place I could think to add this...
        MinecraftForge.preloadCrashClasses(event.getASMHarvestedData(), getModId(), candidate.getClassList());
        Class<?> clazz = Class.forName(className, true, modClassLoader);
        Certificate[] certificates = clazz.getProtectionDomain().getCodeSource().getCertificates();
        int len = 0;
        if (certificates != null) {
            len = certificates.length;
        }
        Builder<String> certBuilder = ImmutableList.builder();
        for (int i = 0; i < len; i++) {
            certBuilder.add(CertificateHelper.getFingerprint(certificates[i]));
        }
        ImmutableList<String> certList = certBuilder.build();
        sourceFingerprints = ImmutableSet.copyOf(certList);
        String expectedFingerprint = (String) descriptor.get("certificateFingerprint");
        fingerprintNotPresent = true;
        if (expectedFingerprint != null && !expectedFingerprint.isEmpty()) {
            if (!sourceFingerprints.contains(expectedFingerprint)) {
                Level warnLevel = Level.ERROR;
                if (source.isDirectory()) {
                    warnLevel = Level.TRACE;
                }
                FMLLog.log(getModId(), warnLevel, "The mod %s is expecting signature %s for source %s, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName());
            } else {
                certificate = certificates[certList.indexOf(expectedFingerprint)];
                fingerprintNotPresent = false;
            }
        }
        @SuppressWarnings("unchecked") List<Map<String, Object>> props = (List<Map<String, Object>>) descriptor.get("customProperties");
        if (props != null) {
            com.google.common.collect.ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
            for (Map<String, Object> p : props) {
                builder.put((String) p.get("k"), (String) p.get("v"));
            }
            customModProperties = builder.build();
        } else {
            customModProperties = EMPTY_PROPERTIES;
        }
        Boolean hasDisableableFlag = (Boolean) descriptor.get("canBeDeactivated");
        boolean hasReverseDepends = !event.getReverseDependencies().get(getModId()).isEmpty();
        if (hasDisableableFlag != null && hasDisableableFlag) {
            disableability = hasReverseDepends ? Disableable.DEPENDENCIES : Disableable.YES;
        } else {
            disableability = hasReverseDepends ? Disableable.DEPENDENCIES : Disableable.RESTART;
        }
        Method factoryMethod = gatherAnnotations(clazz);
        modInstance = getLanguageAdapter().getNewInstance(this, clazz, modClassLoader, factoryMethod);
        NetworkRegistry.INSTANCE.register(this, clazz, (String) (descriptor.containsKey("acceptableRemoteVersions") ? descriptor.get("acceptableRemoteVersions") : null), event.getASMHarvestedData());
        if (fingerprintNotPresent) {
            eventBus.post(new FMLFingerprintViolationEvent(source.isDirectory(), source, ImmutableSet.copyOf(this.sourceFingerprints), expectedFingerprint));
        }
        ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), getLanguageAdapter());
        AutomaticEventSubscriber.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
        ConfigManager.load(this.getModId(), Config.Type.INSTANCE);
        processFieldAnnotations(event.getASMHarvestedData());
    } catch (Throwable e) {
        controller.errorOccurred(this, e);
    }
}
Also used : FMLFingerprintViolationEvent(net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent) Method(java.lang.reflect.Method) ImmutableMap(com.google.common.collect.ImmutableMap) Level(org.apache.logging.log4j.Level) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Certificate(java.security.cert.Certificate) Subscribe(com.google.common.eventbus.Subscribe)

Example 40 with Subscribe

use of com.google.common.eventbus.Subscribe in project MinecraftForge by MinecraftForge.

the class LoadController method buildModList.

@Subscribe
public void buildModList(FMLLoadEvent event) {
    Builder<String, EventBus> eventBus = ImmutableMap.builder();
    for (final ModContainer mod : loader.getModList()) {
        //Create mod logger, and make the EventBus logger a child of it.
        EventBus bus = new EventBus(new SubscriberExceptionHandler() {

            @Override
            public void handleException(final Throwable exception, final SubscriberExceptionContext context) {
                LoadController.this.errorOccurred(mod, exception);
            }
        });
        boolean isActive = mod.registerBus(bus, this);
        if (isActive) {
            activeModList.add(mod);
            modStates.put(mod.getModId(), ModState.UNLOADED);
            eventBus.put(mod.getModId(), bus);
            FMLCommonHandler.instance().addModToResourcePack(mod);
        } else {
            FMLLog.log(mod.getModId(), Level.WARN, "Mod %s has been disabled through configuration", mod.getModId());
            modStates.put(mod.getModId(), ModState.UNLOADED);
            modStates.put(mod.getModId(), ModState.DISABLED);
        }
        modNames.put(mod.getModId(), mod.getName());
    }
    eventChannels = eventBus.build();
}
Also used : SubscriberExceptionHandler(com.google.common.eventbus.SubscriberExceptionHandler) SubscriberExceptionContext(com.google.common.eventbus.SubscriberExceptionContext) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)179 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)46 SimpleCommand (net.kodehawa.mantarobot.core.modules.commands.SimpleCommand)44 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)29 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)26 MantaroData (net.kodehawa.mantarobot.data.MantaroData)25 List (java.util.List)23 Category (net.kodehawa.mantarobot.core.modules.commands.base.Category)22 Utils (net.kodehawa.mantarobot.utils.Utils)22 CommandRegistry (net.kodehawa.mantarobot.core.CommandRegistry)21 Module (net.kodehawa.mantarobot.core.modules.Module)21 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)18 TimeUnit (java.util.concurrent.TimeUnit)16 Collectors (java.util.stream.Collectors)16 MantaroBot (net.kodehawa.mantarobot.MantaroBot)15 Player (net.kodehawa.mantarobot.db.entities.Player)15 DiscordUtils (net.kodehawa.mantarobot.utils.DiscordUtils)15 RateLimiter (net.kodehawa.mantarobot.utils.commands.RateLimiter)14 SubCommand (net.kodehawa.mantarobot.core.modules.commands.SubCommand)13 DBGuild (net.kodehawa.mantarobot.db.entities.DBGuild)13