1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

DownloadCentral: Add initial implementation for skipping categories

This commit is contained in:
gnosygnu 2017-02-08 22:06:36 -05:00
parent 9a19be675e
commit 4dba081399
6 changed files with 65 additions and 4 deletions

View File

@ -30,6 +30,7 @@ public class Xobc_task_mgr implements Xog_json_wkr {
this.todo_mgr = new Xobc_task_regy__todo(this);
this.done_mgr = new Xobc_task_regy__done(this);
this.step_mgr = new Xobc_step_factory(this, data_db, app.Fsys_mgr().Wiki_dir());
this.skip_mgr = new Xobc_skip_mgr(this, app);
this.ary = new Xobc_task_regy__base[] {work_mgr, todo_mgr, done_mgr};
this.rate_mgr = Xobc_cmd__base.New_rate_mgr();
}
@ -44,6 +45,7 @@ public class Xobc_task_mgr implements Xog_json_wkr {
public Gfo_rate_mgr Rate_mgr() {return rate_mgr;} private final Gfo_rate_mgr rate_mgr;
public Xobc_step_factory Step_mgr() {return step_mgr;} private final Xobc_step_factory step_mgr;
public Xobc_filter_mgr Filter_mgr() {return filter_mgr;} private final Xobc_filter_mgr filter_mgr = new Xobc_filter_mgr();
public Xobc_skip_mgr Skip_mgr() {return skip_mgr;} private final Xobc_skip_mgr skip_mgr;
public Xobc_lang_mgr Lang_mgr() {return lang_mgr;} private final Xobc_lang_mgr lang_mgr = new Xobc_lang_mgr();
public void Send_json(String func, Gfobj_nde data) {cbk_mgr.Send_json(cbk_trg, func, data);}
public Xobc_task_mgr Load_or_init() {

View File

@ -68,7 +68,7 @@ public abstract class Xobc_cmd__base implements Xobc_cmd_itm {
case Gfo_prog_ui_.Status__fail: task_mgr.Work_mgr().On_fail(this, this.Cmd_fail_resumes(), cmd_exec_err); break;
case Gfo_prog_ui_.Status__working:
this.Prog_notify_and_chk_if_suspended(data_end, data_end); // fire one more time for 100%; note that 100% may not fire due to timer logic below
task_mgr.Work_mgr().On_done(this);
task_mgr.Work_mgr().On_done(this, true);
break;
}
} catch (Exception e) {

View File

@ -0,0 +1,39 @@
/*
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.bldrs.centrals.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*; import gplx.xowa.addons.bldrs.centrals.*;
import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
public class Xobc_skip_mgr implements Gfo_invk {
private boolean category_enabled;
public Xobc_skip_mgr(Xobc_task_mgr task_mgr, Xoa_app app) {
app.Cfg().Bind_many_app(this, Cfg__namespaces_category);
}
public boolean Should_skip(Xobc_import_step_itm step_itm) {
if (category_enabled && step_itm.Import_type == Xobc_import_type.Tid__wiki__ctg)
return true;
else
return false;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__namespaces_category)) category_enabled = m.ReadBool("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String
Cfg__namespaces_category = "xowa.bldr.download_central.namespaces.category"
;
}

View File

@ -39,6 +39,7 @@ public class Xobc_task_itm implements gplx.CompareAble {
public void Task_status_(byte v) {task_status = v;} // called when task moves from init -> working -> suspended -> done
public void Task_seqn_(int v) {this.task_seqn = v;} // called when task is init'd from db, or added to list
public int compareTo(Object obj) {Xobc_task_itm comp = (Xobc_task_itm)obj; return Int_.Compare(task_seqn, comp.task_seqn);}
public Gfobj_nde Save_to(Gfobj_nde nde) {
nde.Add_int ("task_id" , task_id);
nde.Add_str ("task_name" , task_name);

View File

@ -19,6 +19,7 @@ package gplx.xowa.addons.bldrs.centrals.tasks; import gplx.*; import gplx.xowa.*
import gplx.core.gfobjs.*; import gplx.core.progs.*; import gplx.core.threads.*;
import gplx.xowa.drds.powers.*;
import gplx.xowa.addons.bldrs.centrals.steps.*; import gplx.xowa.addons.bldrs.centrals.cmds.*;
import gplx.xowa.addons.bldrs.centrals.dbs.datas.imports.*;
public class Xobc_task_regy__work extends Xobc_task_regy__base {
private final Thread_adp_mgr thread_mgr = new Thread_adp_mgr(1000, 5000);
private final Xobc_cmd_ctx ctx;
@ -47,6 +48,12 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
}
}
public void Run_task(Xobc_task_itm task, Xobc_cmd_itm cmd) {
// if task marked for skip, launch skip-cmd on separate thread and exit;
if (task_mgr.Skip_mgr().Should_skip(task_mgr.Data_db().Tbl__import_step().Select_one(cmd.Step_id()))) {
thread_mgr.Add("skip_" + cmd.Cmd_uid(), Thread_adp_.Start_by_key("skip_xobc: " + cmd.Cmd_name(), new Xobc_task_skip(this, cmd), ""));
return;
}
task.Task_status_(gplx.core.progs.Gfo_prog_ui_.Status__working);
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
@ -85,12 +92,13 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
task_mgr.Send_json("xo.bldr.work.prog__start__recv", task.Save_to(Gfobj_nde.New()));
thread_mgr.Add(cmd.Cmd_uid(), Thread_adp_.Start_by_val("xobc: " + cmd.Cmd_name(), cmd, cmd, Xobc_cmd__base.Invk__exec, ctx));
}
public void On_done(Xobc_cmd_itm cmd) {
public void On_done(Xobc_cmd_itm cmd, boolean notify) {
Xobc_task_itm task = this.Get_by(cmd.Task_id());
Xobc_step_itm step = task.Step();
boolean step_is_done = step.Cmd_is_last();
boolean task_is_done = step_is_done && task.Step_is_last();
task_mgr.Send_json("xo.bldr.work.prog__done__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_bool("task_is_done", task_is_done));
if (notify)
task_mgr.Send_json("xo.bldr.work.prog__done__recv", Gfobj_nde.New().Add_int("task_id", task.Task_id()).Add_bool("task_is_done", task_is_done));
// step.done -> task.done || step.next
if (step_is_done) {
@ -141,3 +149,15 @@ public class Xobc_task_regy__work extends Xobc_task_regy__base {
task_mgr.Send_json("xo.bldr.work.prog__stat__recv", Gfobj_nde.New().Add_int("task_id", task_id).Add_str("msg", msg));
}
}
class Xobc_task_skip implements Gfo_invk {
private final Xobc_task_regy__work work_regy;
private final Xobc_cmd_itm cmd;
public Xobc_task_skip(Xobc_task_regy__work work_regy, Xobc_cmd_itm cmd) {
this.work_regy = work_regy;
this.cmd = cmd;
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
work_regy.On_done(cmd, false);
return Gfo_invk_.Rv_handled;
}
}

View File

@ -65,5 +65,4 @@ public class Scrib_xtn_mgr extends Xox_mgr_base {
, Cfg__lua__timeout_polling = "xowa.addon.scribunto.lua.timeout_polling"
, Cfg__lua__timeout_busy_wait = "xowa.addon.scribunto.lua.timeout_busy_wait"
;
}