mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.6.4.1'
This commit is contained in:
@@ -16,34 +16,56 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.servers.https; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.servers.*;
|
||||
import gplx.core.envs.*;
|
||||
public class Http_long_poll_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
private final List_adp msgs = List_adp_.New();
|
||||
private long send_time_prv = 0;
|
||||
public int Sleep_interval = 100;
|
||||
public int Send_interval = 1000;
|
||||
private boolean active;
|
||||
|
||||
public void Init_by_app(Xoa_app app) {
|
||||
app.Gui__cbk_mgr().Reg(Xog_cbk_wkr__http.Instance);
|
||||
}
|
||||
public void Send_msg(String msg) {
|
||||
msgs.Add(msg);
|
||||
synchronized (msgs) {
|
||||
msgs.Add(msg);
|
||||
}
|
||||
}
|
||||
public String Exec(gplx.langs.jsons.Json_nde data) {
|
||||
while (true) {
|
||||
if (msgs.Len() == 0) {
|
||||
gplx.core.threads.Thread_adp_.Sleep(Sleep_interval);
|
||||
}
|
||||
else {
|
||||
long send_time_cur = gplx.core.envs.Env_.TickCount();
|
||||
if (send_time_cur - send_time_prv > Send_interval) {
|
||||
send_time_prv = send_time_cur;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// NOTE: this class is a singleton and only supports one user; need to track multiple requests by having http_server track incoming users
|
||||
synchronized (msgs) {
|
||||
if (active) return "polling";
|
||||
}
|
||||
return String_.Concat_lines_nl(msgs.To_str_ary_and_clear());
|
||||
// check if already active; if so, return;
|
||||
while (true) {
|
||||
// get msgs in queue
|
||||
int msgs_len = 0;
|
||||
synchronized (msgs) {
|
||||
active = true;
|
||||
msgs_len = msgs.Len();
|
||||
}
|
||||
|
||||
// no messages
|
||||
if (msgs_len == 0) {
|
||||
gplx.core.threads.Thread_adp_.Sleep(Sleep_interval);
|
||||
continue;
|
||||
}
|
||||
|
||||
// message found; exit loop;
|
||||
break;
|
||||
}
|
||||
|
||||
// return commands
|
||||
String[] rv = null;
|
||||
synchronized (msgs) {
|
||||
rv = msgs.To_str_ary_and_clear();
|
||||
active = false;
|
||||
}
|
||||
return String_.Concat_lines_nl(rv);
|
||||
}
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;} private static final byte[] BRIDGE_KEY = Bry_.new_a7("long_poll");
|
||||
public static final Http_long_poll_cmd Instance = new Http_long_poll_cmd(); Http_long_poll_cmd() {}
|
||||
|
||||
private static final int
|
||||
Sleep_interval = 100
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user