本文整理汇总了Java中com.github.nkzawa.emitter.Emitter类的典型用法代码示例。如果您正苦于以下问题:Java Emitter类的具体用法?Java Emitter怎么用?Java Emitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Emitter类属于com.github.nkzawa.emitter包,在下文中一共展示了Emitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSocketIO
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private void setupSocketIO(Server item){
try {
io = IO.socket(item.getTargetUrl());
io.on("log", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject dataReceive = (JSONObject) args[0];
handleMessage(dataReceive);
}
});
}catch (Exception ex){
Log.i("Exception", ex.getMessage());
}
}
示例2: listenForEvent
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private <J> void listenForEvent(String eventName, String serviceName, final OnEventCallback<J> callback, final Class<J> jClass) {
mSocket.on(serviceName + " " + eventName,
new Emitter.Listener() {
@Override
public void call(Object... args) {
if (args.length == 1) {
JSONObject obj = (JSONObject) args[0];
if (callback instanceof OnCreatedCallback) {
((OnCreatedCallback) callback).onCreated(Serialization.deserializeObject(obj, jClass, gson));
}
if (callback instanceof OnUpdatedCallback) {
((OnUpdatedCallback) callback).onUpdated(Serialization.deserializeObject(obj, jClass, gson));
}
if (callback instanceof OnRemovedCallback) {
((OnRemovedCallback) callback).onRemoved(Serialization.deserializeObject(obj, jClass, gson));
}
if (callback instanceof OnPatchedCallback) {
((OnPatchedCallback) callback).onPatched(Serialization.deserializeObject(obj, jClass, gson));
}
}
}
});
}
示例3: initCallListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initCallListener(final SocketEventListener listener){
return new Emitter.Listener() {
@Override
public void call(Object... args) {
SynergykitLog.print(getEvent() + ": " + STATE_CALLED); //print state
//call listener
if(listener!=null)
listener.call(args);
else
SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);
}
};
}
示例4: initUnsubscribedListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initUnsubscribedListener(final SocketEventListener listener){
return new Emitter.Listener() {
@Override
public void call(Object... args) {
SynergykitLog.print(getEvent() + ": " + STATE_UNSUBSCRIBED); //print state
//unsubscribed listener
if(listener!=null)
listener.unsubscribed();
else
SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);
}
};
}
示例5: off
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@SuppressWarnings("unused")
private void off(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (args.length() == 0) {
this.socket.off();
callbackContext.success();
return;
}
String eventName = args.getString(0);
if (args.length() == 1) {
this.socket.off(eventName);
callbackContext.success();
return;
}
int hashCode = args.getInt(1);
if (LISTENERS.containsKey(hashCode)) {
Emitter.Listener listener = LISTENERS.remove(hashCode);
this.socket.off(eventName, listener);
}
}
示例6: emit
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
/**
* Emits an event with an acknowledge.
*
* @param event an event name
* @param args data to send.
* @param ack the acknowledgement to be called
* @return a reference to this object.
*/
public Emitter emit(final String event, final Object[] args, final Ack ack) {
EventThread.exec(new Runnable() {
@Override
public void run() {
List<Object> _args = new ArrayList<Object>() {{
add(event);
if (args != null) {
addAll(Arrays.asList(args));
}
}};
Packet<JSONArray> packet = new Packet<JSONArray>(Parser.EVENT, new JSONArray(_args));
logger.fine(String.format("emitting packet with ack id %d", ids));
Socket.this.acks.put(ids, ack);
packet.id = ids++;
Socket.this.packet(packet);
}
});
return this;
}
示例7: rememberWebsocket
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void rememberWebsocket() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
EventThread.exec(new Runnable() {
@Override
public void run() {
final Socket socket = new Socket(createOptions());
socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
@Override
public void call(Object... args) {
Transport transport = (Transport) args[0];
socket.close();
if (WebSocket.NAME.equals(transport.name)) {
Socket.Options opts = new Socket.Options();
opts.port = PORT;
opts.rememberUpgrade = true;
Socket socket2 = new Socket(opts);
socket2.open();
values.offer(socket2.transport.name);
socket2.close();
}
}
});
socket.open();
values.offer(socket.transport.name);
}
});
assertThat((String)values.take(), is(Polling.NAME));
assertThat((String)values.take(), is(WebSocket.NAME));
}
示例8: notRememberWebsocket
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void notRememberWebsocket() throws InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
EventThread.exec(new Runnable() {
@Override
public void run() {
final Socket socket = new Socket(createOptions());
socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
@Override
public void call(Object... args) {
Transport transport = (Transport)args[0];
socket.close();
if (WebSocket.NAME.equals(transport.name)) {
Socket.Options opts = new Socket.Options();
opts.port = PORT;
opts.rememberUpgrade = false;
final Socket socket2 = new Socket(opts);
socket2.open();
values.offer(socket2.transport.name);
socket2.close();
}
}
});
socket.open();
values.offer(socket.transport.name);
}
});
assertThat((String)values.take(), is(Polling.NAME));
assertThat((String)values.take(), is(not(WebSocket.NAME)));
}
示例9: initSubscribedListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initSubscribedListener(final SocketEventListener listener){
return new Emitter.Listener() {
@Override
public void call(Object... args) {
SynergykitLog.print(getEvent() + ": " + STATE_SUBSCRIBED); //print state
//subscribed listener
if(listener!=null)
listener.subscribed();
else
SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);
}
};
}
示例10: on
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public static Handle on(final Emitter obj, final String ev, final Emitter.Listener fn) {
obj.on(ev, fn);
return new Handle() {
@Override
public void destroy() {
obj.off(ev, fn);
}
};
}
示例11: bindListenerForEvent
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public void bindListenerForEvent(String event,Emitter.Listener listener) {
if(null != listener && null != socket) {
socket.on(event,listener);
}
}
示例12: getConnectedListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getConnectedListener() {
return connectedListener;
}
示例13: getDisconnectedListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getDisconnectedListener() {
return disconnectedListener;
}
示例14: getReconnectedListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getReconnectedListener() {
return reconnectedListener;
}
示例15: getCallListener
import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getCallListener() {
return callListener;
}