Search in sources :

Example 41 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 42 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 43 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 44 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 45 with Subscribe

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());
    }
}
Also used : TransactionLog(com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLog) SQLException(java.sql.SQLException) TransactionLogStorage(com.dangdang.ddframe.rdb.transaction.soft.storage.TransactionLogStorage) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) BEDSoftTransaction(com.dangdang.ddframe.rdb.transaction.soft.bed.BEDSoftTransaction) SoftTransactionConfiguration(com.dangdang.ddframe.rdb.transaction.soft.api.config.SoftTransactionConfiguration) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) 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