当前位置: 首页>>代码示例>>Java>>正文


Java Emitter.Listener方法代码示例

本文整理汇总了Java中io.socket.emitter.Emitter.Listener方法的典型用法代码示例。如果您正苦于以下问题:Java Emitter.Listener方法的具体用法?Java Emitter.Listener怎么用?Java Emitter.Listener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.socket.emitter.Emitter的用法示例。


在下文中一共展示了Emitter.Listener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connect

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void connect(HashMap<String, Emitter.Listener> events) {

        mEvents = events;
        String url = mServerUrl + "/channel";

        IO.Options opts = new IO.Options();
        opts.forceNew = true;

        opts.query = "A=" + mAppId + "&C=" + mChannelId + "&S=" + mServerName + "&D=" + mDeviceId + "&U=" + xpushSession.getId();

        mChannelSocket = null;

        try {
            mChannelSocket = IO.socket(url, opts);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }

        if (events != null) {
            for (String eventName : events.keySet()) {
                this.on(eventName, events.get(eventName));
            }
        }

        mChannelSocket.connect();
    }
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:27,代码来源:ChannelCore.java

示例2: doClose

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
protected void doClose() {
    final Polling self = this;

    Emitter.Listener close = new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            logger.fine("writing close packet");
            try {
                self.write(new Packet[]{new Packet(Packet.CLOSE)});
            } catch (UTF8Exception err) {
                throw new RuntimeException(err);
            }
        }
    };

    if (this.readyState == ReadyState.OPEN) {
        logger.fine("transport open - closing");
        close.call();
    } else {
        // in case we're trying to close while
        // handshaking is in progress (engine.io-client GH-164)
        logger.fine("transport not open - deferring close");
        this.once(EVENT_OPEN, close);
    }
}
 
开发者ID:socketio,项目名称:engine.io-client-java,代码行数:26,代码来源:Polling.java

示例3: on

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void on(String event, Emitter.Listener fn) {
    mChannelSocket.on(event, fn);
}
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:4,代码来源:ChannelCore.java

示例4: SailsSocket

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public SailsSocket(String url, IO.Options options) {
    // Set logger level to FINE
    logger.setLevel(Level.FINE);

    if (options == null) {
        options = new IO.Options();
    }

    /**
     * Solves problem: "Sails v0.11.x is not compatible with the socket.io/sails.io.js
     * client SDK version you are using (0.9.0). Please see the v0.11 migration guide
     * on http://sailsjs.org for more information".
     *
     * https://github.com/balderdashy/sails/issues/2640
     */
    String sdkVersionQuery = SDK_VERSION_KEY + "=" + SDK_VERSION_VALUE;
    if (options.query == null) {
        options.query = sdkVersionQuery;
    } else {
        options.query = options.query + "&" + sdkVersionQuery;
    }

    try {
        socket = IO.socket(url, options);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    requestQueue = new HashSet<SailsSocketRequest>();

    Emitter.Listener clearRequestQueue = new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            drainRequestQueue();
        }
    };
    socket.on(Socket.EVENT_CONNECT, clearRequestQueue);
    socket.on(Socket.EVENT_RECONNECT, clearRequestQueue);
}
 
开发者ID:joshuamarquez,项目名称:sails.io.java,代码行数:40,代码来源:SailsSocket.java

示例5: connectChannel

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
private void connectChannel() {

        HashMap<String, Emitter.Listener> events = new HashMap<>();

        events.put(Socket.EVENT_CONNECT_ERROR, onConnectError);
        events.put(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
        events.put(Socket.EVENT_CONNECT, onConnectSuccess);
        events.put("message", onMessage);

        mChannelCore.connect(events);
    }
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:12,代码来源:XPushChatFragment.java

示例6: stop

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
 * Stop broadcast topology to server-side.
 */
public Emitter.Listener stop() {
    return new Emitter.Listener() {
        @Override public void call(Object... args) {
            refreshTask.cancel(true);

            AgentClusterDemo.stop();
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:DemoListener.java

示例7: start

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
 * Start broadcast topology to server-side.
 */
public Emitter.Listener start() {
    return new Emitter.Listener() {
        @Override public void call(Object... args) {
            safeStopRefresh();

            final long timeout = args.length > 1 && args[1] instanceof Long ? (long)args[1] : DFLT_TIMEOUT;

            refreshTask = pool.scheduleWithFixedDelay(broadcastTask, 0L, timeout, TimeUnit.MILLISECONDS);
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:15,代码来源:ClusterListener.java

示例8: stop

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
 * Stop broadcast topology to server-side.
 */
public Emitter.Listener stop() {
    return new Emitter.Listener() {
        @Override public void call(Object... args) {
            refreshTask.cancel(true);

            watch();
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:ClusterListener.java

示例9: on

import io.socket.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);
        }
    };
}
 
开发者ID:socketio,项目名称:socket.io-client-java,代码行数:10,代码来源:On.java

示例10: fireReconnectEventsOnSocket

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
@Test(timeout = TIMEOUT)
public void fireReconnectEventsOnSocket() throws URISyntaxException, InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    Manager.Options opts = new Manager.Options();
    opts.reconnection = true;
    opts.timeout = 0;
    opts.reconnectionAttempts = 2;
    opts.reconnectionDelay = 10;
    final Manager manager = new Manager(new URI(uri()), opts);
    socket = manager.socket("/timeout_socket");

    final int[] reconnects = new int[] {0};
    Emitter.Listener reconnectCb = new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            reconnects[0]++;
            values.offer(args[0]);
        }
    };

    socket.on(Socket.EVENT_RECONNECT_ATTEMPT, reconnectCb);
    socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() {
        @Override
        public void call(Object... objects) {
            socket.close();
            manager.close();
            values.offer(reconnects[0]);
        }
    });
    socket.open();
    assertThat((Integer)values.take(), is(reconnects[0]));
    assertThat((Integer)values.take(), is(2));
}
 
开发者ID:socketio,项目名称:socket.io-client-java,代码行数:35,代码来源:ConnectionTest.java

示例11: fireReconnectingWithAttemptsNumberWhenReconnectingTwice

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
@Test(timeout = TIMEOUT)
public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws URISyntaxException, InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    Manager.Options opts = new Manager.Options();
    opts.reconnection = true;
    opts.timeout = 0;
    opts.reconnectionAttempts = 2;
    opts.reconnectionDelay = 10;
    final Manager manager = new Manager(new URI(uri()), opts);
    socket = manager.socket("/timeout_socket");

    final int[] reconnects = new int[] {0};
    Emitter.Listener reconnectCb = new Emitter.Listener() {
        @Override
        public void call(Object... args) {
            reconnects[0]++;
            values.offer(args[0]);
        }
    };

    socket.on(Socket.EVENT_RECONNECTING, reconnectCb);
    socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() {
        @Override
        public void call(Object... objects) {
            socket.close();
            manager.close();
            values.offer(reconnects[0]);
        }
    });
    socket.open();
    assertThat((Integer)values.take(), is(reconnects[0]));
    assertThat((Integer)values.take(), is(2));
}
 
开发者ID:socketio,项目名称:socket.io-client-java,代码行数:35,代码来源:ConnectionTest.java

示例12: on

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void on(String event, Emitter.Listener eventListener) {
    if( !mEvents.containsKey( event) ){
        mGlobalSocket.on(event, eventListener);
    }
}
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:6,代码来源:XPushCore.java

示例13: off

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void off(String event, Emitter.Listener fn) {
    mChannelSocket.off(event, fn);
}
 
开发者ID:xpush,项目名称:lib-xpush-android,代码行数:4,代码来源:ChannelCore.java

示例14: addListener

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void addListener(String event, Emitter.Listener listener) {
    this.socket.off(event, listener);
    this.socket.on(event, listener);
}
 
开发者ID:matheuss,项目名称:msg-android,代码行数:5,代码来源:SocketManager.java

示例15: addOnHandler

import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void addOnHandler(String event,Emitter.Listener listener){
        mSocket.on(event, listener);
}
 
开发者ID:Mahabali,项目名称:Socket.io-Android-Chat,代码行数:4,代码来源:SocketIOService.java


注:本文中的io.socket.emitter.Emitter.Listener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。