前回の記事 : http://qiita.com/muzudho1/items/076127ebb2730c29e229
コマンドライン引数
./apery --enqueue 1113 durable --dequeue 1112 durable autodelete
こんな感じで メッセージ・キューを指定できるようにしたい。
その前に
ログ・ファイルが巨大だぞ
「標準出力に表示をしながらファイルにも保存して、かつローテーションもする」(Qiita)
http://qiita.com/saka1_p/items/5e37fafb35b10bb3d5a3
rotatelogs を調べてみるか。
[1]+ Done
うーむ。
じゃあ、こうか?
./tamesi35a2_cpp.exe --enqueue 1113 durable --dequeue 1112 durable autodelete > rotatelogs ./tamesi35a2_cpp.out.log 86400 2> ./tamesi35a2_cpp.err.log rotatelogs 86400 < /dev/null &
./tamesi35a2_cpp.exe --enqueue 1113 durable --dequeue 1112 durable autodelete 1> rotatelogs ./tamesi35a2_cpp.out.log.%Y%m%d_%H%M%S 5M 2> rotatelogs ./tamesi35a2_cpp.err.log.%Y%m%d_%H%M%S 5M < /dev/null &
こう書くと、
[1]+ Exit 11 ./tamesi35a2_cpp.exe --enqueue 1113 durable --dequeue 1112 durable autodelete ./tamesi35a2_cpp.out.log.%Y%m%d_%H%M%S 5M ./tamesi35a2_cpp.err.log.%Y%m%d_%H%M%S 5M > rotatelogs 2> rotatelogs < /dev/null
こんな感じで解釈されるらしい。
/var/log
「logrotate の概要」(SERVER ARCHITECTURE for LINUX)
http://linux.kororo.jp/cont/server/logrotate.php
なんか Linux にはログ・ローテーションが基本的に備わってるみたいなんだが、これを利用できないものか。
logrotate をググってみたんだが 何を言ってるのか さっぱり分からなかった。
-rw-r--r-- 1 root root 867435892 Mar 16 21:56 tamesi35a2_cpp.out.log
ログファイルの容量が 827メガバイトぐらいあって 読めないぜ。
動くときと、動かないときがある
そんなプログラム、実用できないんだが……。
13:00:05'042 35a2_cpp main commandLineArguments=[--enqueue 1113 durable --dequeue 1112 durable autodelete ]
13:00:05'043 35a2_cpp main dump begin
13:00:05'043 tamesi35a2_cs.cs Dump
name_queues [ENQUEUE_INDEX] =[1113]
lifeSpan_queues [ENQUEUE_INDEX] =[1]
----
name_queues [DEQUEUE_INDEX] =[1112]
lifeSpan_queues [DEQUEUE_INDEX] =[3]
----
13:00:05'043 35a2_cpp main dump end
13:00:05'043 35a2_cpp ___(C) ___ begin
13:00:05'043 35a2_cpp ___(C) DQ_ begin
13:00:05'044 35a2_cpp ___(C) channel.open begin
13:00:05'044 35a2_cpp ___(C) connection.open begin
13:00:05'043 35a2_cpp (P)___ WKP begin
13:00:05'044 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:00:05'044 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:00:05'044 35a2_cpp (P)___ channel.open begin
13:00:05'044 35a2_cpp (P)___ connection.open begin
13:00:05'050 35a2_cpp ___(C) connection.open end
13:00:05'051 35a2_cpp ___(C) channel.open end
13:00:05'051 35a2_cpp ___(C) DQ_ end
13:00:05'051 35a2_cpp ___(C) CNS begin
13:00:05'051 35a2_cpp ___(C) CNS end
13:00:05'051 35a2_cpp ___(C) ___ ev_run begin
13:00:05'051 35a2_cpp (P)___ connection.open end
13:00:05'051 35a2_cpp (P)___ channel.open end
13:00:05'051 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:00:05'051 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:00:05'052 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:00:05'052 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:00:05'179 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:27'923 35a2_cpp ___(C) CNS.received begin [a]
13:01:27'923 35a2_cpp ___(C) RTB.putMessage begin [0] before lock [a]
13:01:27'924 35a2_cpp ___(C) RTB.putMessage begin [0] [a]
13:01:27'924 35a2_cpp ___(C) RTB.putMessage end next=[1]
13:01:27'924 35a2_cpp ___(C) CNS.received.ack begin [1] [a]
13:01:27'924 35a2_cpp ___(C) CNS.received.ack end [1]
13:01:27'924 35a2_cpp ___(C) CNS.received end [a]
13:01:27'937 35a2_cpp (P)___ RTB.removeMessage begin [0] [a]
13:01:27'937 35a2_cpp (P)___ RTB.removeMessage end return=[a] next=[1]
13:01:27'937 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[adaze] ****important****
13:01:27'937 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:27'937 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:27'957 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:27'963 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [adaze] **********important**********
13:01:27'963 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:27'963 35a2_cpp (P)___ connection.close begin
13:01:27'963 35a2_cpp (P)___ channel.close begin
13:01:27'963 35a2_cpp (P)___ channel.close end
13:01:27'963 35a2_cpp (P)___ connection.close end
13:01:27'963 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:27'971 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:27'971 35a2_cpp (P)___ WKP.SM_ end
13:01:27'971 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:27'971 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:27'971 35a2_cpp (P)___ channel.open begin
13:01:27'971 35a2_cpp (P)___ connection.open begin
13:01:27'971 35a2_cpp (P)___ connection.open end
13:01:27'971 35a2_cpp (P)___ channel.open end
13:01:27'971 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:27'971 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:27'971 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:27'971 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:27'977 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:32'233 35a2_cpp ___(C) CNS.received begin [b]
13:01:32'233 35a2_cpp ___(C) RTB.putMessage begin [1] before lock [b]
13:01:32'233 35a2_cpp ___(C) RTB.putMessage begin [1] [b]
13:01:32'233 35a2_cpp ___(C) RTB.putMessage end next=[2]
13:01:32'233 35a2_cpp ___(C) CNS.received.ack begin [2] [b]
13:01:32'234 35a2_cpp ___(C) CNS.received.ack end [2]
13:01:32'234 35a2_cpp ___(C) CNS.received end [b]
13:01:32'239 35a2_cpp (P)___ RTB.removeMessage begin [1] [b]
13:01:32'239 35a2_cpp (P)___ RTB.removeMessage end return=[b] next=[2]
13:01:32'239 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[bdaze] ****important****
13:01:32'239 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:32'239 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:32'259 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:32'261 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [bdaze] **********important**********
13:01:32'261 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:32'261 35a2_cpp (P)___ connection.close begin
13:01:32'261 35a2_cpp (P)___ channel.close begin
13:01:32'261 35a2_cpp (P)___ channel.close end
13:01:32'261 35a2_cpp (P)___ connection.close end
13:01:32'261 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:32'262 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:32'262 35a2_cpp (P)___ WKP.SM_ end
13:01:32'262 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:32'262 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:32'262 35a2_cpp (P)___ channel.open begin
13:01:32'262 35a2_cpp (P)___ connection.open begin
13:01:32'262 35a2_cpp (P)___ connection.open end
13:01:32'263 35a2_cpp (P)___ channel.open end
13:01:32'263 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:32'263 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:32'263 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:32'263 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:32'274 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:34'722 35a2_cpp ___(C) CNS.received begin [c]
13:01:34'722 35a2_cpp ___(C) RTB.putMessage begin [2] before lock [c]
13:01:34'722 35a2_cpp ___(C) RTB.putMessage begin [2] [c]
13:01:34'722 35a2_cpp ___(C) RTB.putMessage end next=[3]
13:01:34'722 35a2_cpp ___(C) CNS.received.ack begin [3] [c]
13:01:34'722 35a2_cpp ___(C) CNS.received.ack end [3]
13:01:34'722 35a2_cpp ___(C) CNS.received end [c]
13:01:34'735 35a2_cpp (P)___ RTB.removeMessage begin [2] [c]
13:01:34'735 35a2_cpp (P)___ RTB.removeMessage end return=[c] next=[3]
13:01:34'735 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[cdaze] ****important****
13:01:34'735 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:34'735 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:34'755 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:34'756 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [cdaze] **********important**********
13:01:34'756 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:34'756 35a2_cpp (P)___ connection.close begin
13:01:34'756 35a2_cpp (P)___ channel.close begin
13:01:34'756 35a2_cpp (P)___ channel.close end
13:01:34'756 35a2_cpp (P)___ connection.close end
13:01:34'756 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:34'758 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:34'758 35a2_cpp (P)___ WKP.SM_ end
13:01:34'758 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:34'758 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:34'758 35a2_cpp (P)___ channel.open begin
13:01:34'758 35a2_cpp (P)___ connection.open begin
13:01:34'758 35a2_cpp (P)___ connection.open end
13:01:34'758 35a2_cpp (P)___ channel.open end
13:01:34'758 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:34'758 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:34'758 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:34'758 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:34'762 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:35'407 35a2_cpp ___(C) CNS.received begin [d]
13:01:35'407 35a2_cpp ___(C) RTB.putMessage begin [3] before lock [d]
13:01:35'407 35a2_cpp ___(C) RTB.putMessage begin [3] [d]
13:01:35'407 35a2_cpp ___(C) RTB.putMessage end next=[4]
13:01:35'407 35a2_cpp ___(C) CNS.received.ack begin [4] [d]
13:01:35'407 35a2_cpp ___(C) CNS.received.ack end [4]
13:01:35'407 35a2_cpp ___(C) CNS.received end [d]
13:01:35'427 35a2_cpp (P)___ RTB.removeMessage begin [3] [d]
13:01:35'427 35a2_cpp (P)___ RTB.removeMessage end return=[d] next=[4]
13:01:35'427 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[ddaze] ****important****
13:01:35'427 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:35'427 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:35'447 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:35'449 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [ddaze] **********important**********
13:01:35'449 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:35'449 35a2_cpp (P)___ connection.close begin
13:01:35'449 35a2_cpp (P)___ channel.close begin
13:01:35'449 35a2_cpp (P)___ channel.close end
13:01:35'449 35a2_cpp (P)___ connection.close end
13:01:35'449 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:35'450 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:35'450 35a2_cpp (P)___ WKP.SM_ end
13:01:35'450 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:35'450 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:35'450 35a2_cpp (P)___ channel.open begin
13:01:35'450 35a2_cpp (P)___ connection.open begin
13:01:35'451 35a2_cpp (P)___ connection.open end
13:01:35'451 35a2_cpp (P)___ channel.open end
13:01:35'451 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:35'451 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:35'451 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:35'451 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:35'457 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:36'358 35a2_cpp ___(C) CNS.received begin [e747;12R]
13:01:36'358 35a2_cpp ___(C) RTB.putMessage begin [4] before lock [e747;12R]
13:01:36'358 35a2_cpp ___(C) RTB.putMessage begin [4] [e747;12R]
13:01:36'358 35a2_cpp ___(C) RTB.putMessage end next=[5]
13:01:36'358 35a2_cpp ___(C) CNS.received.ack begin [5] [e747;12R]
13:01:36'358 35a2_cpp ___(C) CNS.received.ack end [5]
13:01:36'358 35a2_cpp ___(C) CNS.received end [e747;12R]
13:01:36'363 35a2_cpp (P)___ RTB.removeMessage begin [4] [e747;12R]
13:01:36'363 35a2_cpp (P)___ RTB.removeMessage end return=[e747;12R] next=[5]
13:01:36'363 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[e747;12Rdaze] ****important****
13:01:36'363 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:36'363 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:36'383 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:36'385 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [e747;12Rdaze] **********important**********
13:01:36'385 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:36'385 35a2_cpp (P)___ connection.close begin
13:01:36'385 35a2_cpp (P)___ channel.close begin
13:01:36'385 35a2_cpp (P)___ channel.close end
13:01:36'385 35a2_cpp (P)___ connection.close end
13:01:36'386 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:36'387 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:36'387 35a2_cpp (P)___ WKP.SM_ end
13:01:36'387 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:36'387 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:36'387 35a2_cpp (P)___ channel.open begin
13:01:36'387 35a2_cpp (P)___ connection.open begin
13:01:36'387 35a2_cpp (P)___ connection.open end
13:01:36'387 35a2_cpp (P)___ channel.open end
13:01:36'387 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:36'387 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:36'387 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:36'387 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:36'394 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:37'143 35a2_cpp ___(C) CNS.received begin [f]
13:01:37'143 35a2_cpp ___(C) RTB.putMessage begin [5] before lock [f]
13:01:37'143 35a2_cpp ___(C) RTB.putMessage begin [5] [f]
13:01:37'143 35a2_cpp ___(C) RTB.putMessage end next=[6]
13:01:37'143 35a2_cpp ___(C) CNS.received.ack begin [6] [f]
13:01:37'144 35a2_cpp ___(C) CNS.received.ack end [6]
13:01:37'144 35a2_cpp ___(C) CNS.received end [f]
13:01:37'144 35a2_cpp (P)___ RTB.removeMessage begin [5] [f]
13:01:37'144 35a2_cpp (P)___ RTB.removeMessage end return=[f] next=[6]
13:01:37'144 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[fdaze] ****important****
13:01:37'144 35a2_cpp (P)___ WKP.BQ_.OS_ if begin
13:01:37'144 35a2_cpp (P)___ WKP.BQ_.OS_ if end
13:01:37'164 35a2_cpp (P)___ WKP.BQ_.OS_ end
13:01:37'166 35a2_cpp (P)___ WKP.BQ_.OS_ CT_.onSuccess Commited [fdaze] **********important**********
13:01:37'166 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection begin
13:01:37'167 35a2_cpp (P)___ connection.close begin
13:01:37'167 35a2_cpp (P)___ channel.close begin
13:01:37'167 35a2_cpp (P)___ channel.close end
13:01:37'167 35a2_cpp (P)___ connection.close end
13:01:37'167 35a2_cpp (P)___ WKP.BQ_.OS_ closeConnection end
13:01:37'168 35a2_cpp (P)___ WKP.SM_ ev_run end
13:01:37'168 35a2_cpp (P)___ WKP.SM_ end
13:01:37'168 35a2_cpp (P)___ WKP.SM_ begin name_enqueue=[1113] lifeSpan_enqueue=[1] name_dequeue=[1112] lifeSpan_dequeue=[3]
13:01:37'168 35a2_cpp (P)___ WKP.SM_.declareQueue begin
13:01:37'168 35a2_cpp (P)___ channel.open begin
13:01:37'168 35a2_cpp (P)___ connection.open begin
13:01:37'168 35a2_cpp (P)___ connection.open end
13:01:37'168 35a2_cpp (P)___ channel.open end
13:01:37'168 35a2_cpp (P)___ WKP.SM_.declareQueue end
13:01:37'168 35a2_cpp (P)___ WKP.SM_.bindQueue begin
13:01:37'168 35a2_cpp (P)___ WKP.SM_.bindQueue end
13:01:37'168 35a2_cpp (P)___ WKP.SM_ ev_run begin
13:01:37'173 35a2_cpp (P)___ WKP.BQ_.OS_ begin
13:01:38'056 35a2_cpp ___(C) CNS.received begin [g]
13:01:38'056 35a2_cpp ___(C) RTB.putMessage begin [6] before lock [g]
13:01:38'056 35a2_cpp ___(C) RTB.putMessage begin [6] [g]
13:01:38'056 35a2_cpp ___(C) RTB.putMessage end next=[7]
13:01:38'056 35a2_cpp ___(C) CNS.received.ack begin [7] [g]
13:01:38'056 35a2_cpp ___(C) CNS.received.ack end [7]
13:01:38'056 35a2_cpp ___(C) CNS.received end [g]
13:01:38'069 35a2_cpp (P)___ RTB.removeMessage begin [6] [g]
13:01:38'069 35a2_cpp (P)___ RTB.removeMessage end return=[g] next=[7]
13:01:38'069 35a2_cpp (P)___ WKP.BQ_.OS_ next,publish message=[gdaze] ****important****
動いているときは コネクションの開け閉めができている感じ。
コマンドライン引数の解析
bool parseArgs(int argc, char* argv[], std::string& name_enqueue, LifeSpan_t& lifeSpan_enqueue, std::string& name_dequeue, LifeSpan_t& lifeSpan_dequeue)
{
if (0<argc)
{
// プログラム名を省き、コマンドライン引数だけをつなげる。
std::string cmdArg;
for (int i = 1; i < argc; ++i)
{
cmdArg += std::string(argv[i]);
if (i < argc) {
cmdArg += " ";
}
}
std::istringstream data(cmdArg);
std::cout << getTimeslipNow() << "35a2_cpp main commandLineArguments=[" << data.str() << "]" << std::endl;
// 与件
// 「--enqueue 1117 durable autodelete --dequeue 1116 durable autodelete」
// 寿命は可変個数設定可能「durable」「autodelete」「passive」「exclusive」
// 受け皿
// name_queues 結果はこれらの配列に入れる
// lifeSpan_queues
// 記憶
int m0 = -1; // enqueue or dequeue index.
int m1 = -1; // lifespans index.
// 解析器
std::string a;
while (data >> a) {
if ("--" == a.substr(0, 2)) {//先頭の2文字が「--」の場合
if ("--enqueue" == a) { m0 = ENQUEUE_INDEX; m1 = -1; }
else if ("--dequeue" == a) { m0 = DEQUEUE_INDEX; m1 = -1; }
else { break; }
}
else if (
">" == a.substr(0, 1)//先頭の1文字が「>」の場合
|| "<" == a.substr(0, 1)//「<」
|| ">" == a.substr(1, 1)//先頭から2文字目が「>」の場合
) {
break;
} else if (0 == m0) { // エンキュー先キュー名
if (-1 == m1) {
name_enqueue = a;
lifeSpan_enqueue = 0;
m1++;
}
else {
lifeSpan_enqueue |= LifeSpanString_To_Int(a);
}
} else if ( 1 == m0) { // デキュー元キュー名
if (-1 == m1) {
name_dequeue = a;
lifeSpan_dequeue = 0;
m1++;
}
else {
lifeSpan_dequeue |= LifeSpanString_To_Int(a);
}
}
else
{
}
}
if ("" == name_enqueue || "" == name_dequeue) {
goto gt_CommandlineParameterError;
}
std::cout << getTimeslipNow() << "35a2_cpp main dump begin" << std::endl;
std::cout << getTimeslipNow() << Dump();
std::cout << getTimeslipNow() << "35a2_cpp main dump end" << std::endl;
}
else
{
goto gt_CommandlineParameterError;
}
return true;
gt_CommandlineParameterError:
std::cerr << getTimeslipNow() << "コマンドライン引数の「--enqueue 送信先キュー名 寿命」「--dequeue 受信元キュー名 寿命」を漏れなく指定してください。" << std::endl
<< "例: --enqueue 1117 durable autodelete --dequeue 1116 durable autodelete" << std::endl
<< "寿命は可変個数設定可能「durable」「autodelete」「passive」「exclusive」" << std::endl
<< "queueNames[0]=[" << name_queues[ENQUEUE_INDEX] << "]" << std::endl
<< "queueNames[1]=[" << name_queues[DEQUEUE_INDEX] << "]" << std::endl;
return false;
}
使い方
int main(int argc, char* argv[])
{
// 引数の解析
if (!parseArgs(argc, argv, name_queues[ENQUEUE_INDEX], lifeSpan_queues[ENQUEUE_INDEX], name_queues[DEQUEUE_INDEX], lifeSpan_queues[DEQUEUE_INDEX]))
{
exit(12);
}
// キューの監視スレッド、メッセージの送信スレッドをスタート
{
auto th1 = std::thread([] { workConsume(); });
auto th2 = std::thread([] { workProduce(); });
for (;;) // このメイン・スレッドはずっと寝てる
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
// このプログラムは、自分では接続を切らないので、ここから下には来ない
th2.join();
th1.join();
}
return 0;
}
浮かむ瀬 のコマンドライン引数は
パラメーターというより、コマンドを叩いたのと同じように処理されるのだった。
./apery --enqueue 1113 durable --dequeue 1112 durable autodelete > ./apery.out.log 2> ./apery.err.log < /dev/null &
と書いて実行すると、
--enqueue 1113 durable --dequeue 1112 durable autodelete
というコマンドを叩いたが、未対応のコマンドです、みたいになってしまう。
「--enqueue」「--dequeue」は スルーするように改造しよう。
usi までは届く
# ./tamesi34_cs.exe 2> ./tamesi34_cs.err.log
削除したいキューがあれば名前を、無ければ空文字列を入れろだぜ☆(^~^)
Name : キューを削除します
"" + [Enter] : 次のステップへ進む
ex.) BrokenBox
Delete ? >
エンキュー先のメッセージ・キューの名前を入れろだぜ☆(^~^)
ex.) SunnyBox
Enqueue ? > 1112
エンキュー先のメッセージ・キューの寿命を、足し算して答えろだぜ☆(^~^)
(1) durable : RabbitMQが止まってもキューを残す
(2) autodelete : コンシューマーが1人も接続していなかったら消す
(4) passive : キューが存在するかどうかチェックするだけ。中身見ない時これ
(8) exclusive : この接続でだけ使える。この接続が切れたら消す
ex.) 3
Enqueue ? > 3
デキュー先のメッセージ・キューの名前を入れろだぜ☆(^~^)
ex.) RainyBox
Dequeue ? > 1113
デキュー先のメッセージ・キューの寿命を、足し算して答えろだぜ☆(^~^)
(1) durable : RabbitMQが止まってもキューを残す
(2) autodelete : コンシューマーが1人も接続していなかったら消す
(4) passive : キューが存在するかどうかチェックするだけ。中身見ない時これ
(8) exclusive : この接続でだけ使える。この接続が切れたら消す
ex.) 1
Dequeue ? > 1
01:27:52 960 34_cs ___(C) start begin
01:27:52 969 34_cs ___(C) consumer.create begin
01:27:52 970 34_cs ___(C) consumer.create end
01:27:52 971 34_cs ___(C) channel.open begin
01:27:52 972 34_cs ___(C) connection.open begin
01:27:53 172 34_cs ___(C) connection.open end
01:27:53 178 34_cs ___(C) channel.open end
01:27:53 181 34_cs <-------- [interrupt!] Registered(^q^)
01:27:53 181 34_cs ___(C) start end
01:27:53 181 34_cs (P)___ waitRegistered begin
01:27:53 181 34_cs (P)___ waitRegistered end
終了するときは[Ctrl]+[C]キーを押せだぜ☆(^~^)
エンキューするときはメッセージを打ち込んで[Enter]キーを押せだぜ☆(^◇^)
ex.) hello, world
Enqueue? > a
01:27:54 077 34_cs (P)___ enqueue begin [a]
01:27:54 078 34_cs (P)___ channel.open begin
01:27:54 078 34_cs (P)___ connection.open begin
01:27:54 097 34_cs (P)___ connection.open end
01:27:54 100 34_cs (P)___ channel.open end
01:27:54 104 34_cs (P)___ enqueue end
01:27:54 104 34_cs (P)___ connection.close begin
01:27:54 104 34_cs (P)___ channel.close begin
01:27:54 115 34_cs (P)___ channel.close end
01:27:54 128 34_cs <-------- [interrupt!] Dequeue(^q^) unknown command: a
01:27:54 130 34_cs (P)___ connection.close end
Enqueue? > usi
01:28:00 966 34_cs (P)___ enqueue begin [usi]
01:28:00 967 34_cs (P)___ channel.open begin
01:28:00 967 34_cs (P)___ connection.open begin
01:28:00 995 34_cs (P)___ connection.open end
01:28:00 997 34_cs (P)___ channel.open end
01:28:00 997 34_cs (P)___ enqueue end
01:28:00 997 34_cs (P)___ connection.close begin
01:28:00 997 34_cs (P)___ channel.close begin
01:28:01 001 34_cs (P)___ channel.close end
01:28:01 003 34_cs (P)___ connection.close end
Enqueue? > 01:28:01 019 34_cs <-------- [interrupt!] Dequeue(^q^) unknown command: a
id name ukamuse_SDT4
id author Hiraoka Takuya
option name Best_Book_Move type check default false
option name Book_File type string default book/20150503/book.bin
option name Byoyomi_Margin type spin default 500 min 0 max 2147483647
option name Clear_Hash type button
option name Draw_Ply type spin default 256 min 1 max 2147483647
option name Engine_Name type string default ukamuse_SDT4
option name Max_Book_Ply type spin default 32767 min 0 max 32767
option name Max_Random_Score_Diff type spin default 0 min 0 max 32600
option name Max_Random_Score_Diff_Ply type spin default 32767 min 0 max 32767
option name Min_Book_Ply type spin default 32767 min 0 max 32767
option name Min_Book_Score type spin default -180 min -32601 max 32601
option name Minimum_Thinking_Time type spin default 20 min 0 max 2147483647
option name Move_Overhead type spin default 30 min 0 max 5000
option name MultiPV type spin default 1 min 1 max 594
option name OwnBook type check default true
option name Slow_Mover type spin default 89 min 1 max 1000
option name Slow_Mover_10 type spin default 10 min 1 max 1000
option name Slow_Mover_16 type spin default 20 min 1 max 1000
option name Slow_Mover_20 type spin default 40 min 1 max 1000
option name Threads type spin default 2 min 1 max 256
option name Time_Margin type spin default 4500 min 0 max 2147483647
option name USI_Hash type spin default 256 min 1 max 1048576
option name USI_Ponder type check default true
usiok
isready
01:28:08 774 34_cs (P)___ enqueue begin [isready]
01:28:08 774 34_cs (P)___ channel.open begin
01:28:08 774 34_cs (P)___ connection.open begin
01:28:08 795 34_cs (P)___ connection.open end
01:28:08 797 34_cs (P)___ channel.open end
01:28:08 797 34_cs (P)___ enqueue end
01:28:08 797 34_cs (P)___ connection.close begin
01:28:08 797 34_cs (P)___ channel.close begin
01:28:08 800 34_cs (P)___ channel.close end
01:28:08 801 34_cs (P)___ connection.close end
Enqueue? > isready
01:28:23 339 34_cs (P)___ enqueue begin [isready]
01:28:23 352 34_cs (P)___ channel.open begin
01:28:23 353 34_cs (P)___ connection.open begin
01:28:23 422 34_cs (P)___ connection.open end
01:28:23 456 34_cs (P)___ channel.open end
01:28:23 456 34_cs (P)___ enqueue end
01:28:23 456 34_cs (P)___ connection.close begin
01:28:23 457 34_cs (P)___ channel.close begin
01:28:23 461 34_cs (P)___ channel.close end
01:28:23 464 34_cs (P)___ connection.close end
Enqueue? > isready
01:28:45 299 34_cs (P)___ enqueue begin [isready]
01:28:45 300 34_cs (P)___ channel.open begin
01:28:45 300 34_cs (P)___ connection.open begin
01:28:45 315 34_cs (P)___ connection.open end
01:28:45 317 34_cs (P)___ channel.open end
01:28:45 318 34_cs (P)___ enqueue end
01:28:45 318 34_cs (P)___ connection.close begin
01:28:45 318 34_cs (P)___ channel.close begin
01:28:45 319 34_cs (P)___ channel.close end
01:28:45 320 34_cs (P)___ connection.close end
Enqueue? >
usi の応答があったあと、応答が無くなってしまった。
apery は bin フォルダーの下に入れて実行する必要がある
そうだった、関連するファイルが bin の中にあるのだった。
01:48:46 952 34_cs ___(C) start begin
01:48:46 957 34_cs ___(C) consumer.create begin
01:48:46 958 34_cs ___(C) consumer.create end
01:48:46 959 34_cs ___(C) channel.open begin
01:48:46 959 34_cs ___(C) connection.open begin
01:48:47 131 34_cs ___(C) connection.open end
01:48:47 136 34_cs ___(C) channel.open end
01:48:47 140 34_cs <-------- [interrupt!] Registered(^q^)
01:48:47 141 34_cs ___(C) start end
01:48:47 141 34_cs (P)___ waitRegistered begin
01:48:47 141 34_cs (P)___ waitRegistered end
終了するときは[Ctrl]+[C]キーを押せだぜ☆(^~^)
エンキューするときはメッセージを打ち込んで[Enter]キーを押せだぜ☆(^◇^)
ex.) hello, world
Enqueue? > position sfen lnsgkgsnl / 1r5b1 / ppppppppp / 9 / 9 / 9 / PPPPPPPPP / 1B5R1 / LNSGKGSNL b - 1 moves
01:48:54 088 34_cs (P)___ enqueue begin [position sfen lnsgkgsnl / 1r5b1 / ppppppppp / 9 / 9 / 9 / PPPPPPPPP / 1B5R1 / LNSGKGSNL b - 1 moves]
01:48:54 089 34_cs (P)___ channel.open begin
01:48:54 089 34_cs (P)___ connection.open begin
01:48:54 109 34_cs (P)___ connection.open end
01:48:54 111 34_cs (P)___ channel.open end
01:48:54 116 34_cs (P)___ enqueue end
01:48:54 117 34_cs (P)___ connection.close begin
01:48:54 118 34_cs (P)___ channel.close begin
01:48:54 124 34_cs (P)___ channel.close end
01:48:54 132 34_cs (P)___ connection.close end
Enqueue? > 01:48:54 156 34_cs <-------- [interrupt!] Dequeue(^q^) incorrect SFEN string : lnsgkgsnl / 1r5b1 / ppppppppp / 9 / 9 / 9 / PPPPPPPPP / 1B5R1 / LNSGKGSNL b - 1
あれっ、moves はどこへ消えたのか? - 1 が何か悪いのか?
Dequeue ? > 1
01:53:51 203 34_cs ___(C) start begin
01:53:51 209 34_cs ___(C) consumer.create begin
01:53:51 209 34_cs ___(C) consumer.create end
01:53:51 210 34_cs ___(C) channel.open begin
01:53:51 211 34_cs ___(C) connection.open begin
01:53:51 374 34_cs ___(C) connection.open end
01:53:51 379 34_cs ___(C) channel.open end
01:53:51 382 34_cs <-------- [interrupt!] Registered(^q^)
01:53:51 382 34_cs ___(C) start end
01:53:51 382 34_cs (P)___ waitRegistered begin
01:53:51 382 34_cs (P)___ waitRegistered end
終了するときは[Ctrl]+[C]キーを押せだぜ☆(^~^)
エンキューするときはメッセージを打ち込んで[Enter]キーを押せだぜ☆(^◇^)
ex.) hello, world
Enqueue? > position sfen lnsgkgsnl / 1r5b1 / ppppppppp / 9 / 9 / 9 / PPPPPPPPP / 1B5R1 / LNSGKGSNL b - 1 moves
01:53:57 667 34_cs (P)___ enqueue begin [position sfen lnsgkgsnl / 1r5b1 / ppppppppp / 9 / 9 / 9 / PPPPPPPPP / 1B5R1 / LNSGKGSNL b - 1 moves]
01:53:57 668 34_cs (P)___ channel.open begin
01:53:57 668 34_cs (P)___ connection.open begin
01:53:57 677 34_cs (P)___ connection.open end
01:53:57 679 34_cs (P)___ channel.open end
01:53:57 685 34_cs (P)___ enqueue end
01:53:57 685 34_cs (P)___ connection.close begin
01:53:57 685 34_cs (P)___ channel.close begin
01:53:57 691 34_cs (P)___ channel.close end
01:53:57 702 34_cs (P)___ connection.close end
Enqueue? > go
01:54:07 378 34_cs (P)___ enqueue begin [go]
01:54:07 378 34_cs (P)___ channel.open begin
01:54:07 378 34_cs (P)___ connection.open begin
01:54:07 388 34_cs (P)___ connection.open end
01:54:07 390 34_cs (P)___ channel.open end
01:54:07 391 34_cs (P)___ enqueue end
01:54:07 392 34_cs (P)___ connection.close begin
01:54:07 392 34_cs (P)___ channel.close begin
01:54:07 393 34_cs (P)___ channel.close end
01:54:07 395 34_cs (P)___ connection.close end
この反応が無くなるやつは なんなんだろう?
position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves
なんか 余計な空白が入っていたので詰めた。
ツーカー
else if (token == "tu") {
#if UBUNTU
// tu と飛んできたら ka と返す
service_io::sendMessage("ka");
#else
std::cerr << "Command error : \"tu\" command for UBUNTU.";
#endif
}
こんなん入れてみた。
Dequeue ? > 1
02:10:42 226 34_cs ___(C) start begin
02:10:42 230 34_cs ___(C) consumer.create begin
02:10:42 230 34_cs ___(C) consumer.create end
02:10:42 231 34_cs ___(C) channel.open begin
02:10:42 232 34_cs ___(C) connection.open begin
02:10:42 417 34_cs ___(C) connection.open end
02:10:42 422 34_cs ___(C) channel.open end
02:10:42 424 34_cs <-------- [interrupt!] Registered(^q^)
02:10:42 425 34_cs ___(C) start end
02:10:42 425 34_cs (P)___ waitRegistered begin
02:10:42 425 34_cs (P)___ waitRegistered end
終了するときは[Ctrl]+[C]キーを押せだぜ☆(^~^)
エンキューするときはメッセージを打ち込んで[Enter]キーを押せだぜ☆(^◇^)
ex.) hello, world
Enqueue? > position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves
02:10:53 690 34_cs (P)___ enqueue begin [position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves]
02:10:53 691 34_cs (P)___ channel.open begin
02:10:53 691 34_cs (P)___ connection.open begin
02:10:53 700 34_cs (P)___ connection.open end
02:10:53 702 34_cs (P)___ channel.open end
02:10:53 708 34_cs (P)___ enqueue end
02:10:53 709 34_cs (P)___ connection.close begin
02:10:53 710 34_cs (P)___ channel.close begin
02:10:53 716 34_cs (P)___ channel.close end
02:10:53 723 34_cs (P)___ connection.close end
Enqueue? > tu
02:11:00 433 34_cs (P)___ enqueue begin [tu]
02:11:00 433 34_cs (P)___ channel.open begin
02:11:00 434 34_cs (P)___ connection.open begin
02:11:00 439 34_cs (P)___ connection.open end
02:11:00 441 34_cs (P)___ channel.open end
02:11:00 443 34_cs (P)___ enqueue end
02:11:00 444 34_cs (P)___ connection.close begin
02:11:00 444 34_cs (P)___ channel.close begin
02:11:00 445 34_cs (P)___ channel.close end
02:11:00 447 34_cs (P)___ connection.close end
Enqueue? > 02:11:00 470 34_cs <-------- [interrupt!] Dequeue(^q^) ka
応答が返ってくるということは、ローテーション・バッファーが ロック状態になってるんじゃないか?
position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves
02:12:55 496 34_cs (P)___ enqueue begin [position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves]
02:12:55 496 34_cs (P)___ channel.open begin
02:12:55 497 34_cs (P)___ connection.open begin
02:12:55 524 34_cs (P)___ connection.open end
02:12:55 527 34_cs (P)___ channel.open end
02:12:55 527 34_cs (P)___ enqueue end
02:12:55 527 34_cs (P)___ connection.close begin
02:12:55 527 34_cs (P)___ channel.close begin
02:12:55 529 34_cs (P)___ channel.close end
02:12:55 531 34_cs (P)___ connection.close end
Enqueue? > 02:12:55 550 34_cs <-------- [interrupt!] Dequeue(^q^) unknown command: position sfen lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1 moves
うーむ、なんで?
02:15:19 949 34_cs (P)___ enqueue begin []
02:15:19 950 34_cs (P)___ channel.open begin
02:15:19 950 34_cs (P)___ connection.open begin
02:15:19 963 34_cs (P)___ connection.open end
02:15:19 973 34_cs (P)___ channel.open end
02:15:19 973 34_cs (P)___ enqueue end
02:15:19 973 34_cs (P)___ connection.close begin
02:15:19 973 34_cs (P)___ channel.close begin
02:15:19 975 34_cs (P)___ channel.close end
02:15:19 976 34_cs (P)___ connection.close end
Enqueue? > tu
02:15:23 436 34_cs (P)___ enqueue begin [tu]
02:15:23 437 34_cs (P)___ channel.open begin
02:15:23 437 34_cs (P)___ connection.open begin
02:15:23 454 34_cs (P)___ connection.open end
02:15:23 456 34_cs (P)___ channel.open end
02:15:23 456 34_cs (P)___ enqueue end
02:15:23 456 34_cs (P)___ connection.close begin
02:15:23 457 34_cs (P)___ channel.close begin
02:15:23 458 34_cs (P)___ channel.close end
02:15:23 459 34_cs (P)___ connection.close end
Enqueue? > tu
02:15:25 636 34_cs (P)___ enqueue begin [tu]
02:15:25 636 34_cs (P)___ channel.open begin
02:15:25 636 34_cs (P)___ connection.open begin
02:15:25 641 34_cs (P)___ connection.open end
02:15:25 643 34_cs (P)___ channel.open end
02:15:25 643 34_cs (P)___ enqueue end
02:15:25 643 34_cs (P)___ connection.close begin
02:15:25 644 34_cs (P)___ channel.close begin
02:15:25 645 34_cs (P)___ channel.close end
02:15:25 647 34_cs (P)___ connection.close end
Enqueue? >
tu も効かなくなった。
# jobs
[1]+ Running ./apery --enqueue 1113 durable --dequeue 1112 durable autodelete > ./apery.out.log 2> ./apery.err.log < /dev/null & (wd: /home/★user/shogi/ukamuse_sdt4_child4/bin)