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);
}
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());
}
}
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);
}
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);
}
}
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();
}
Aggregations