/** * Generic version of Selectors.predicate() * @param p * @return */ public static <T> Selector<T> typedPredicate(final Predicate<T> p) { Predicate<Object> x = new Predicate<Object>() { @Override public boolean test(Object t) { if (t != null) { try { return p.test((T) t); } catch (ClassCastException e) { // Not really a problem. Due to Java's type erasure, // can't do an instnaceof check, so this will // have to do. } } return false; } }; return Selectors.predicate(x); }
public static Selector anySQSMessage() { return Selectors.type(SQSMessage.class); }
/** * A short-hand alias for {@link Selectors#anonymous()}. * <p/> * Creates an anonymous {@link Selector}. * * @return a new Selector * * @see ObjectSelector */ public static Selector $() { return anonymous(); }
/** * Creates an anonymous {@link Selector}. * * @return a new Selector * * @see ObjectSelector */ public static Selector anonymous() { Object obj = new AnonymousKey(); return $(obj); }
/** * A short-hand alias for {@link Selectors#object}. * <p/> * Creates a {@link Selector} based on the given object. * * @param obj * The object to use for matching * * @return The new {@link ObjectSelector}. * * @see ObjectSelector */ public static <T> Selector<T> $(T obj) { return object(obj); }
/** * A short-hand alias for {@link Selectors#uri(String)}. * <p/> * Creates a {@link Selector} based on a URI template. * * @param uri * The string to compile into a URI template and use for matching * * @return The new {@link UriPathSelector}. * * @see UriPathTemplate * @see UriPathSelector */ public static Selector U(String uri) { return uri(uri); }
/** * Creates a {@link Selector} based on the given string format and arguments. * * @param fmt * The {@code String.format} style format specification * @param args * The format args * * @return The new {@link ObjectSelector}. * * @see ObjectSelector * @see String#format(String, Object...) */ public static Selector $(String fmt, Object... args) { return object(String.format(fmt, args)); }
@Override public void register(String eventName, Object eventHandler) { if (eventHandler == null) { throw new NullPointerException(); } if (eventHandler instanceof EventListener) { r.<Event> on($(eventName), new DefaultConsumerAdatper((EventListener) eventHandler)); return; } Method method = resolveMethod(eventHandler); r.<Event> on($(eventName), new ReflectedConsumerAdatper(eventHandler, method)); }
public static Selector streamArn(String arn) { return Selectors.predicate(it -> { if (it instanceof KinesisRecord) { KinesisRecord kr = (KinesisRecord) it; return arn.equals(kr.getStreamArn()); } return false; }); }
public static Selector anyKinesisRecord() { return Selectors.type(KinesisRecord.class); }
/** * Register the given {@link reactor.fn.Consumer} on an anonymous {@link reactor.bus.selector.Selector} and * set the given event's {@code replyTo} property to the corresponding anonymous key, then register the consumer to * receive replies from the {@link reactor.fn.Function} assigned to handle the given key. * * @param key The key to be matched by {@link Selector Selectors} * @param event The event to notify. * @param reply The consumer to register as a reply handler. * @return {@literal this} */ public <T extends Event<?>> EventBus sendAndReceive(Object key, Event<?> event, Consumer<T> reply) { Selector sel = Selectors.anonymous(); on(sel, reply).cancelAfterUse(); notify(key, event.setReplyTo(sel.getObject())); return this; }
@Override public void start() { if (isRunning()) { return; } synchronized (monitor) { reg = eventBus.on(Selectors.$(selector), ev -> handleEvent(ev)); running = true; } }
public static Selector queueName(String name) { return Selectors.predicate(it -> { if (it instanceof SQSMessage) { return ((SQSMessage) it).getUrl().endsWith("/" + name); } return false; }); } }
public static Selector anySNSMessageSelector() { return Selectors.type(SNSMessage.class); }
@Override public void start() { if (isRunning()) { return; } synchronized (monitor) { reg = eventBus.on(Selectors.$(selector), ev -> handleEvent(ev)); running = true; } }
public Selector eventsFromBridgeSelector() { return Selectors.predicate(p -> { if (p instanceof SQSMessage) { return ((SQSMessage) p).getBridge() == this; } return false; }); } }
/** * A short-hand alias for {@link Selectors#type(Class)}. * <p/> * Creates a {@link Selector} based on the given class type that matches objects whose type is * assignable according to {@link Class#isAssignableFrom(Class)}. * * @param supertype * The supertype to compare. * * @return The new {@link ClassSelector}. * * @see ClassSelector */ public static ClassSelector T(Class<?> supertype) { return type(supertype); }
public static Selector streamName(String name) { return Selectors.predicate(it -> { if (it instanceof KinesisRecord) { KinesisRecord kr = (KinesisRecord) it; return kr.getStreamName().equals(name); } return false; }); } }
public Selector eventsFromBridgeSelector() { return Selectors.predicate(p -> { if (p instanceof KinesisRecord) { return ((KinesisRecord) p).getBridge() == this; } return false; }); }