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);
}
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);
}
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);
}
});
}
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;
}
use of com.google.common.eventbus.Subscribe in project sharding-jdbc by dangdangdotcom.
the class BestEffortsDeliveryListener method listen.
@Subscribe
@AllowConcurrentEvents
public void listen(final DMLExecutionEvent event) {
if (!isProcessContinuously()) {
return;
}
SoftTransactionConfiguration transactionConfig = SoftTransactionManager.getCurrentTransactionConfiguration().get();
TransactionLogStorage transactionLogStorage = TransactionLogStorageFactory.createTransactionLogStorage(transactionConfig.buildTransactionLogDataSource());
BEDSoftTransaction bedSoftTransaction = (BEDSoftTransaction) SoftTransactionManager.getCurrentTransaction().get();
switch(event.getEventExecutionType()) {
case BEFORE_EXECUTE:
//TODO 对于批量执行的SQL需要解析成两层列表
transactionLogStorage.add(new TransactionLog(event.getId(), bedSoftTransaction.getTransactionId(), bedSoftTransaction.getTransactionType(), event.getDataSource(), event.getSql(), event.getParameters(), System.currentTimeMillis(), 0));
return;
case EXECUTE_SUCCESS:
transactionLogStorage.remove(event.getId());
return;
case EXECUTE_FAILURE:
boolean deliverySuccess = false;
for (int i = 0; i < transactionConfig.getSyncMaxDeliveryTryTimes(); i++) {
if (deliverySuccess) {
return;
}
boolean isNewConnection = false;
Connection conn = null;
PreparedStatement preparedStatement = null;
try {
conn = bedSoftTransaction.getConnection().getConnection(event.getDataSource(), SQLStatementType.UPDATE);
if (!isValidConnection(conn)) {
bedSoftTransaction.getConnection().releaseBrokenConnection(conn);
conn = bedSoftTransaction.getConnection().getConnection(event.getDataSource(), SQLStatementType.UPDATE);
isNewConnection = true;
}
preparedStatement = conn.prepareStatement(event.getSql());
//TODO 对于批量事件需要解析成两层列表
for (int parameterIndex = 0; parameterIndex < event.getParameters().size(); parameterIndex++) {
preparedStatement.setObject(parameterIndex + 1, event.getParameters().get(parameterIndex));
}
preparedStatement.executeUpdate();
deliverySuccess = true;
transactionLogStorage.remove(event.getId());
} catch (final SQLException ex) {
log.error(String.format("Delivery times %s error, max try times is %s", i + 1, transactionConfig.getSyncMaxDeliveryTryTimes()), ex);
} finally {
close(isNewConnection, conn, preparedStatement);
}
}
return;
default:
throw new UnsupportedOperationException(event.getEventExecutionType().toString());
}
}
Aggregations