pushlet基本流程

 

长链接:

客户端长轮询(pull,poll)

Stream, (在Subscriber.fetchEvents{ while (isActive()){deQueueAll();//没有命令就发心跳}})

 

 

流程:

 

Pushlet.doRequest

            1. 创建会话

 

           2. Controller.doCommand

        {

                 //根据客户端的命令进行命令分发

                   启动或停止subscriber,设置返回的命令等,若是publish事件-->

                    Dispatcher.getInstance().unicast(aCommand.reqEvent, to); || Dispatcher.getInstance().multicast(aCommand.reqEvent);

 

                 //分发完毕执行,Handle response back to client

                if (eventType.endsWith(Protocol.E_LISTEN) ||
                    eventType.equals(Protocol.E_REFRESH)) {
                    // Data channel events
                    // Loops until refresh or connection closed
                     getSubscriber().fetchEvents(aCommand);

                 } else {
                     // Send response for control commands
                       sendControlResponse(aCommand);
                 }

            }

 

 

入库

Dispatcher.getInstance().multicast-->

multicast或unicast触发

SessionManager.getInstance().apply(sessionManagerVisitor, method, args);

遍历所有的会话,进行调用

visitMulticast || visitBroadcast

判断当前会话的Subscriber是否符合条件,符合就调用-->

Subscriber.onEvent(e){enQueue()}

SessionManager对event进行管理(AgingTimerTask),超时会话将被stop(),会话也会stop从属于它的Subscriber;

 

 

出库

长轮询是sendControlResponse(aCommand);

protected void sendControlResponse(Command aCommand) {
        try {

            // Try to prevent caching in any form.
            aCommand.sendResponseHeaders();

            // Let clientAdapter determine how to send event
            aCommand.getClientAdapter().start();

            // Push to client through client adapter
            aCommand.getClientAdapter().push(aCommand.getResponseEvent());

            // One shot response
            aCommand.getClientAdapter().stop();
        } catch (Throwable t) {
            session.stop();
        }
    }

 

stream方式如下:

在Subscriber.fetchEvents{ while (isActive()){

// Update session time to live
session.kick();

 

deQueueAll();

 

//没有事件就发心跳

 

//发到客户端

clientAdapter.push(events[i]);

}}

 

NOTE:

Command创建ClientAdapter,同时把resq实例赋给它,对外的输入都是由ClientAdapter完成

 

下面的图转自 http://blog.youkuaiyun.com/yxw246/archive/2008/05/08/2418255.aspx



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值