Search in sources :

Example 16 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 17 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)

Example 18 with Subscribe

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

the class LoadController method propogateStateMessage.

@Subscribe
public void propogateStateMessage(FMLEvent stateEvent) {
    if (stateEvent instanceof FMLPreInitializationEvent) {
        modObjectList = buildModObjectList();
    }
    ProgressBar bar = ProgressManager.push(stateEvent.description(), activeModList.size(), true);
    for (ModContainer mc : activeModList) {
        bar.step(mc.getName());
        sendEventToModContainer(stateEvent, mc);
    }
    ProgressManager.pop(bar);
}
Also used : FMLPreInitializationEvent(net.minecraftforge.fml.common.event.FMLPreInitializationEvent) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar) Subscribe(com.google.common.eventbus.Subscribe)

Example 19 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 20 with Subscribe

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

the class AggregatingListener method slowHeartBeat.

/**
   * Detect slow heartbeat (long time without any events) from the forked JVM.
   */
@Subscribe
public void slowHeartBeat(LowLevelHeartBeatEvent e) {
    Description current = null;
    if (tests != null && !tests.isEmpty()) {
        current = tests.peek().getDescription();
    } else {
        // may be null.
        current = lastSuite;
    }
    target.post(new HeartBeatEvent(slave, current, e.lastActivity, e.currentTime));
}
Also used : Description(org.junit.runner.Description) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Subscribe (com.google.common.eventbus.Subscribe)115 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)13 EventBus (com.google.common.eventbus.EventBus)11 BuckEventBus (com.facebook.buck.event.BuckEventBus)10 Test (org.junit.Test)10 UPID (com.groupon.mesos.util.UPID)8 Scheduler (org.apache.mesos.Scheduler)8 SchedulerDriver (org.apache.mesos.SchedulerDriver)8 IOException (java.io.IOException)7 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)7 FakeClock (com.facebook.buck.timing.FakeClock)6 ArrayList (java.util.ArrayList)6 LogRecord (java.util.logging.LogRecord)6 Description (org.junit.runner.Description)6 WatchEvent (java.nio.file.WatchEvent)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)5 EventKey (com.facebook.buck.event.EventKey)4 Action (com.google.devtools.build.lib.actions.Action)4 File (java.io.File)4 UUID (java.util.UUID)4