23 out << get_name() <<
'(';
25 const int64_t journal_checkpoint = client.get_journal_checkpoint();
26 const int64_t connection_checkpoint = client.get_connection_checkpoint();
27 const int64_t diff = connection_checkpoint - journal_checkpoint;
29 out << journal_checkpoint;
31 out <<
'+' << diff <<
")(pull to sync)";
36 if (client.is_pullonly())
37 out <<
"(cannot push)";
39 out <<
"(push to sync)";
46 void Client_Command_Processor::pull
50 std::chrono::milliseconds wait
53 const int64_t byte_count = client.pull(wait);
56 out <<
"pulled " << byte_count <<
" bytes, checkpoint = ";
57 out << client.get_journal_checkpoint() <<
'\n';
68 out <<
". Sleeping for " << seconds <<
" seconds...\n";
71 std::this_thread::sleep_for(std::chrono::seconds(1));
79 const std::string &command,
80 std::istream ¶meters,
85 if (command ==
"help")
93 pull_every [<wait_seconds>] [<sleep_seconds>]
95 if (!client.is_pullonly())
96 out <<
" push\n push_every [<sleep_seconds>]\n";
101 else if (command ==
"db")
110 database = &rdc->get_database();
112 database = &wdc->get_database();
132 else if (command ==
"pull")
134 float wait_seconds = 0;
135 parameters >> wait_seconds;
136 pull(out, std::chrono::milliseconds(std::lround(wait_seconds * 1000)));
138 else if (command ==
"pull_every")
140 float wait_seconds = 1;
141 int sleep_seconds = 0;
142 parameters >> wait_seconds >> sleep_seconds;
149 pull(out, std::chrono::milliseconds(std::lround(wait_seconds * 1000)));
150 sleep(sleep_seconds, out);
153 else if (command ==
"push" && !client.is_pullonly())
155 client.push_if_ahead();
157 else if (command ==
"push_every" && !client.is_pullonly())
159 int sleep_seconds = 1;
160 parameters >> sleep_seconds;
167 client.push_if_ahead();
168 sleep(sleep_seconds, out);
181 const std::string &command,
182 std::istream ¶meters,
187 if (command ==
"help")
191 out << R
"RRR(Writable Client
194 set_valid_data <true|false>
195 set_timestamp <true|false>
196 set_hard_checkpoint <true|false>
202 else if (command ==
"transaction")
204 auto *
const wdc =
dynamic_cast<Writable_Database_Client *
>(&client);
205 auto *
const wjc =
dynamic_cast<Writable_Journal_Client *
>(&client);
209 wdc->transaction([&](
const Readable &readable, Writable &writable)
211 Interpreter interpreter
215 &client.get_journal().get_file(),
219 interpreter.set_parent(
this);
220 interpreter.set_prompt_string(
"transaction");
221 interpreter.main_loop(in, out);
226 wjc->transaction([&](Writable_Journal &journal)
228 Writable_Interpreter interpreter(journal, journal);
229 Blob_Reader_Command_Processor processor(journal.get_file());
230 interpreter.add_processor(processor);
231 interpreter.set_parent(
this);
232 interpreter.set_prompt_string(
"transaction(journal)");
233 interpreter.main_loop(in, out);
237 out <<
"Client is not writable, cannot run transaction\n";
239 else if (command ==
"set_valid_data")
241 get_writable_client().set_valid_data(
read_boolean(parameters));
243 else if (command ==
"set_timestamp")
245 get_writable_client().set_timestamp(
read_boolean(parameters));
247 else if (command ==
"set_hard_checkpoint")
249 get_writable_client().set_hard_checkpoint(
read_boolean(parameters));
Status process_command(const std::string &command, std::istream ¶meters, std::istream &in, std::ostream &out) override
void write_prompt(std::ostream &out) const override
static void sleep(int seconds, std::ostream &out)
void set_parent(const Command_Interpreter *new_parent)
void main_loop(std::istream &in, std::ostream &out)
void set_prompt_string(std::string s)
Status process_command(const std::string &command, std::istream ¶meters, std::istream &in, std::ostream &out) override
void add_processor(Command_Processor &processor)
static constexpr int no_signal
static void set_signal(int status)
Status process_command(const std::string &command, std::istream ¶meters, std::istream &in, std::ostream &out) override
std::string get_time_string_of_now()
bool read_boolean(std::istream &in)