rx.subjects.SerializedSubject Java Examples
The following examples show how to use
rx.subjects.SerializedSubject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Example_8_Model.java From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 | 6 votes |
public Observable<LogRow> getLogs() { SerializedSubject<LogRow, LogRow> subject = new SerializedSubject<>(PublishSubject.create()); ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat(Example_8_Model.class.getSimpleName() + "-thread-%d").build(); final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), threadFactory); IntStream.range(1, Runtime.getRuntime().availableProcessors() + 1).forEach(value -> { executorService.submit(() -> { SysOutUtils.sysout(Thread.currentThread().getName() + " will briefly start creating lots of log rows..."); VariousUtils.sleep(1000); long incrementingNumber = 1; while (true) { subject.onNext(new LogRow( DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now()), "Status " + Integer.toString(ThreadLocalRandom.current().nextInt(1, 5)), "Action " + incrementingNumber + " from " + Thread.currentThread().getName())); } }); }); return subject; }
Example #2
Source File: RXBus.java From RXBus with Apache License 2.0 | 6 votes |
/** * Sends an event to the bus * <p> * @param event the event that should be broadcasted to the bus * @param key the key this event should be broadcasted to * @param sendToDefaultBusAsWell if true, all observers of the event class will receive this event as well */ public synchronized <T> void sendEvent(T event, String key, boolean sendToDefaultBusAsWell) { RXBusEventIsNullException.checkEvent(event); RXBusKeyIsNullException.checkKey(key); // 1) send to key bound bus SerializedSubject subject = getSubject(new RXQueueKey(event.getClass(), key), false); // only send event, if subject exists => this means someone has at least once subscribed to it if (subject != null) subject.onNext(event); // 2) send to unbound bus if (sendToDefaultBusAsWell) sendEvent(event); }
Example #3
Source File: RXBus.java From RXBus with Apache License 2.0 | 6 votes |
/** * Sends an event to the bus * <p> * @param event the event that should be broadcasted to the bus * @param key the key this event should be broadcasted to * @param sendToDefaultBusAsWell if true, all observers of the event class will receive this event as well */ public synchronized <T> void sendEvent(T event, Integer key, boolean sendToDefaultBusAsWell) { RXBusEventIsNullException.checkEvent(event); RXBusKeyIsNullException.checkKey(key); // 1) send to key bound bus SerializedSubject subject = getSubject(new RXQueueKey(event.getClass(), key), false); // only send event, if subject exists => this means someone has at least once subscribed to it if (subject != null) subject.onNext(event); // 2) send to unbound bus if (sendToDefaultBusAsWell) sendEvent(event); }
Example #4
Source File: PushServer.java From mantis with Apache License 2.0 | 5 votes |
protected void failedToWriteBatch(AsyncConnection<T> connection, int batchSize, Counter legacyDroppedWrites, SerializedSubject<String, String> metaMsgSubject) { if (legacyDroppedWrites != null) { legacyDroppedWrites.increment(batchSize); } if (metaMsgSubject != null) { MantisMetaDroppedMessage msg = new MantisMetaDroppedMessage(batchSize, System.currentTimeMillis()); metaMsgSubject.onNext(msg.toString()); } failedWrites.increment(batchSize); connectionManager.failedWrites(connection, batchSize); }
Example #5
Source File: RxBusOlder.java From RxBus with Apache License 2.0 | 5 votes |
public <T> Observable<T> register(@NonNull Object tag, @NonNull Class<T> clazz) { List<Subject> subjectList = mSubjectsMapper.get(tag); if (subjectList == null) { subjectList = new ArrayList<>(); mSubjectsMapper.put(tag, subjectList); } Subject<T, T> subject = new SerializedSubject<>(PublishSubject.<T>create()); subjectList.add(subject); if (DEBUG) { Timber.d("[register] mSubjectsMapper: " + mSubjectsMapper); } return subject; }
Example #6
Source File: RXBus.java From RXBus with Apache License 2.0 | 5 votes |
private synchronized SerializedSubject getSubject(RXQueueKey key, boolean createIfMissing) { // 1) look if key already has a publisher subject, if so, return it if (mSubjectsKeys.containsKey(key)) return mSubjectsKeys.get(key); // 2) else, create a new one and put it into the map else if (createIfMissing) { SerializedSubject subject = new SerializedSubject(PublishSubject.create()); mSubjectsKeys.put(key, subject); return subject; } else return null; }
Example #7
Source File: RXBus.java From RXBus with Apache License 2.0 | 5 votes |
private synchronized SerializedSubject getSubject(Class<?> key, boolean createIfMissing) { // 1) look if key already has a publisher subject, if so, return it if (mSubjectsClasses.containsKey(key)) return mSubjectsClasses.get(key); // 2) else, create a new one and put it into the map else if (createIfMissing) { SerializedSubject subject = new SerializedSubject(PublishSubject.create()); mSubjectsClasses.put(key, subject); return subject; } else return null; }
Example #8
Source File: RXBus.java From RXBus with Apache License 2.0 | 5 votes |
/** * Get an observable that observes all events that are send with the key and are of the type of the event class * <p> * @param key the event key you want to observe * @return an Observable, that will observe all events of the @param key class */ public synchronized <T> Observable<T> observeEvent(RXQueueKey key) { if (key == null) throw new RuntimeException("You can't use a null key"); SerializedSubject subject = getSubject(key, true); return subject; }
Example #9
Source File: RXBus.java From RXBus with Apache License 2.0 | 5 votes |
/** * Get an observable that observes all events of the the class the * <p> * @param eventClass the class of event you want to observe * @return an Observable, that will observe all events of the @param key class */ public synchronized <T> Observable<T> observeEvent(Class<T> eventClass) { RXBusEventIsNullException.checkEvent(eventClass); SerializedSubject subject = getSubject(eventClass, true); return subject; }
Example #10
Source File: RXBus.java From RXBus with Apache License 2.0 | 5 votes |
/** * Sends an event to the bus * ATTENTION: all observers that are observing the class of the event will retrieve it * <p> * @param event the event that should be broadcasted to the bus */ public synchronized <T> void sendEvent(T event) { RXBusEventIsNullException.checkEvent(event); SerializedSubject subject = getSubject(event.getClass(), false); // only send event, if subject exists => this means someone has at least once subscribed to it if (subject != null) subject.onNext(event); }
Example #11
Source File: DefaultAuditLogService.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Inject public DefaultAuditLogService() { this.observer = new SerializedSubject<>(PublishSubject.create()); this.observable = observer .onBackpressureBuffer( BACK_PRESSURE_BUFFER_SIZE, () -> logger.warn("Exceeded back pressure buffer of " + BACK_PRESSURE_BUFFER_SIZE), BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST ) .observeOn(Schedulers.io()); }
Example #12
Source File: PushServer.java From mantis with Apache License 2.0 | 5 votes |
protected Observable<Void> manageConnection(final DefaultChannelWriter<R> writer, String host, int port, String groupId, String slotId, String id, final AtomicLong lastWriteTime, final boolean applicationHeartbeats, final Subscription heartbeatSubscription, boolean applySampling, long samplingRateMSec, final SerializedSubject<String, String> metaMsgSubject, final Subscription metaMsgSubscription, Func1<T, Boolean> predicate, final Action0 connectionClosedCallback, final Counter legacyMsgProcessedCounter, final Counter legacyDroppedWrites, final Action0 connectionSubscribeCallback) { return manageConnectionWithCompression(writer, host, port, groupId, slotId, id, lastWriteTime, applicationHeartbeats, heartbeatSubscription, applySampling, samplingRateMSec, null, null, predicate, connectionClosedCallback, legacyMsgProcessedCounter, legacyDroppedWrites, connectionSubscribeCallback, false, false); }
Example #13
Source File: GatewayHandler.java From arcusplatform with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes", "null" }) GatewayHandler(WebSocketClientHandshaker handshaker) { this.authorizedMessages = new SerializedSubject(PublishSubject.create()); this.registeredMessages = new SerializedSubject(PublishSubject.create()); this.platformMessages = new SerializedSubject(PublishSubject.create()); this.protocolMessages = new SerializedSubject(PublishSubject.create()); this.handshaker = handshaker; this.websocketFrameBuf = Unpooled.unreleasableBuffer(Unpooled.buffer(GatewayConnection.WEBSOCKETS_MAX_FRAME_LENGTH)); this.lastHubMsg = System.nanoTime(); this.lastPlatformMsg = System.nanoTime(); }
Example #14
Source File: RxAttachPicker.java From SSForms with GNU General Public License v3.0 | 4 votes |
private RxAttachPicker() { this.subject = new SerializedSubject<>(PublishSubject.<ArrayList<String>>create()); }
Example #15
Source File: WritableEndpoint.java From mantis with Apache License 2.0 | 4 votes |
public WritableEndpoint(String host, int port, String slotId, ObservableConnection<?, ?> connection) { super(host, port, slotId); subject = new SerializedSubject<T, T>(PublishSubject.<T>create()); this.connection = connection; }
Example #16
Source File: RxBus.java From AppPlus with MIT License | 4 votes |
private RxBus(){ rxBus = new SerializedSubject(PublishSubject.<T>create()); }
Example #17
Source File: RxBus.java From ZZShow with Apache License 2.0 | 4 votes |
public RxBus() { mBus = new SerializedSubject<>(PublishSubject.create()); }
Example #18
Source File: RxBus.java From MaterialHome with Apache License 2.0 | 4 votes |
public RxBus() { bus = new SerializedSubject<>(PublishSubject.create()); }
Example #19
Source File: RxBus.java From FileManager with Apache License 2.0 | 4 votes |
private RxBus() { //非线程安全的PublishSubject包装成线程安全的SerializedSubject bus = new SerializedSubject<>(PublishSubject.create()); }
Example #20
Source File: WritableEndpoint.java From mantis with Apache License 2.0 | 4 votes |
public WritableEndpoint(String host, int port) { super(host, port); subject = new SerializedSubject<T, T>(PublishSubject.<T>create()); }
Example #21
Source File: RxBus.java From TestChat with Apache License 2.0 | 4 votes |
public RxBus() { mSubject = new SerializedSubject<>(PublishSubject.create()); mSubscriptionMap = new HashMap<>(); }
Example #22
Source File: RxImagePicker.java From SSForms with GNU General Public License v3.0 | 4 votes |
private RxImagePicker() { this.subject = new SerializedSubject<>(PublishSubject.<List<Image>>create()); }
Example #23
Source File: RxTokenPicker.java From SSForms with GNU General Public License v3.0 | 4 votes |
private RxTokenPicker() { this.subject = new SerializedSubject<>(PublishSubject.<ArrayList<FormTokenObject>>create()); }
Example #24
Source File: RxSignaturePicker.java From SSForms with GNU General Public License v3.0 | 4 votes |
private RxSignaturePicker() { this.subject = new SerializedSubject<>(PublishSubject.<Bitmap>create()); }
Example #25
Source File: RxBus.java From HeroVideo-master with Apache License 2.0 | 4 votes |
private RxBus() { bus = new SerializedSubject<>(PublishSubject.create()); }
Example #26
Source File: RxBus.java From MicroReader with MIT License | 4 votes |
public RxBus() { bus = new SerializedSubject<>(PublishSubject.create()); }
Example #27
Source File: RxBus.java From GankLock with GNU General Public License v3.0 | 4 votes |
private RxBus() { subject = new SerializedSubject<>(PublishSubject.create()); }
Example #28
Source File: RxBus.java From Dota2Helper with Apache License 2.0 | 4 votes |
private RxBus() { bus = new SerializedSubject<>(PublishSubject.create()); }
Example #29
Source File: RxBus.java From HeroVideo-master with Apache License 2.0 | 4 votes |
private RxBus() { bus = new SerializedSubject<>(PublishSubject.create()); }
Example #30
Source File: RxBusManager.java From TestChat with Apache License 2.0 | 4 votes |
private RxBusManager(){ mSubject = new SerializedSubject<>(PublishSubject.create()); mSubscriptionMap = new HashMap<>(); }