EventBus

聊聊lettuce的指标监控

丶灬走出姿态 提交于 2019-12-03 01:59:49
序 本文主要研究一下lettuce的指标监控 DefaultCommandLatencyEventPublisher lettuce-core-5.0.4.RELEASE-sources.jar!/io/lettuce/core/event/metrics/DefaultCommandLatencyEventPublisher.java public class DefaultCommandLatencyEventPublisher implements MetricEventPublisher { private final EventExecutorGroup eventExecutorGroup; private final EventPublisherOptions options; private final EventBus eventBus; private final CommandLatencyCollector commandLatencyCollector; private final Runnable EMITTER = this::emitMetricsEvent; private volatile ScheduledFuture<?> scheduledFuture; public DefaultCommandLatencyEventPublisher

Bridging messages from eventbus to subscribed websocket clients using VertX

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use websocket to create a publish-suscribe model which can be reached through both SockJS and Websocket (for Javascript clients on one side, and for Java clients on the other. Currently I'm able to subscribe using SockJS and Javascript clients. However, when trying to use websocket to receive messages in my Java client, I am able to connect to the websocket server, but don't receive any messages from the server. My current client code: public class WebsocketReceiverIntegrationTest { public static void main(String[] args) {

Websocket creation using sockjs-client/sockjs in angular2 webapp project

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Angular2 webapp project for FRONT-END and Vertex3 for BACK-END. Using Sockjs-client i'm creating websocket (at client side) to create a communication channel between Frontend and Backend. I have installed sockjs-client using npm : npm install sockjs-client When I import sockjs-client in LoginService.ts file : import * as SockJS from 'sockjs-client'; export class LoginService { URL: string = 'http://localhost:8082/eventbus'; sock: SockJS; handlers = {}; private _opened: boolean = false; public open(): void { if (!this._opened) {

Progaurd issue “Warning:Ignoring InnerClasses attribute for an anonymous inner class”

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I don't know how I can describe this issue. I searched a lot, but I didn't find any solution. Also this solution did not help me -keepattributes EnclosingMethod : dependencies { compile project ( ':libraries:material-drawer' ) compile fileTree ( dir : 'libs' , include : [ '*.jar' ]) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.0' compile 'com.android.support:recyclerview-v7:23.2.0' compile 'com.android.support:design:23.2.0' compile 'com.google.code.gson:gson:2.4' compile 'com.mcxiaoke.volley

How to/Should I unit test EventBus events with Mockito?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use Otto's EventBus in my Android app. In my LoginNetworkOperation class, I catch different kinds of network connection errors and I post different bus events for each one, and my LoginPresenter class is registered as a listener and certain methods are invoked, when these events are fired. My question is how (and should I) do I unit test whether the LoginNetworkOperation throws this event and LoginPresenter handles it with Mockito ? I looked at this question: Guava EventBus unit tests but it doesn't provide enough information, especially

EventBus 源码解析

∥☆過路亽.° 提交于 2019-12-03 00:34:48
1. 功能介绍 1.1 EventBus EventBus 是一个 Android 事件发布/订阅框架,通过解耦发布者和订阅者简化 Android 事件传递,这里的事件可以理解为消息,本文中统一称为事件。事件传递既可用于 Android 四大组件间通讯,也可以用户异步线程和主线程间通讯等等。 传统的事件传递方式包括:Handler、BroadCastReceiver、Interface 回调,相比之下 EventBus 的优点是代码简洁,使用简单,并将事件发布和订阅充分解耦。 1.2 概念 事件(Event): 又可称为消息,本文中统一用事件表示。其实就是一个对象,可以是网络请求返回的字符串,也可以是某个开关状态等等。 事件类型(EventType) 指事件所属的 Class。 事件分为一般事件和 Sticky 事件,相对于一般事件,Sticky 事件不同之处在于,当事件发布后,再有订阅者开始订阅该类型事件,依然能收到该类型事件最近一个 Sticky 事件。 订阅者(Subscriber): 订阅某种事件类型的对象。当有发布者发布这类事件后,EventBus 会执行订阅者的 onEvent 函数,这个函数叫 事件响应函数 。订阅者通过 register 接口订阅某个事件类型,unregister 接口退订。订阅者存在优先级,优先级高的订阅者可以取消事件继续向优先级低的订阅者分发

EventBus基础用法

匿名 (未验证) 提交于 2019-12-03 00:27:02
1、EventBus三要素 Event:事件。可以是任意类型的对象 Subscriber:事件订阅者。在EventBus3.0之前消息吹了的方法只能限定于onEvent,onEventMainThread,onEventBackgroundThread,和onEventAsync,它们分别代表4种线程模型。而在3.0之后,事件处理的方法可以随便取名,但是需要添加一个注解@Subscribe,并且要指定线程模型(默认是Posting) publisher:事件发布者。可以在任意线程任意位置发布事件,直接调用EventBus到的post方法,根据post函数参数的类型,会自动调用订阅相应类型事件的函数。 2、EventBus的4种线程模型 POSTING: 该事件在哪个线程发布出来,事件处理函数就在哪个线程运行 MAIN:该事件无论在哪个线程发布出来,事件处理函数都会在主线程中执行,所以时间处理的时间不能太长,长了会导致ANR. BACKGROUND:如果时间在UI线程中发布出来,那么该事件处理函数就会在新的线程中运行;如果事件本来就是在子线程中发布,那么该事件处理函数直接在发布事件的线程中执行。 ASYNC:无论该事件在哪个线程发布,该事件处理函数都会在新建的子线程中运行。 3、使用 // 自定义事件类 public class MessageEvent { } // 注册

EventBus使用

匿名 (未验证) 提交于 2019-12-03 00:26:01
使用EventBus的界面 第二张代码可看可不看,不是重点,(一三是重点) 红框里是主要传递参数的方法。 最后要记得在onDestory里面 有人没明白可以联系我qq:137267618 暂时还没空整理demo。马上要离职。 文章来源: EventBus使用

EventBus的Post方法发送事件

匿名 (未验证) 提交于 2019-12-03 00:26:01
例: 组件与组件之间的传递代替Intent,线程间的通讯代替handler 加依赖: dependencies { compile 'org.greenrobot:eventbus:3.0.0' } 加权限: MainActivity /** * Module, EventBus , 2 Activity * <p> * Module * <p> * EventBus, EventBus * <p> * EventBus , * <p> * EventBus Post * <p> * , * * Intent, handler */ public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button button ; private TextView tv_title ; private EventBus mEventBus ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); initView(); //

EventBus实现全解,手写EventBus

匿名 (未验证) 提交于 2019-12-03 00:08:02
首先,大家都知道,EventBus是个非常好用的事件传递工具,相比之前Handler随着参数传递来说,本人自我感觉是非常的方便,并且也比较轻量,也不会像handler那样,一不小心就会出现内存泄漏,好了,废话不多说,还是看看它的具体实现吧. 用过的同学都知道,EventBus使用起来用到的最重要的就是注册和反注册,已经事件的定义,参数的传递,3.0以后加入了线程的控制,主线程还是子线程的模式,还有粘性事件(这里就不多说,因为用的不是特别多,当然具体情况,具体分析啦) 所以接下来就是EventBus实现的几个类: EventBus -------EventBus实现类 SubcribeMethod -------方法回调以及线程类型,回调方法参数设置 Subscribe ------- 注解类 ThreadMode ------线程枚举 1.EventBus实现方法 1):首先要使用EventBus就需要先注册,有注册就要反注册,这个是配套的(具体为什么,我想大家都知道,这里就不累赘了,哈哈) EventBus.getDefault().register(this); 2):再者就是,注册完了,就开始使用了,大家都知道EventBus的使用非常简单; EventBus.getDefault().post(定义的事件); 3):事件处理 @Subscribe(threadMode =