Java Code Examples for rx.subjects.SerializedSubject

The following are top voted examples for showing how to use rx.subjects.SerializedSubject. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: FragmentCapsulation   File: RxBus.java   View source code 6 votes vote down vote up
/**
 * 用SerializedSubject包装PublishSubject,序列化
 */
private RxBus() {
    //private final PublishSubject<Object> _bus = PublishSubject.create();

    // If multiple threads are going to emit events to this
    // then it must be made thread-safe like this instead
    _bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 2
Project: joy-library   File: ObjectRequest.java   View source code 6 votes vote down vote up
/**
 * Creates a new request with the given method.
 *
 * @param method the request {@link Method} to use
 * @param url    URL to fetch the Object
 * @param clazz  the Object class to return
 */
private ObjectRequest(int method, String url, Class clazz) {

    super(method, url, null);
    mClazz = clazz;
    mHasCache = BaseApplication.getVolleyCache().get(getCacheKey()) != null;
    setShouldCache(false);
    addEntryListener();
    setRetryPolicy(new DefaultRetryPolicy(DEFAULT_TIMEOUT_MS, DEFAULT_MAX_RETRIES, DEFAULT_BACKOFF_MULT));

    mSubject = new SerializedSubject<>(PublishSubject.create());
}
 
Example 3
Project: RXBus   File: RXBus.java   View source code 6 votes vote down vote up
/**
 * 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
Project: RXBus   File: RXBus.java   View source code 6 votes vote down vote up
/**
 * 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 5
Project: Java_MVVM_with_Swing_and_RxJava_Examples   File: Example_8_Model.java   View source code 6 votes vote down vote up
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 6
Project: TestChat   File: RxBusManager.java   View source code 5 votes vote down vote up
private RxBusManager(){
        mSubject = new SerializedSubject<>(PublishSubject.create());
        mSubscriptionMap = new HashMap<>();
}
 
Example 7
Project: Closet   File: RxBus.java   View source code 5 votes vote down vote up
/**
 * 用SerializedSubject包装PublishSubject,序列化
 */
private RxBus() {
    //private final PublishSubject<Object> _bus = PublishSubject.create();

    // If multiple threads are going to emit events to this
    // then it must be made thread-safe like this instead
    _bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 8
Project: MyDemo   File: RxBus.java   View source code 5 votes vote down vote up
private RxBus() {
    mSubject = new SerializedSubject<>(PublishSubject.create());
}
 
Example 9
Project: 12306_Android   File: RxBus.java   View source code 5 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 10
Project: MicroReader   File: RxBus.java   View source code 5 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 11
Project: FluxJava   File: RxBus.java   View source code 5 votes vote down vote up
/**
 * Constructor.
 *
 * @since 2016/7/5
 */
public RxBus() {
    // Subject that, once an Observer has subscribed,
    // emits all subsequently observed items to the subscriber.
    // PublishSubject is not thread-safe,
    // PublishSubject need to be converted into SerializedSubject
    this.mBus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 12
Project: RXBus   File: RXBus.java   View source code 5 votes vote down vote up
/**
 * 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 13
Project: RXBus   File: RXBus.java   View source code 5 votes vote down vote up
/**
 * 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 14
Project: RXBus   File: RXBus.java   View source code 5 votes vote down vote up
/**
 * 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 15
Project: RXBus   File: RXBus.java   View source code 5 votes vote down vote up
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 16
Project: RXBus   File: RXBus.java   View source code 5 votes vote down vote up
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 17
Project: rxtodo   File: ListNoteActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    presenter = new ListNotePresenter(Inject.get().notesStore());
    clickedNotesSubject = new SerializedSubject<>(PublishSubject.<String>create());
    setContentView(R.layout.view_listnotes);
}
 
Example 18
Project: SeeWeather-master   File: RxBus.java   View source code 5 votes vote down vote up
private RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 19
Project: gank-examples   File: RxBus.java   View source code 5 votes vote down vote up
private RxBus() {
	BUS = new SerializedSubject<>(PublishSubject.create());
}
 
Example 20
Project: gitlab-android   File: RxBus.java   View source code 5 votes vote down vote up
public <E> void post(E event){
    //subject.onNext(event);
    Class clazz = event.getClass();
    Subject<E,E> subject = subjectHashMap.get(clazz);
    if(subject==null){
        subject = new SerializedSubject<>(PublishSubject.<E>create());
        subjectHashMap.put(clazz,subject);
    }
    subject.onNext(event);
}
 
Example 21
Project: gitlab-android   File: RxBus.java   View source code 5 votes vote down vote up
public <E> Observable<E> observeEvents(Class<E> eventClass) {
    Subject<E,E> subject = subjectHashMap.get(eventClass);
    if(subject==null){
        subject = new SerializedSubject<>(PublishSubject.<E>create());
        subjectHashMap.put(eventClass,subject);
    }
    if(eventClass.isAssignableFrom(UniqueEvent.class)&&subject.hasObservers()){
        return Observable.empty();//if the event should only be received by one observer
    }
    return subject.ofType(eventClass);//pass only events of specified type, filter all other
}
 
Example 22
Project: 12306_Android   File: RxBus.java   View source code 5 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 23
Project: spring-cloud-stream   File: SubjectMessageHandler.java   View source code 5 votes vote down vote up
@Override
public synchronized void start() {
	if (!this.running) {
		this.subject = new SerializedSubject(PublishSubject.create());
		Observable<?> outputStream = this.processor.process(this.subject);
		this.subscription = outputStream.subscribe(new Action1<Object>() {

			@Override
			public void call(Object outputObject) {
				if (ClassUtils.isAssignable(Message.class, outputObject.getClass())) {
					getOutputChannel().send((Message) outputObject);
				}
				else {
					getOutputChannel().send(MessageBuilder.withPayload(outputObject).build());
				}
			}
		}, new Action1<Throwable>() {

			@Override
			public void call(Throwable throwable) {
				SubjectMessageHandler.this.logger.error(throwable.getMessage(), throwable);
			}
		}, new Action0() {

			@Override
			public void call() {
				SubjectMessageHandler.this.logger
						.info("Subscription close for [" + SubjectMessageHandler.this.subscription + "]");
			}
		});
		this.running = true;
	}
}
 
Example 24
Project: the-blue-alliance-android   File: TestDatafeedFragment.java   View source code 5 votes vote down vote up
@Before
public void setUp() {
    mFragment = spy(new SimpleDatafeedFragment());
    mSubject = spy(new SerializedSubject<>(PublishSubject.create()));
    mFragment.setObservable(mSubject);
    mController = FragmentTestDriver.getController(mFragment)
            .makeTestActivityController()
            .makeActivity();
    mActivity = mController.getActivity();

    mRefreshController = mActivity.getRefreshController();
    mStatusController = mActivity.getStatusController();
    mEventBus = mActivity.getEventBus();
}
 
Example 25
Project: HeroVideo-master   File: RxBus.java   View source code 4 votes vote down vote up
private RxBus()
{

    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 26
Project: GitHub   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    mSubject = new SerializedSubject<>(PublishSubject.create());
}
 
Example 27
Project: newIPlay   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 28
Project: TestChat   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
        mSubject = new SerializedSubject<>(PublishSubject.create());
        mSubscriptionMap = new HashMap<>();
}
 
Example 29
Project: qvod   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 30
Project: DizzyPassword   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 31
Project: Retrofit-RxAndroid-RxJava-MVP__DownFile   File: RxBus.java   View source code 4 votes vote down vote up
private RxBus(){
    observable=new SerializedSubject<>(PublishSubject.create());
}
 
Example 32
Project: Retrofit-RxAndroid-RxJava-MVP__DownFile   File: RxBus.java   View source code 4 votes vote down vote up
public SerializedSubject getObservable(){
    return observable;
}
 
Example 33
Project: MvpStructure   File: RxBus.java   View source code 4 votes vote down vote up
/**
 * PublishSubject只会把在订阅发生的时间点之后来自原始Observable的数据发射给观察者
 */
public RxBus() {
    mSubject = new SerializedSubject<>(PublishSubject.create());
}
 
Example 34
Project: RxJavaAndRetrofitSimple   File: RxBusEvent.java   View source code 4 votes vote down vote up
private void rebuild() {
    bus = new SerializedSubject(PublishSubject.create());
    stickyEvents.clear();
}
 
Example 35
Project: Dota2Helper   File: RxBus.java   View source code 4 votes vote down vote up
private RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 36
Project: ToBuy   File: RxBus.java   View source code 4 votes vote down vote up
private RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
    stickyBus = new SerializedSubject<>(BehaviorSubject.create());
}
 
Example 37
Project: GankLock   File: RxBus.java   View source code 4 votes vote down vote up
private RxBus() {
    subject = new SerializedSubject<>(PublishSubject.create());
}
 
Example 38
Project: grooo   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 39
Project: grooo   File: RxBus.java   View source code 4 votes vote down vote up
public RxBus() {
    bus = new SerializedSubject<>(PublishSubject.create());
}
 
Example 40
Project: Minerva   File: Importer.java   View source code 4 votes vote down vote up
/**
 * Create new progress subject.
 */
private void createProgressSubject() {
    if (progressSubject == null) progressSubject = new SerializedSubject<>(BehaviorSubject.create());
}