Package reactor.event.selector

Examples of reactor.event.selector.Selector


        dm.returnsProxy = type.isAssignableFrom(m.getReturnType());

        if(isOn(m)) {
          for(MethodSelectorResolver msr : selectorResolvers) {
            if(msr.supports(m)) {
              Selector sel = msr.apply(m);
              if(null != sel) {
                selectors.put(m, sel);
                dynamicMethods.put(m, dm);
                break;
              }
View Full Code Here


    @SuppressWarnings({"unchecked", "rawtypes"})
    public Object invoke(Object proxy, Method method, final Object[] args) throws Throwable {
      final DynamicMethod dm = dynamicMethods.get(method);

      if(isOn(method)) {
        Selector sel = selectors.get(method);
        if(null == sel) {
          return proxy;
        }

        if(args.length > 1) {
View Full Code Here

    final String jsonPathTmpl = "$.data[?(@.run == %s)]";

    runTest("JsonPath[String]", new Function<Integer, Tuple2<Selector, Object>>() {
      @Override
      public Tuple2<Selector, Object> apply(Integer i) {
        Selector sel = J(String.format(jsonPathTmpl, i));
        String json = String.format(jsonTmpl, i);
        return Tuple.<Selector, Object>of(sel, json);
      }
    });

    runTest("JsonPath[POJO]", new Function<Integer, Tuple2<Selector, Object>>() {
      @Override
      public Tuple2<Selector, Object> apply(Integer i) {
        Selector sel = J(String.format(jsonPathTmpl, i));
        DataNode node = new DataNode(new DataNode.Run(i));
        return Tuple.<Selector, Object>of(sel, node);
      }
    });

    runTest("JsonPath[Map]", new Function<Integer, Tuple2<Selector, Object>>() {
      @Override
      public Tuple2<Selector, Object> apply(Integer i) {
        Selector sel = J(String.format(jsonPathTmpl, i));
        String json = String.format(jsonTmpl, i);
        Object key;
        try {
          key = mapper.readValue(json, Map.class);
        } catch(IOException e) {
          throw new IllegalStateException(e);
        }
        return Tuple.<Selector, Object>of(sel, key);
      }
    });

    runTest("JsonPath[Tree]", new Function<Integer, Tuple2<Selector, Object>>() {
      @Override
      public Tuple2<Selector, Object> apply(Integer i) {
        Selector sel = J(String.format(jsonPathTmpl, i));
        String json = String.format(jsonTmpl, i);
        Object key;
        try {
          key = mapper.readTree(json);
        } catch(IOException e) {
View Full Code Here

  private final Registry<Object> cachingRegistry = new CacheMissCountingCachingRegistry<Object>(cacheMisses);

  @Test
  public void registrationsWithTheSameSelectorAreOrderedByInsertionOrder() {
    String key = "selector";
    Selector selector = Selectors.$(key);

    this.cachingRegistry.register(selector, "echo");
    this.cachingRegistry.register(selector, "bravo");
    this.cachingRegistry.register(selector, "alpha");
    this.cachingRegistry.register(selector, "charlie");
View Full Code Here

  }

  @Test
  public void nonEmptyResultsAreCached() {
    String key = "/**/selector";
    Selector selector = Selectors.uri(key);

    this.cachingRegistry.register(selector, "alpha");

    this.cachingRegistry.select("/test/selector");
    this.cachingRegistry.select("/test/selector");
View Full Code Here

  }

  @Test
  public void cacheIsRefreshedWhenANewRegistrationWithTheSameSelectorIsMade() {
    String key = "selector";
    Selector selector = Selectors.$(key);

    this.cachingRegistry.register(selector, "alpha");

    this.cachingRegistry.select(key);
    this.cachingRegistry.select(key);
View Full Code Here

  }

  //@Test
  public void cacheIsRefreshedWhenANewRegistrationWithADifferentSelectorIsMade() {
    String key1 = "selector";
    Selector selector1 = Selectors.$(key1);

    this.cachingRegistry.register(selector1, "alpha");

    this.cachingRegistry.select(key1);
    this.cachingRegistry.select(key1);

    assertEquals(1, this.cacheMisses.get());

    String key2 = "selector2";
    Selector selector2 = Selectors.$(key2);

    this.cachingRegistry.register(selector2, "bravo");

    this.cachingRegistry.select(key1);
    this.cachingRegistry.select(key1);
View Full Code Here

  }

  @Test
  public void testRelaysEventsToReactor() throws InterruptedException {
    Reactor r = Reactors.reactor().get();
    Selector key = Selectors.$();

    final CountDownLatch latch = new CountDownLatch(5);
    final Tap<Event<Integer>> tap = new Tap<Event<Integer>>() {
      @Override
      public void accept(Event<Integer> integerEvent) {
        super.accept(integerEvent);
        latch.countDown();
      }
    };

    r.on(key, tap);

    Stream<String> stream = Streams.just("1", "2", "3", "4", "5");
    Stream<Void> s =
        stream
            .map(STRING_2_INTEGER)
            .notify(key.getObject(), r);
    System.out.println(s.debug());

    //await(s, is(5));
    assertThat("latch was counted down", latch.getCount(), is(0l));
    assertThat("value is 5", tap.get().getData(), is(5));
View Full Code Here

  //Issue : https://github.com/reactor/reactor/issues/237
  @Test
  public void invokeConsumersWithCustomSelector() {

    Subscription sub1 = new Subscription("client1", "test");
    Selector s1 = new MySelector(sub1);

    // consumer1
    this.cachingRegistry.register(s1, "pseudo-consumer-1");

    // notify1
    List<Registration<?>> registrations = this.cachingRegistry.select("test");

    assertEquals( "number of consumers incorrect", 1, registrations.size());


    // consumer2
    this.cachingRegistry.register(s1, "pseudo-consumer-2");

    // consumer3
    Subscription sub2 = new Subscription("client2", "test");
    Selector s2 = new MySelector(sub2);
    this.cachingRegistry.register(s2, "pseudo-consumer-3");

    //consumer 4
    Subscription sub3 = new Subscription("client2", "test2");
    Selector s3 = new MySelector(sub3);
    this.cachingRegistry.register(s3, "pseudo-consumer-4");

    //prepopulate and add another consumer
    this.cachingRegistry.select("test2");
    this.cachingRegistry.register(s3, "pseudo-consumer-5");
View Full Code Here

  }

  @Override
  public Promise<IN> sendAndReceive(OUT data) {
    final Promise<IN> d = Promises.defer(env, eventsReactor.getDispatcher());
    Selector sel = $();
    eventsReactor.on(sel, new EventConsumer<IN>(d)).cancelAfterUse();
    replyToKeys.add(sel.getObject());
    send(data, null);
    return d;
  }
View Full Code Here

TOP

Related Classes of reactor.event.selector.Selector

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.