Search in sources :

Example 11 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 12 with Subscribe

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

the class BroadcastEventListenerTest method tryBroadcastInMultipleBuses.

@Test
public void tryBroadcastInMultipleBuses() {
    BuckEventBus bus1 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus1"));
    BuckEventBus bus2 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus2"));
    bus1.register(new Object() {

        @Subscribe
        public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
            trackedEvents.add(event);
        }
    });
    bus2.register(new Object() {

        @Subscribe
        public void actionGraphCacheHit(ActionGraphEvent.Cache.Hit event) {
            trackedEvents.add(event);
        }

        @Subscribe
        public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
            trackedEvents.add(event);
        }
    });
    BroadcastEventListener listener = new BroadcastEventListener();
    listener.addEventBus(bus1);
    listener.addEventBus(bus2);
    listener.broadcast(ActionGraphEvent.Cache.hit());
    listener.broadcast(ActionGraphEvent.Cache.miss(/* cacheWasEmpty */
    false));
    assertEquals(countEventsOf(ActionGraphEvent.Cache.Miss.class), 2);
    assertEquals(countEventsOf(ActionGraphEvent.Cache.Hit.class), 1);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Subscribe(com.google.common.eventbus.Subscribe) Test(org.junit.Test)

Example 13 with Subscribe

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

the class ActionGraphCacheTest method setUp.

@Before
public void setUp() {
    // Creates the following target graph:
    //      A
    //     /
    //    B
    nodeB = createTargetNode("B");
    nodeA = createTargetNode("A", nodeB);
    targetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
    eventBus = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)));
    broadcastEventListener = new BroadcastEventListener();
    broadcastEventListener.addEventBus(eventBus);
    eventBus.register(new Object() {

        @Subscribe
        public void actionGraphCacheEvent(ActionGraphEvent.Cache event) {
            trackedEvents.add(event);
        }
    });
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 14 with Subscribe

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

the class ShellStepTest method createContext.

private static ExecutionContext createContext(ImmutableMap<ProcessExecutorParams, FakeProcess> processes, final Console console) throws IOException {
    ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).setProcessExecutor(new FakeProcessExecutor(processes, console)).build();
    context.getBuckEventBus().register(new Object() {

        @Subscribe
        public void logEvent(ConsoleEvent event) throws IOException {
            if (event.getLevel().equals(Level.WARNING)) {
                console.getStdErr().write(event.getMessage().getBytes(Charsets.UTF_8));
            }
        }
    });
    return context;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Subscribe(com.google.common.eventbus.Subscribe) IOException(java.io.IOException)

Example 15 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)

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