本文整理汇总了Java中rx.subjects.SerializedSubject类的典型用法代码示例。如果您正苦于以下问题:Java SerializedSubject类的具体用法?Java SerializedSubject怎么用?Java SerializedSubject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializedSubject类属于rx.subjects包,在下文中一共展示了SerializedSubject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
/**
* 用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());
}
示例2: ObjectRequest
import rx.subjects.SerializedSubject; //导入依赖的package包/类
/**
* 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());
}
示例3: sendEvent
import rx.subjects.SerializedSubject; //导入依赖的package包/类
/**
* 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);
}
示例4: getLogs
import rx.subjects.SerializedSubject; //导入依赖的package包/类
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;
}
示例5: RxBusManager
import rx.subjects.SerializedSubject; //导入依赖的package包/类
private RxBusManager(){
mSubject = new SerializedSubject<>(PublishSubject.create());
mSubscriptionMap = new HashMap<>();
}
示例6: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
private RxBus() {
mSubject = new SerializedSubject<>(PublishSubject.create());
}
示例7: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
public RxBus() {
bus = new SerializedSubject<>(PublishSubject.create());
}
示例8: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
/**
* 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());
}
示例9: observeEvent
import rx.subjects.SerializedSubject; //导入依赖的package包/类
/**
* 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;
}
示例10: getSubject
import rx.subjects.SerializedSubject; //导入依赖的package包/类
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;
}
示例11: onCreate
import rx.subjects.SerializedSubject; //导入依赖的package包/类
@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);
}
示例12: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
private RxBus() {
bus = new SerializedSubject<>(PublishSubject.create());
}
示例13: RxBus
import rx.subjects.SerializedSubject; //导入依赖的package包/类
private RxBus() {
BUS = new SerializedSubject<>(PublishSubject.create());
}
示例14: post
import rx.subjects.SerializedSubject; //导入依赖的package包/类
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);
}
示例15: observeEvents
import rx.subjects.SerializedSubject; //导入依赖的package包/类
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
}