mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Source: Restore broken commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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 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) {
|
||||
synchronized (msgs) {
|
||||
msgs.Add(msg);
|
||||
}
|
||||
}
|
||||
public String Exec(gplx.langs.jsons.Json_nde data) {
|
||||
// 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";
|
||||
}
|
||||
// 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
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.*;
|
||||
public class Http_send_msg_cmd implements gplx.xowa.htmls.bridges.Bridge_cmd_itm {
|
||||
public void Init_by_app(Xoa_app app) {}
|
||||
public String Exec(gplx.langs.jsons.Json_nde data) {
|
||||
gplx.langs.jsons.Json_nde jnde = (gplx.langs.jsons.Json_nde)data.Get_as_itm_or_null(Bry_.new_a7("msg"));
|
||||
Http_long_poll_cmd.Instance.Send_msg(jnde.Print_as_json());
|
||||
return "{}";
|
||||
}
|
||||
|
||||
public byte[] Key() {return BRIDGE_KEY;}
|
||||
public static final byte[] BRIDGE_KEY = Bry_.new_a7("send_msg");
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.xowa.bldrs.wkrs.*;
|
||||
import gplx.xowa.htmls.bridges.*;
|
||||
public class Xoax_long_poll_addon implements Xoax_addon_itm, Xoax_addon_itm__json {
|
||||
public Bridge_cmd_itm[] Json_cmds() {
|
||||
return new Bridge_cmd_itm[]
|
||||
{ Http_long_poll_cmd.Instance
|
||||
, new Http_send_msg_cmd()
|
||||
};
|
||||
}
|
||||
|
||||
public String Addon__key() {return "xowa.servers.https.long_poll";}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
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.xowa.guis.cbks.*; import gplx.core.gfobjs.*; import gplx.xowa.guis.cbks.swts.*;
|
||||
public class Xog_cbk_wkr__http implements Xog_cbk_wkr {
|
||||
private final Gfobj_wtr__json__browser json_wtr = new Gfobj_wtr__json__browser();
|
||||
public Object Send_json(Xog_cbk_trg trg, String func, Gfobj_nde data) {
|
||||
String script = json_wtr.Write_as_func__drd(func, data);
|
||||
Http_long_poll_cmd.Instance.Send_msg(script);
|
||||
return null;
|
||||
}
|
||||
public void Send_prog(String head) {
|
||||
Http_long_poll_cmd.Instance.Send_msg(head);
|
||||
}
|
||||
public static final Xog_cbk_wkr__http Instance = new Xog_cbk_wkr__http(); Xog_cbk_wkr__http() {}
|
||||
}
|
||||
Reference in New Issue
Block a user