Package com.google.common.eventbus

Examples of com.google.common.eventbus.EventBus$EventWithHandler


public class GFacNotifier {
    private EventBus eventBus;

    public GFacNotifier(){
        eventBus = new EventBus();
    }
View Full Code Here


    private static EventBus bus;

    private static EventBus bus() {
        if (bus == null) {
            bus = new EventBus("erlide");
            bus.register(new ErlideEventBus());
        }
        return bus;
    }
View Full Code Here

    private EventBus eventBus;
    private Class<?> listenerInterface;

    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        EventBus resolvedEventBus = eventBus;
        if (resolvedEventBus == null) {
            resolvedEventBus = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, EventBus.class);
        }

        return new GuavaEventBusEndpoint(uri, this, resolvedEventBus, listenerInterface);
View Full Code Here

    @Test(expected = IllegalStateException.class)
    public void shouldForwardMessageToCamel() throws Exception {
        // Given
        SimpleRegistry registry = new SimpleRegistry();
        registry.put("eventBus", new EventBus());
        CamelContext context = new DefaultCamelContext(registry);
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("guava-eventbus:eventBus?listenerInterface=org.apache.camel.component.guava.eventbus.CustomListener&eventClass=org.apache.camel.component.guava.eventbus.MessageWrapper").
View Full Code Here

    private int numberLongEvents = 10;


    @Before
    public void setUp() {
        eventBus = new EventBus();
        deadEventSubscriber = new DeadEventSubscriber();
        eventBus.register(deadEventSubscriber);
        eventPublisher = new EventPublisher(eventBus);
        cashPurchaseEventSubscriber = new CashPurchaseEventSubscriber(eventBus);
        creditPurchaseEventSubscriber = new CreditPurchaseEventSubscriber(eventBus);
View Full Code Here

    // Process test classes and resources.
    long start = System.currentTimeMillis();   
    final List<String> testClassNames = processTestResources();

    final EventBus aggregatedBus = new EventBus("aggregated");
    final TestsSummaryEventListener summaryListener = new TestsSummaryEventListener();
    aggregatedBus.register(summaryListener);
   
    for (Object o : listeners) {
      if (o instanceof ProjectComponent) {
        ((ProjectComponent) o).setProject(getProject());
      }
      if (o instanceof AggregatedEventListener) {
        ((AggregatedEventListener) o).setOuter(this);
      }
      aggregatedBus.register(o);
    }

    if (testClassNames.isEmpty()) {
      aggregatedBus.post(new AggregatedQuitEvent());
    } else {
      start = System.currentTimeMillis();
     
      final int slaveCount = determineSlaveCount(testClassNames.size());
      final List<SlaveInfo> slaveInfos = Lists.newArrayList();
      for (int slave = 0; slave < slaveCount; slave++) {
        final SlaveInfo slaveInfo = new SlaveInfo(slave, slaveCount);
        slaveInfos.add(slaveInfo);
      }

      // Order test class names identically for balancers.
      Collections.sort(testClassNames);
     
      // Prepare a pool of suites dynamically dispatched to slaves as they become idle.
      final Deque<String> stealingQueue =
          new ArrayDeque<String>(loadBalanceSuites(slaveInfos, testClassNames, balancers));
      aggregatedBus.register(new Object() {
        @Subscribe @SuppressWarnings("unused")
        public void onSlaveIdle(SlaveIdle slave) {
          if (stealingQueue.isEmpty()) {
            slave.finished();
          } else {
            String suiteName = stealingQueue.pop();
            slave.newSuite(suiteName);
          }
        }
      });

      // Create callables for the executor.
      final List<Callable<Void>> slaves = Lists.newArrayList();
      for (int slave = 0; slave < slaveCount; slave++) {
        final SlaveInfo slaveInfo = slaveInfos.get(slave);
        slaves.add(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            executeSlave(slaveInfo, aggregatedBus);
            return null;
          }
        });
      }

      ExecutorService executor = Executors.newCachedThreadPool();
      aggregatedBus.post(new AggregatedStartEvent(slaves.size(), testClassNames.size()));

      try {
        List<Future<Void>> all = executor.invokeAll(slaves);
        executor.shutdown();

        for (int i = 0; i < slaves.size(); i++) {
          Future<Void> f = all.get(i);
          try {
            f.get();
          } catch (ExecutionException e) {
            slaveInfos.get(i).executionError = e.getCause();
          }
        }
      } catch (InterruptedException e) {
        log("Master interrupted? Weird.", Project.MSG_ERR);
      }
      aggregatedBus.post(new AggregatedQuitEvent());

      for (SlaveInfo si : slaveInfos) {
        if (si.start > 0 && si.end > 0) {
          log(String.format(Locale.ENGLISH, "JVM J%d: %8.2f .. %8.2f = %8.2fs",
              si.id,
View Full Code Here

    log("Forked JVM process command line (may need escape sequences for your shell):\n" +
        slave.slaveCommandLine, Project.MSG_VERBOSE);

    commandline.createArgument().setValue(SlaveMain.OPTION_STDIN);

    final EventBus eventBus = new EventBus("slave-" + slave.id);
    final DiagnosticsListener diagnosticsListener = new DiagnosticsListener(slave, this);
    eventBus.register(diagnosticsListener);
    eventBus.register(new AggregatingListener(aggregatedBus, slave));

    final AtomicReference<Charset> clientCharset = new AtomicReference<Charset>();
    final AtomicBoolean clientWithLimitedCharset = new AtomicBoolean();
    final PrintWriter w = new PrintWriter(Files.newWriter(classNamesDynamic, Charsets.UTF_8));
    eventBus.register(new Object() {
      @SuppressWarnings("unused")
      @Subscribe
      public void onIdleSlave(final SlaveIdle idleSlave) {
        aggregatedBus.post(new SlaveIdle() {
          @Override
View Full Code Here

    // Process test classes and resources.
    long start = System.currentTimeMillis();   
    final TestsCollection testCollection = processTestResources();

    final EventBus aggregatedBus = new EventBus("aggregated");
    final TestsSummaryEventListener summaryListener = new TestsSummaryEventListener();
    aggregatedBus.register(summaryListener);
   
    for (Object o : listeners) {
      if (o instanceof ProjectComponent) {
        ((ProjectComponent) o).setProject(getProject());
      }
      if (o instanceof AggregatedEventListener) {
        ((AggregatedEventListener) o).setOuter(this);
      }
      aggregatedBus.register(o);
    }

    if (testCollection.testClasses.isEmpty()) {
      aggregatedBus.post(new AggregatedQuitEvent());
    } else {
      start = System.currentTimeMillis();

      // Check if we allow duplicate suite names. Some reports (ANT compatible XML
      // reports) will have a problem with duplicate suite names, for example.
      if (uniqueSuiteNames) {
        testCollection.onlyUniqueSuiteNames();
      }

      final int jvmCount = determineForkedJvmCount(testCollection);
      final List<ForkedJvmInfo> slaveInfos = Lists.newArrayList();
      for (int jvmid = 0; jvmid < jvmCount; jvmid++) {
        final ForkedJvmInfo slaveInfo = new ForkedJvmInfo(jvmid, jvmCount);
        slaveInfos.add(slaveInfo);
      }

     
      if (jvmCount > 1 && uniqueSuiteNames && testCollection.hasReplicatedSuites()) {
        throw new BuildException(String.format(Locale.ENGLISH,
            "There are test suites that request JVM replication and the number of forked JVMs %d is larger than 1. Run on a single JVM.",
            jvmCount));
      }

      // Prepare a pool of suites dynamically dispatched to slaves as they become idle.
      final Deque<String> stealingQueue =
          new ArrayDeque<String>(loadBalanceSuites(slaveInfos, testCollection, balancers));
      aggregatedBus.register(new Object() {
        @Subscribe
        public void onSlaveIdle(SlaveIdle slave) {
          if (stealingQueue.isEmpty()) {
            slave.finished();
          } else {
            String suiteName = stealingQueue.pop();
            slave.newSuite(suiteName);
          }
        }
      });
     
      // Check for filtering expressions.
      @SuppressWarnings("unchecked")
      Vector<Variable> vv = getCommandline().getSystemProperties().getVariablesVector();
      for (Variable v : vv) {
        if (SysGlobals.SYSPROP_TESTFILTER().equals(v.getKey())) {
          try {
            Node root = new FilterExpressionParser().parse(v.getValue());
            log("Parsed test filtering expression: " + root.toExpression(), Project.MSG_INFO);
          } catch (Exception e) {
            log("Could not parse filtering expression: " + v.getValue(), Project.MSG_WARN);
          }
        }
      }

      // Create callables for the executor.
      final List<Callable<Void>> slaves = Lists.newArrayList();
      for (int slave = 0; slave < jvmCount; slave++) {
        final ForkedJvmInfo slaveInfo = slaveInfos.get(slave);
        slaves.add(new Callable<Void>() {
          @Override
          public Void call() throws Exception {
            executeSlave(slaveInfo, aggregatedBus);
            return null;
          }
        });
      }

      ExecutorService executor = Executors.newCachedThreadPool();
      aggregatedBus.post(new AggregatedStartEvent(slaves.size(),
          // TODO: this doesn't account for replicated suites.
          testCollection.testClasses.size()));

      try {
        List<Future<Void>> all = executor.invokeAll(slaves);
        executor.shutdown();

        for (int i = 0; i < slaves.size(); i++) {
          Future<Void> f = all.get(i);
          try {
            f.get();
          } catch (ExecutionException e) {
            slaveInfos.get(i).executionError = e.getCause();
          }
        }
      } catch (InterruptedException e) {
        log("Master interrupted? Weird.", Project.MSG_ERR);
      }
      aggregatedBus.post(new AggregatedQuitEvent());

      for (ForkedJvmInfo si : slaveInfos) {
        if (si.start > 0 && si.end > 0) {
          log(String.format(Locale.ENGLISH, "JVM J%d: %8.2f .. %8.2f = %8.2fs",
              si.id,
View Full Code Here

    log("Forked JVM process command line (may need escape sequences for your shell):\n" +
        slave.slaveCommandLine, Project.MSG_VERBOSE);

    commandline.createArgument().setValue(SlaveMain.OPTION_STDIN);

    final EventBus eventBus = new EventBus("slave-" + slave.id);
    final DiagnosticsListener diagnosticsListener = new DiagnosticsListener(slave, this);
    eventBus.register(diagnosticsListener);
    eventBus.register(new AggregatingListener(aggregatedBus, slave));

    final AtomicReference<Charset> clientCharset = new AtomicReference<Charset>();
    final AtomicBoolean clientWithLimitedCharset = new AtomicBoolean();
    final PrintWriter w = new PrintWriter(Files.newWriter(classNamesDynamic, Charsets.UTF_8));
    eventBus.register(new Object() {
      @Subscribe
      public void onIdleSlave(final SlaveIdle idleSlave) {
        aggregatedBus.post(new SlaveIdle() {
          @Override
          public void finished() {
View Full Code Here

    * Provides asynchronous {@link EventBus}.
    */
   @Provides
   @Singleton
   EventBus provideSyncEventBus(DeadEventLoggingHandler deadEventsHandler) { // NO_UCD
      EventBus syncBus = new EventBus("jclouds-sync-event-bus");
      syncBus.register(deadEventsHandler);
      return syncBus;
   }
View Full Code Here

TOP

Related Classes of com.google.common.eventbus.EventBus$EventWithHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.