diff --git a/BenchmarkTest.md b/BenchmarkTest.md new file mode 100644 index 0000000..c0de5ee --- /dev/null +++ b/BenchmarkTest.md @@ -0,0 +1,257 @@ +### Using Apache AB for HTTPSQS Benchmark Test: ### + +CPU:Intel(R) Xeon(R) CPU E5540 @ 2.53GHz + + +--- + + +### PUT 512 bytes text message into a queue (With Keep-Alive): 23018 requests/sec ### + +``` +[root@xoyo ~]# ab -k -c 10 -n 100000 "http://127.0.0.1:1218/?name=xoyo&opt=put&data=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ +Copyright 2006 The Apache Software Foundation, http://www.apache.org/ + +Benchmarking 127.0.0.1 (be patient) +Completed 10000 requests +Completed 20000 requests +Completed 30000 requests +Completed 40000 requests +Completed 50000 requests +Completed 60000 requests +Completed 70000 requests +Completed 80000 requests +Completed 90000 requests +Finished 100000 requests + + +Server Software: +Server Hostname: 127.0.0.1 +Server Port: 1218 + +Document Path: /?name=xoyo&opt=put&data=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +Document Length: 14 bytes + +Concurrency Level: 10 +Time taken for tests: 4.344264 seconds +Complete requests: 100000 +Failed requests: 0 +Write errors: 0 +Keep-Alive requests: 100000 +Total transferred: 16388896 bytes +HTML transferred: 1400000 bytes +Requests per second: 23018.86 [#/sec] (mean) +Time per request: 0.434 [ms] (mean) +Time per request: 0.043 [ms] (mean, across all concurrent requests) +Transfer rate: 3683.94 [Kbytes/sec] received + +Connection Times (ms) + min mean[+/-sd] median max +Connect: 0 0 0.0 0 0 +Processing: 0 0 1.1 0 108 +Waiting: 0 0 1.1 0 108 +Total: 0 0 1.1 0 108 + +Percentage of the requests served within a certain time (ms) + 50% 0 + 66% 0 + 75% 0 + 80% 0 + 90% 0 + 95% 0 + 98% 0 + 99% 0 + 100% 108 (longest request) +``` + + +--- + + +### GET 512 bytes text message from a queue (With Keep-Alive): 25982 requests/sec ### + +``` +[root@xoyo ~]# ab -k -c 10 -n 100000 "http://127.0.0.1:1218/?name=xoyo&opt=get" +This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ +Copyright 2006 The Apache Software Foundation, http://www.apache.org/ + +Benchmarking 127.0.0.1 (be patient) +Completed 10000 requests +Completed 20000 requests +Completed 30000 requests +Completed 40000 requests +Completed 50000 requests +Completed 60000 requests +Completed 70000 requests +Completed 80000 requests +Completed 90000 requests +Finished 100000 requests + + +Server Software: +Server Hostname: 127.0.0.1 +Server Port: 1218 + +Document Path: /?name=xoyo&opt=get +Document Length: 512 bytes + +Concurrency Level: 10 +Time taken for tests: 3.848696 seconds +Complete requests: 100000 +Failed requests: 0 +Write errors: 0 +Keep-Alive requests: 100000 +Total transferred: 66288898 bytes +HTML transferred: 51200000 bytes +Requests per second: 25982.83 [#/sec] (mean) +Time per request: 0.385 [ms] (mean) +Time per request: 0.038 [ms] (mean, across all concurrent requests) +Transfer rate: 16819.98 [Kbytes/sec] received + +Connection Times (ms) + min mean[+/-sd] median max +Connect: 0 0 0.0 0 0 +Processing: 0 0 0.0 0 2 +Waiting: 0 0 0.0 0 2 +Total: 0 0 0.0 0 2 + +Percentage of the requests served within a certain time (ms) + 50% 0 + 66% 0 + 75% 0 + 80% 0 + 90% 0 + 95% 0 + 98% 0 + 99% 0 + 100% 2 (longest request) +``` + + +--- + + +### PUT 512 bytes text message into a queue (Without Keep-Alive): 11840 requests/sec ### + +``` +[root@xoyo ~]# ab -c 10 -n 100000 "http://127.0.0.1:1218/?name=xoyo&opt=put&data=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ +Copyright 2006 The Apache Software Foundation, http://www.apache.org/ + +Benchmarking 127.0.0.1 (be patient) +Completed 10000 requests +Completed 20000 requests +Completed 30000 requests +Completed 40000 requests +Completed 50000 requests +Completed 60000 requests +Completed 70000 requests +Completed 80000 requests +Completed 90000 requests +Finished 100000 requests + + +Server Software: +Server Hostname: 127.0.0.1 +Server Port: 1218 + +Document Path: /?name=xoyo&opt=put&data=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +Document Length: 14 bytes + +Concurrency Level: 10 +Time taken for tests: 8.445621 seconds +Complete requests: 100000 +Failed requests: 0 +Write errors: 0 +Total transferred: 8788895 bytes +HTML transferred: 1400000 bytes +Requests per second: 11840.46 [#/sec] (mean) +Time per request: 0.845 [ms] (mean) +Time per request: 0.084 [ms] (mean, across all concurrent requests) +Transfer rate: 1016.15 [Kbytes/sec] received + +Connection Times (ms) + min mean[+/-sd] median max +Connect: 0 0 0.0 0 0 +Processing: 0 0 0.8 0 58 +Waiting: 0 0 0.8 0 58 +Total: 0 0 0.8 0 58 + +Percentage of the requests served within a certain time (ms) + 50% 0 + 66% 0 + 75% 0 + 80% 0 + 90% 1 + 95% 1 + 98% 1 + 99% 1 + 100% 58 (longest request) +``` + + +--- + + +### GET 512 bytes text message from a queue (Without Keep-Alive): 13294 requests/sec ### + +``` +[root@xoyo ~]# ab -c 10 -n 100000 "http://127.0.0.1:1218/?name=xoyo&opt=get" +This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 +Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ +Copyright 2006 The Apache Software Foundation, http://www.apache.org/ + +Benchmarking 127.0.0.1 (be patient) +Completed 10000 requests +Completed 20000 requests +Completed 30000 requests +Completed 40000 requests +Completed 50000 requests +Completed 60000 requests +Completed 70000 requests +Completed 80000 requests +Completed 90000 requests +Finished 100000 requests + + +Server Software: +Server Hostname: 127.0.0.1 +Server Port: 1218 + +Document Path: /?name=xoyo&opt=get +Document Length: 512 bytes + +Concurrency Level: 10 +Time taken for tests: 7.521673 seconds +Complete requests: 100000 +Failed requests: 0 +Write errors: 0 +Total transferred: 58700000 bytes +HTML transferred: 51200000 bytes +Requests per second: 13294.91 [#/sec] (mean) +Time per request: 0.752 [ms] (mean) +Time per request: 0.075 [ms] (mean, across all concurrent requests) +Transfer rate: 7621.18 [Kbytes/sec] received + +Connection Times (ms) + min mean[+/-sd] median max +Connect: 0 0 0.0 0 0 +Processing: 0 0 0.1 0 2 +Waiting: 0 0 0.1 0 2 +Total: 0 0 0.1 0 2 + +Percentage of the requests served within a certain time (ms) + 50% 0 + 66% 0 + 75% 0 + 80% 0 + 90% 0 + 95% 0 + 98% 0 + 99% 1 + 100% 2 (longest request) +``` \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index bbc84f3..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# Makefile for httpsqs -CC=gcc -CFLAGS=-Wl,-rpath,/usr/local/libevent-2.0.12-stable/lib/:/usr/local/tokyocabinet-1.4.47/lib/ -L/usr/local/libevent-2.0.12-stable/lib/ -levent -L/usr/local/tokyocabinet-1.4.47/lib/ -ltokyocabinet -I/usr/local/libevent-2.0.12-stable/include/ -I/usr/local/tokyocabinet-1.4.47/include/ -lz -lbz2 -lrt -lpthread -lm -lc -O2 -g - -httpsqs: httpsqs.c - $(CC) -o httpsqs httpsqs.c prename.c $(CFLAGS) - @echo "" - @echo "httpsqs build complete." - @echo "" - -clean: httpsqs - rm -f httpsqs - -install: httpsqs - install $(INSTALL_FLAGS) -m 4755 -o root httpsqs $(DESTDIR)/usr/bin diff --git a/ProjectHome.md b/ProjectHome.md new file mode 100644 index 0000000..c641776 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1,482 @@ +> HTTPSQS is a Simple Queue Service based on HTTP GET/POST protocol. + +> This is free software, and you are welcome to modify and redistribute it under the New BSD License. + +> [点击这里查看简体中文使用说明 (Click here to see the Simplified Chinese instructions)](http://blog.s135.com/httpsqs/) + +## 1. Features ## + + * Very simple + + * Very fast, more than 10000 requests/sec + + * High concurrency, support the tens of thousands of concurrent connections. + + * Multiple queue + + * A single queue length maximum support one billion (1,000,000,000). + + * Low memory consumption, mass data storage, storage dozens of GB of data takes less than 100MB of physical memory buffer. + + * Convenient to change the maximum queue length of per-queue. + + * Queue status view + + * Be able to view the contents of the specified queue ID. + + * Multi-Character encoding support + + * Less than 900 lines source code, easy to second development. + + +--- + + +## 2. Benchmark Test ## + +> [Using Apache AB for HTTPSQS Benchmark Test](http://code.google.com/p/httpsqs/wiki/BenchmarkTest) + + +--- + + +![http://blog.s135.com/attachment/200912/httpsqs_elements.png](http://blog.s135.com/attachment/200912/httpsqs_elements.png) + + +--- + + +## 3. Server Install ## + +> Operating System: CentOS Linux 5.4 + +``` +ulimit -SHn 65535 + +wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz +tar zxvf libevent-2.0.12-stable.tar.gz +cd libevent-2.0.12-stable/ +./configure --prefix=/usr/local/libevent-2.0.12-stable/ +make +make install +cd ../ + +wget http://httpsqs.googlecode.com/files/tokyocabinet-1.4.47.tar.gz +tar zxvf tokyocabinet-1.4.47.tar.gz +cd tokyocabinet-1.4.47/ +./configure --prefix=/usr/local/tokyocabinet-1.4.47/ +#Note: In the 32-bit Linux operating system, compiler Tokyo cabinet, please use the ./configure --enable-off64 instead of ./configure to breakthrough the filesize limit of 2GB. +#./configure --enable-off64 --prefix=/usr/local/tokyocabinet-1.4.47/ +make +make install +cd ../ + +wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz +tar zxvf httpsqs-1.7.tar.gz +cd httpsqs-1.7/ +make +make install +cd ../ +``` + + +--- + + +## 4. Server Document ## + +> ![http://blog.s135.com/attachment/201006/httpsqs.png](http://blog.s135.com/attachment/201006/httpsqs.png) + +> `[root@xoyo ~]# httpsqs -h` + +``` + -l interface to listen on, default is 0.0.0.0 + -p TCP port number to listen on (default: 1218) + -x database directory (example: /opt/httpsqs/data) + -t timeout for an http request (default: 3) + -s the interval to sync updated contents to the disk (default: 5) + -c the maximum number of non-leaf nodes to be cached (default: 1024) + -m database memory cache size in MB (default: 100) + -i save PID in (default: /tmp/httpsqs.pid) + -a the auth password to access httpsqs (example: mypass123) + -d run as a daemon + -h print this help and exit +``` + +> Example: + +``` +ulimit -SHn 65535 +httpsqs -d -p 1218 -x /data0/queue +``` + +> or with auth password: + +``` +ulimit -SHn 65535 +httpsqs -d -p 1218 -x /data0/queue -a mypass123 +``` + + +> Use command "killall httpsqs", "pkill httpsqs" and "kill `cat /tmp/httpsqs.pid`" to stop httpsqs. + +> Please note that don't use the command "pkill -9 httpsqs" and "kill -9 PID of httpsqs", otherwise, the data in memory has not been saved to disk will be lost. + + +--- + + +## 5. Client Document ## + +> Important Notice: The message must be GET before the PUT position to catch up with the GET position in the circle. + +#### (1). PUT text message into a queue #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=put&data=url_encoded_text_message&auth=mypass123" +``` + +> or + +> HTTP POST protocol (Using curl for example): + +``` +curl -d "url_encoded_text_message" "http://host:port/?name=your_queue_name&opt=put&auth=mypass123" +``` + +> Using google chrome browser for example: + +> ![http://blog.s135.com/attachment/200912/put.png](http://blog.s135.com/attachment/200912/put.png) + +> If PUT successful, return: + +``` +HTTPSQS_PUT_OK +``` + +> If an error occurs, return: + +``` +HTTPSQS_PUT_ERROR +``` + +> If Queue full, return: + +``` +HTTPSQS_PUT_END +``` + +> HTTPSQS add a line "Pos: xxx" in the HTTP header and sends that back to the client since version 1.2, the "xxx" is the put pos of the current queue. For example: + +``` +HTTP/1.1 200 OK +Content-Type: text/plain +Keep-Alive: 120 +Pos: 19 +Date: Thu, 18 Mar 2010 04:57:08 GMT +Content-Length: 14 + +HTTPSQS_PUT_OK +``` + +#### (2). GET text message from a queue #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?charset=utf-8&name=your_queue_name&opt=get&auth=mypass123" +``` + +``` +curl "http://host:port/?charset=gb2312&name=your_queue_name&opt=get&auth=mypass123" +``` + +> Using google chrome browser for example: + +> ![http://blog.s135.com/attachment/200912/get.png](http://blog.s135.com/attachment/200912/get.png) + +> Return the queue contents. + +> If there is no unread queue message, return: + +``` +HTTPSQS_GET_END +``` + +> HTTPSQS add a line "Pos: xxx" in the HTTP header and sends that back to the client since version 1.2, the "xxx" is the get pos of the current queue. For example: + +``` +HTTP/1.1 200 OK +Content-Type: text/plain; charset=utf-8 +Keep-Alive: 120 +Pos: 7 +Date: Thu, 18 Mar 2010 04:56:01 GMT +Content-Length: 7 + +message +``` + +> #### The charset parameter (Example: /?charset=utf-8): #### +> Documents transmitted with HTTP that are of type text, such as text/html, text/plain, etc., can send a charset parameter in the HTTP header to specify the character encoding of the document. + +> It is very important to always label Web documents explicitly. HTTP 1.1 says that the default charset is ISO-8859-1. But there are too many unlabeled documents in other encodings, so browsers use the reader's preferred encoding when there is no explicit charset parameter. + +> The line in the HTTP header typically looks like this: + +> Content-Type: text/plain; charset=utf-8 + +> In theory, any character encoding that has been [registered with IANA](http://www.iana.org/assignments/character-sets) can be used, but there is no browser that understands all of them. + +#### (3). View queue status #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=status&auth=mypass123" +``` + +> Return (for example): + +``` +HTTP Simple Queue Service v1.3 +------------------------------ +Queue Name: xoyo +Maximum number of queues: 1000000 +Put position of queue (1st lap): 45 +Get position of queue (1st lap): 6 +Number of unread queue: 39 +``` + +> or if the "Put position of queue" greater than the "Maximum number of queues", it will come back to the pos 1. + +``` +HTTP Simple Queue Service v1.3 +------------------------------ +Queue Name: xoyo +Maximum number of queues: 1000000 +Put position of queue (2st lap): 4562 +Get position of queue (1st lap): 900045 +Number of unread queue: 104517 +``` + +> Using google chrome browser for example: + +> ![http://blog.s135.com/attachment/200912/status.png](http://blog.s135.com/attachment/200912/status.png) + +#### (4). View queue status in json #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=status_json&auth=mypass123" +``` + +> Return (for example): + +``` +{"name":"xoyo","maxqueue":1000000,"putpos":45,"putlap":1,"getpos":6,"getlap":1,"unread":39} +``` + +> or if the "Put position of queue" greater than the "Maximum number of queues", it will come back to the pos 1. + +``` +{"name":"xoyo","maxqueue":1000000,"putpos":4562,"putlap":2,"getpos":900045,"getlap":1,"unread":104517} +``` + +#### (5). View the contents of the specified queue pos (id) #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?charset=utf-8&name=your_queue_name&opt=view&pos=5&auth=mypass123" +``` + +``` +curl "http://host:port/?charset=gb2312&name=your_queue_name&opt=view&pos=19&auth=mypass123" +``` + +> pos >=1 and <= 1000000000 + +> Return the contents of the specified queue pos. + +#### (6). Reset the queue #### + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=reset&auth=mypass123" +``` + +> If reset successful, return: + +``` +HTTPSQS_RESET_OK +``` + +> If an error occurs, return: + +``` +HTTPSQS_RESET_ERROR +``` + +#### (7). Change the maximum queue length of per-queue #### + +> Default maximum queue length: 1000000 + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=maxqueue&num=1000000000&auth=mypass123" +``` + +> num >=10 and <= 1000000000 + +> If change the maximum queue length successful, return: + +``` +HTTPSQS_MAXQUEUE_OK +``` + +> This operation will be cancelled if "Put position of queue" less than "Get position of queue" (lap of PUT > lap of GET), will return: + +``` +HTTPSQS_MAXQUEUE_CANCEL +``` + +#### (8). Change the interval to sync updated contents to the disk #### + +> Default interval: 5 seconds or the parameter set by "httpsqs -s second" + +> HTTP GET protocol (Using curl for example): + +``` +curl "http://host:port/?name=your_queue_name&opt=synctime&num=10&auth=mypass123" +``` + +> num >=1 and <= 1000000000 + +> If change the interval successful, return: + +``` +HTTPSQS_SYNCTIME_OK +``` + +> If "num" not between 1 to 1000000000, will return: + +``` +HTTPSQS_SYNCTIME_CANCEL +``` + +#### (9). Authentication failed #### + +> If password(/?auth=xxx) authentication failed, return: + +``` +HTTPSQS_AUTH_FAILED +``` + +#### (10). Global error #### + +> If an global error occurs, return: + +``` +HTTPSQS_ERROR +``` + + +--- + + +## 6. Client Document ## + +#### (1). PHP Client #### + +> A、PHP ext: http://code.google.com/p/php-httpsqs-client/ + +> B、PHP Class: View source code: [httpsqs\_client.php](http://code.google.com/p/httpsqs/source/browse/trunk/client/php/httpsqs_client.php) + +> Usage: + +``` +put($queue_name, $queue_data); + +/* +2. GET text message from a queue. + Return the queue contents. + If there is no unread queue message, return text: HTTPSQS_GET_END + If an error occurs, return boolean: false. +*/ +$result = $httpsqs->get($queue_name); + +/* +3. GET text message and pos from a queue. + Return example: array("pos" => 7, "data" => "text message") + If there is no unread queue message, return: array("pos" => 0, "data" => "HTTPSQS_GET_END") + If an error occurs, return boolean: false. +*/ +$result = $httpsqs->gets($queue_name); + +/* +4. View queue status +*/ +$result = $httpsqs->status($queue_name); + +/* +5. View queue status in json + Return example: {"name":"queue_name","maxqueue":5000000,"putpos":130,"putlap":1,"getpos":120,"getlap":1,"unread":10} +*/ +$result = $httpsqs->status_json($queue_name); + +/* +6. View the contents of the specified queue pos (id). + Return the contents of the specified queue pos. +*/ +$result = $httpsqs->view($queue_name, $queue_pos); + +/* +7. Reset the queue. + If reset successful, return boolean: true + If an error occurs, return boolean: false +*/ +$result = $httpsqs->reset($queue_name); + +/* +8. Change the maximum queue length of per-queue. + If change the maximum queue length successful, return boolean: true + If it be cancelled, return boolean: false +*/ +$result = $httpsqs->maxqueue($queue_name, $num); + +/* +9. Change the interval to sync updated contents to the disk. + If change the interval successful, return boolean: true + If it be cancelled, return boolean: false +*/ +$result = $httpsqs->synctime($num); +?> +``` + +#### (2). Perl Client (Third Party, Developer: [tonny0830](http://code.google.com/u/tonny0830/)) #### + +> Perl client file path: httpsqs-1.3/client/perl/ + +> View source code: http://code.google.com/p/httpsqs/source/browse/trunk/client/perl/ + +#### (3). Java Client (Third Party, Developer: [SuperSNY](http://code.google.com/u/SuperSNY/)) #### + +> Download: http://httpsqs.googlecode.com/files/httpsqs4j-java-client-1.0.zip + +> New code: svn checkout http://httpsqs.googlecode.com/svn/trunk/client/httpsqs4j/ httpsqs4j + +> Documentation: http://blog.s135.com/book/httpsqs/client/httpsqs4j/ \ No newline at end of file diff --git a/client/c/Makefile b/client/c/Makefile deleted file mode 100644 index 2935eab..0000000 --- a/client/c/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# Makefile for httpsqs_client -CC=gcc - -httpsqs_client: httpsqs_client.c - $(CC) httpsqs_client.c -o httpsqs_client - -clean: httpsqs_client - rm -f httpsqs_client - -install: httpsqs_client - install -m 4755 -o root httpsqs_client $(DESTDIR)/usr/bin diff --git a/client/c/client.c b/client/c/client.c deleted file mode 100644 index d0b9da1..0000000 --- a/client/c/client.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * httpsqsCԿͻ˺ - * ֧֣get put view reset maxqueue statusܣݲ֧keep-alive - * 룺gcc -o client client.c - * ʹ÷ - * GET: httpsqs_get(char * your_queue_name) - * PUT: httpsqs_put(char * your_queue_name, char * data) - * VIEW: httpsqs_view(char * your_queue_name, char * pos) - * MAXQUEUE httpsqs_maxqueue(char * your_queue_name, char * num) - * STATUS httpsqs_status(char * your_queue_name) - * RESET httpsqs_reset(char * your_queue_name) - * ߣ lb13810398408@gmail.com - * ڣ201047 - */ -#include -#include -#include -#include -#include -#include -#include - -#define HttpsqsIp "192.168.1.102" -#define HttpsqsPort 1218 -#define Charset "utf-8" - -int htconnect(char *domain,int port) -{ - int white_sock; - struct hostent * site; - struct sockaddr_in me; - site = gethostbyname(domain); - if(site == NULL) return -2; - white_sock = socket(AF_INET,SOCK_STREAM, 0); - if(white_sock < 0) return -1; - memset(&me, 0, sizeof(struct sockaddr_in)); - memcpy(&me.sin_addr, site->h_addr_list[0], site->h_length); - me.sin_family = AF_INET; - me.sin_port = htons(port); - return (connect(white_sock, (struct sockaddr *)&me, sizeof(struct sockaddr)) < 0) ? -1 : white_sock; -} - -int htsend(int sock,char *fmt,...) -{ - char BUF[1024]; - va_list argptr; - va_start(argptr, fmt); - vsprintf(BUF,fmt, argptr); - va_end(argptr); - return send(sock, BUF, strlen(BUF), 0); -} - -int http_get(char * query) -{ - int black_sock; - - black_sock = htconnect(HttpsqsIp, HttpsqsPort); - if (black_sock < 0) return; - - htsend(black_sock, "GET %s HTTP/1.1\r\n", query, 10); - htsend(black_sock, "Host: %s\r\n", HttpsqsIp, 10); - htsend(black_sock, "Connection: close\r\n", 10); - htsend(black_sock, "\r\n", 10); - - return black_sock; -} - -int http_put(char * data, char * query) -{ - int black_sock; - int len = 0; - - black_sock = htconnect(HttpsqsIp, HttpsqsPort); - if (black_sock < 0) return; - len = strlen(data); - htsend(black_sock, "POST %s HTTP/1.1\r\n", query, 10); - htsend(black_sock, "Host: %s\r\n", HttpsqsIp, 10); - htsend(black_sock, "Content-Length: %d\r\n", len, 10); - htsend(black_sock, "Connection: close\r\n", 10); - htsend(black_sock, "\r\n", 10); - htsend(black_sock, "%s", data, 10); - - return black_sock; -} - -char * httpsqs_maxqueue(char * name, char * num) -{ - char data[3]; - int sock; - char * query; - char max[300]; - int i = 0, j = 0; - char * fs; - - query = (char *)malloc((strlen(name) + strlen(num) + strlen(Charset) + 35) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=maxqueue&num=%s", Charset, name, num); - - sock = http_get(query); - free(query); - - while (read(sock, data, 1) > 0) - { - if(j >= 7) - { - max[i] = data[0]; - i ++; - } - if(data[0] == '\n') - { - j ++; - } - } - - if(strlen(max) > 0) - { - max[i] = '\0'; - } - fs = (char *)malloc(strlen(max) * sizeof(char)); - strcpy(fs, max); - return fs; -} - -char * httpsqs_reset(char * name) -{ - char data[3]; - int sock; - char * query; - char reset[300]; - int i = 0, j = 0; - char * fs; - - query = (char *)malloc((strlen(name) + strlen(Charset) + 27) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=reset", Charset, name); - - sock = http_get(query); - free(query); - - while (read(sock, data, 1) > 0) - { - if(j >= 7) - { - reset[i] = data[0]; - i ++; - } - if(data[0] == '\n') - { - j ++; - } - } - if(strlen(reset) > 0) - { - reset[i] = '\0'; - } - fs = (char *)malloc(strlen(reset) * sizeof(char)); - strcpy(fs, reset); - return fs; -} - -char * httpsqs_status(char * name) -{ - char data[3]; - int sock; - char * query; - char status[300]; - int i = 0, j = 0; - char * fs; - - query = (char *)malloc((strlen(name) + strlen(Charset) + 28) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=status", Charset, name); - - sock = http_get(query); - free(query); - - while (read(sock, data, 1) > 0) - { - if(j >= 7) - { - status[i] = data[0]; - i ++; - } - if(data[0] == '\n') - { - j ++; - } - } - if(strlen(status) > 0) - { - status[i] = '\0'; - } - fs = (char *)malloc(strlen(status) * sizeof(char)); - strcpy(fs, status); - return fs; -} - -char * httpsqs_put(char * name, char * bodydata) -{ - char data[3]; - char dataarr[2][20]; - char pos[10]; - int sock; - char * query; - int i = 0, j = 0, flag = 0; - - char queuedata[2000]; - char * fq; - //fq = queuedata; - - query = (char *)malloc((strlen(name) + strlen(Charset) + 25) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=put", Charset, name); - - sock = http_put(bodydata, query); - free(query); - - memset(dataarr[0], 0, strlen(dataarr[0])); - memset(dataarr[1], 0, strlen(dataarr[1])); - while (read(sock, data, 1) > 0) - { - if(j == 3) - { - if(data[0] == 'P') - { - flag = 1; - } - if(flag == 1) - { - i++; - if(i >= 6) - { - dataarr[0][i-6] = data[0]; - } - } - } - if(j == 4 && strlen(dataarr[0]) > 2) - { - for(i = 0; i < strlen(dataarr[0])-2; i++) - { - pos[i] = dataarr[0][i]; - } - pos[strlen(pos)] = '\0'; - memset(dataarr[0], 0, strlen(dataarr[0])); - strcpy(dataarr[0], pos); - i = 0; - if(strlen(pos) > 0) - { - flag = 2; - } - } - if(flag == 2 && strlen(pos) > 0) - { - if(j == 8) - { - dataarr[1][i] = data[0]; - i++; - } - } - if(data[0] == '\n') - { - j ++; - } - - } - if(strlen(dataarr[1]) > 0) - { - dataarr[1][i] = '\0'; - } - memset(queuedata, 0, strlen(queuedata)); - sprintf(queuedata, "Pos:%s\nData:%s", dataarr[0], dataarr[1]); - fq = (char *)malloc(strlen(queuedata) * sizeof(char)); - strcpy(fq, queuedata); - //printf("%s\n\n\n", queuedata); - return fq; -} - -char * httpsqs_view(char * name, char * pos) -{ - char data[3]; - int sock; - char * query; - int i = 0, j = 0; - - char queuedata[2000]; - char * fq; - - query = (char *)malloc((strlen(name) + strlen(Charset) + strlen(pos) + 31) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=view&pos=%s", Charset, name, pos); - - sock = http_get(query); - free(query); - - while (read(sock, data, 1) > 0) - { - if(j >= 7) - { - queuedata[i] = data[0]; - i ++; - } - if(data[0] == '\n') - { - j ++; - } - } - if(strlen(queuedata) > 0) - { - queuedata[i] = '\0'; - } - fq = (char *)malloc(strlen(queuedata) * sizeof(char)); - strcpy(fq, queuedata); - return fq; -} - -char * httpsqs_get(char * name) -{ - char data[3]; - char dataarr[2][2000]; - char pos[10]; - int sock; - char * query; - int i = 0, j = 0, flag = 0; - - char queuedata[2000]; - char * fq; - - query = (char *)malloc((strlen(name) + strlen(Charset) + 25) * sizeof(char)); - sprintf(query, "/?charset=%s&name=%s&opt=get", Charset, name); - - sock = http_get(query); - free(query); - - memset(dataarr[0], 0, strlen(dataarr[0])); - memset(dataarr[1], 0, strlen(dataarr[1])); - while (read(sock, data, 1) > 0) - { - if(j == 3) - { - if(data[0] == 'P') - { - flag = 1; - } - if(flag == 1) - { - i++; - if(i >= 6) - { - dataarr[0][i-6] = data[0]; - } - } - } - if(j == 4 && strlen(dataarr[0]) > 2) - { - for(i = 0; i < strlen(dataarr[0])-2; i++) - { - pos[i] = dataarr[0][i]; - } - pos[strlen(pos)] = '\0'; - memset(dataarr[0], 0, strlen(dataarr[0])); - strcpy(dataarr[0], pos); - i = 0; - if(strlen(pos) > 0) - { - flag = 2; - } - } - if(flag == 2 && strlen(pos) > 0) - { - if(j == 8) - { - dataarr[1][i] = data[0]; - i++; - } - } - if(data[0] == '\n') - { - j ++; - } - } - - if(strlen(dataarr[1]) > 0) - { - dataarr[1][strlen(dataarr[1])] = '\0'; - } - - memset(queuedata, 0, strlen(queuedata)); - sprintf(queuedata, "Pos:%s\nData:%s", dataarr[0], dataarr[1]); - fq = (char *)malloc(strlen(queuedata) * sizeof(char)); - strcpy(fq, queuedata); - return fq; -} - -int main(int argc,char **argv) -{ - char * data; - - data = httpsqs_put(argv[1], argv[2]); - printf("%s\n", data); - free(data); - - data = httpsqs_status(argv[1]); - printf("%s\n", data); - free(data); - - data = httpsqs_get(argv[1]); - printf("%s\n", data); - free(data); - - data = httpsqs_reset(argv[1]); - printf("%s\n", data); - free(data); - /* - data = httpsqs_maxqueue(argv[1], argv[2]); - printf("%s\n", data); - free(data); - - data = httpsqs_view(argv[1], argv[2]); - printf("%s\n", data); - free(data); - */ -} diff --git a/client/c/httpsqs_client.c b/client/c/httpsqs_client.c deleted file mode 100644 index c556e91..0000000 --- a/client/c/httpsqs_client.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - *本程序用C语言作为Linux守护进程 - *实现每秒读取队列内容平且POST发送给处理端(例如PHP程序) - *可以修改处理队列数据部分的代码实现其他的数据处理 - *本程序只是一个最初级的作品,本人的C语言水平也很低(在写这个程序前还不会C语言的socket发送HTTP请求) - *希望张宴大哥给予指正与修改,体现我们开源的优势~哈哈 - * - *使用方法: - *make - *make install - *httpsqs_client -q your_queue_name -t 20(每秒获取队列的次数) - * - *作者:李博 lb13810398408@gmail.com - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define HttpsqsIp "192.168.1.102" -#define HttpsqsPort 1218 - -#define RemoteIp "xxx.xxx.xxx.xxx"//本程序获取队列后的处理是将数据POST给PHP程序 用户可以自行修改那一部分 -#define RemotePort 80 - -void init_daemon(void); - - -void init_daemon(void) -{ - int pid; - int i; - if(pid = fork()) - exit(0); - else if(pid < 0) - exit(1); - setsid(); - - if(pid = fork()) - exit(0); - else if(pid < 0) - exit(1); - - for(i = 0; i < NOFILE; ++i) - close(i); - chdir("/var"); - umask(0); - return; -} - -int htconnect(char *domain,int port) -{ - int white_sock; - struct hostent * site; - struct sockaddr_in me; - site = gethostbyname(domain); - if(site == NULL) return -2; - white_sock = socket(AF_INET,SOCK_STREAM, 0); - if(white_sock < 0) return -1; - memset(&me, 0, sizeof(struct sockaddr_in)); - memcpy(&me.sin_addr, site->h_addr_list[0], site->h_length); - me.sin_family = AF_INET; - me.sin_port = htons(port); - return (connect(white_sock, (struct sockaddr *)&me, sizeof(struct sockaddr)) < 0) ? -1 : white_sock; -} - -int htsend(int sock,char *fmt,...) -{ - char BUF[1024]; - va_list argptr; - va_start(argptr, fmt); - vsprintf(BUF,fmt, argptr); - va_end(argptr); - return send(sock, BUF, strlen(BUF), 0); -} - -int httpsqs_get(char *queuename) -{ - int black_sock; - - black_sock = htconnect(HttpsqsIp, HttpsqsPort); - if (black_sock < 0) return; - - htsend(black_sock, "GET /?charset=utf-8&name=%s&opt=get HTTP/1.1\r\n", queuename, 10); - htsend(black_sock, "Host: %s\r\n", HttpsqsIp, 10); - htsend(black_sock, "Connection: close\r\n", 10); - htsend(black_sock, "\r\n", 10); - - return black_sock; -} - -int http_post(char *datastr) -{ - int black_sock; - int len = 0; - - black_sock = htconnect(RemoteIp, RemotePort); - if (black_sock < 0) return; - len = strlen(datastr) + 5; - htsend(black_sock, "POST /index.php?m=feed&a=feed_add HTTP/1.1\r\n", 10); - htsend(black_sock, "Content-type: application/x-www-form-urlencoded\r\n", 10); - htsend(black_sock, "Host: www.oooffice.com\r\n", 10); - htsend(black_sock, "Content-Length: %d\r\n", len, 10); - htsend(black_sock, "Connection: close\r\n", 10); - htsend(black_sock, "\r\n", 10); - htsend(black_sock, "data=%s", datastr, 10); - - return black_sock; -} - -void process(char *queuename, int loop) -{ - FILE * fp; - int black_sock; - char data[3]; - char posstr[15]; - char datastr[2000]; - char post[5000]; - int i = 0; - int j = 0; - int len = 0; - int flag = 0; - - char pos[10]; - int p = 0; - - loop --; - while(loop) - { - memset(data, 0, strlen(data)); - memset(datastr, 0, strlen(datastr)); - memset(pos, 0, strlen(pos)); - - black_sock = httpsqs_get(queuename); - - i = 0; - j = 0; - - while (read(black_sock, data, 1) > 0) - { - if(j == 3) - { - if(data[0] == 'P') - flag = 1; - if(flag == 1) - { - i++; - if(i >= 6) - posstr[i-6] = data[0]; - } - } - if(j == 4 && strlen(posstr) > 2) - { - for(i = 0; i < strlen(posstr)-2; i++) - pos[i] = posstr[i]; - pos[strlen(pos)] = '\0'; - i = 0; - if(strlen(pos) > 0) - flag = 2; - } - if(flag == 2 && strlen(pos) > 0) - { - if(j == 8) - { - datastr[i] = data[0]; - i++; - } - } - if(data[0] == '\n') - j ++; - } - if(strlen(datastr) > 0) - datastr[strlen(datastr)] = '\0'; - - if(strlen(datastr) > 0 && strlen(pos) > 0) - printf("POS:%s\nDATA:%s\n", pos, datastr); - - close(black_sock); - memset(data, 0, strlen(data)); - - if(strlen(datastr) > 0 && strlen(pos) > 0) - { - p = atoi(pos); - - if((fp = fopen("httpsqs_feed.log", "a")) >= 0) - fprintf(fp, "GET FROM HTTPSQS:\r\nPOS:%d\nDATA:%s\r\n", p, datastr); - - //这部分是获取队列内容后的操作部分,queuedata为队列内容,p为队列的Pos - black_sock = http_post(datastr); - - i = 0; - while (read(black_sock, data, 1)>0) - { - if(data[0] == '|') - { - if(post[i-1] == 'D' && post[i-2] == 'N' && post[i-3] == 'E') - { - post[i-3] = '\0'; - break; - } - } - post[i] = data[0]; - i++; - } - memset(data, 0, strlen(data)); - close(black_sock); - if(strlen(post)) - { - if(fp >=0) - { - strcpy(post, strstr(post, "Array")); - fprintf(fp, "POST TO REMOTE\r\n%s\r\n", post); - fclose(fp); - } - } - } - - memset(post, 0, strlen(post)); - loop --; - } - return; -} - -int main(int argc,char **argv) -{ - char queuename[20]; - int loop; - - if(argc <= 4 || strcmp(argv[1], "-q") != 0 || strcmp(argv[3], "-t") != 0) - { - printf("You should run program like:\n"); - printf("%s -q queuename -t timespersec\n", argv[0]); - return; - } - - strcpy(queuename, argv[2]); - loop = atoi(argv[4]); - - if(loop < 1) - { - printf("The -t(times per second) must be an int number & > 0\n"); - return; - } - - init_daemon(); - - while(1) - { - sleep(1); - process(queuename, loop); - } -} diff --git a/client/httpsqs4j/.classpath b/client/httpsqs4j/.classpath deleted file mode 100644 index 07ca123..0000000 --- a/client/httpsqs4j/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/client/httpsqs4j/.project b/client/httpsqs4j/.project deleted file mode 100644 index 26b9280..0000000 --- a/client/httpsqs4j/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Httpsqs4j - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/client/httpsqs4j/.settings/org.eclipse.jdt.core.prefs b/client/httpsqs4j/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index c8e5ed4..0000000 --- a/client/httpsqs4j/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Apr 29 11:07:00 CST 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Httpsqs4j.class b/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Httpsqs4j.class deleted file mode 100644 index 04c0483..0000000 Binary files a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Httpsqs4j.class and /dev/null differ diff --git a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsClient.class b/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsClient.class deleted file mode 100644 index 6e1de31..0000000 Binary files a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsClient.class and /dev/null differ diff --git a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsException.class b/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsException.class deleted file mode 100644 index bcd11cf..0000000 Binary files a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsException.class and /dev/null differ diff --git a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsStatus.class b/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsStatus.class deleted file mode 100644 index ead9326..0000000 Binary files a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/HttpsqsStatus.class and /dev/null differ diff --git a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Test.class b/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Test.class deleted file mode 100644 index 005d9d7..0000000 Binary files a/client/httpsqs4j/bin/com/daguu/lib/httpsqs4j/Test.class and /dev/null differ diff --git a/client/httpsqs4j/doc/allclasses-frame.html b/client/httpsqs4j/doc/allclasses-frame.html deleted file mode 100644 index 7bed02c..0000000 --- a/client/httpsqs4j/doc/allclasses-frame.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -All Classes - - - - - - - - - - - -All Classes -
- - - - - -
Httpsqs4j -
-HttpsqsClient -
-HttpsqsException -
-HttpsqsStatus -
-Test -
-
- - - diff --git a/client/httpsqs4j/doc/allclasses-noframe.html b/client/httpsqs4j/doc/allclasses-noframe.html deleted file mode 100644 index 1d71d58..0000000 --- a/client/httpsqs4j/doc/allclasses-noframe.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - -All Classes - - - - - - - - - - - -All Classes -
- - - - - -
Httpsqs4j -
-HttpsqsClient -
-HttpsqsException -
-HttpsqsStatus -
-Test -
-
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Httpsqs4j.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Httpsqs4j.html deleted file mode 100644 index 035bc07..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Httpsqs4j.html +++ /dev/null @@ -1,290 +0,0 @@ - - - - - - - -Httpsqs4j - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.daguu.lib.httpsqs4j -
-Class Httpsqs4j

-
-java.lang.Object
-  extended by com.daguu.lib.httpsqs4j.Httpsqs4j
-
-
-
-
public class Httpsqs4j
extends java.lang.Object
- - -

-Httpsqs4j基础类,用于设置连接信息及创建客户端对象 -

- -

-

-
Author:
-
Henry Young
-
-
- -

- - - - - - - - - - - -
-Constructor Summary
Httpsqs4j() - -
-           
-  - - - - - - - - - - - - - - - -
-Method Summary
-static HttpsqsClientcreateNewClient() - -
-          创建新的客户端对象
-static voidsetConnectionInfo(java.lang.String ip, - int port, - java.lang.String charset) - -
-          设置连接信息
- - - - - - - -
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- - - - - - - - -
-Constructor Detail
- -

-Httpsqs4j

-
-public Httpsqs4j()
-
-
- - - - - - - - -
-Method Detail
- -

-setConnectionInfo

-
-public static void setConnectionInfo(java.lang.String ip,
-                                     int port,
-                                     java.lang.String charset)
-                              throws HttpsqsException
-
-
设置连接信息 -

-

-
Parameters:
ip -
port -
charset - 字符集 -
Throws: -
HttpsqsException
-
-
-
- -

-createNewClient

-
-public static HttpsqsClient createNewClient()
-
-
创建新的客户端对象 -

-

- -
Returns:
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsClient.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsClient.html deleted file mode 100644 index f3f81c3..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsClient.html +++ /dev/null @@ -1,384 +0,0 @@ - - - - - - - -HttpsqsClient - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.daguu.lib.httpsqs4j -
-Class HttpsqsClient

-
-java.lang.Object
-  extended by com.daguu.lib.httpsqs4j.HttpsqsClient
-
-
-
-
public class HttpsqsClient
extends java.lang.Object
- - -

-客户端类,使用Httpsqs4j类的createNewClient()方法创建,创建前请先调用Httpsqs4j的setConnectionInfo设置连接信息 -

- -

-

-
Author:
-
Henry Young
-
-
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Method Summary
- longgetLastPos() - -
-          获取最后一次出入队列操作的位置值
- HttpsqsStatusgetStatus(java.lang.String queueName) - -
-          获取HttpSQS状态
- java.lang.StringgetString(java.lang.String queueName) - -
-          将字符串出队列
- java.lang.StringgetStringAt(java.lang.String queueName, - long pos) - -
-          获取某位置的字符串
- voidputString(java.lang.String queueName, - java.lang.String str) - -
-          将字符串加入队列
- booleanreset(java.lang.String queueName) - -
-          重置队列
- booleansetMaxNumber(java.lang.String queueName, - long number) - -
-          设置最大队列数量
- - - - - - - -
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- - - - - - - - -
-Method Detail
- -

-getLastPos

-
-public long getLastPos()
-
-
获取最后一次出入队列操作的位置值 -

-

- -
Returns:
-
-
-
- -

-getStatus

-
-public HttpsqsStatus getStatus(java.lang.String queueName)
-                        throws HttpsqsException
-
-
获取HttpSQS状态 -

-

-
Parameters:
queueName - 队列名称 -
Returns:
-
Throws: -
HttpsqsException
-
-
-
- -

-putString

-
-public void putString(java.lang.String queueName,
-                      java.lang.String str)
-               throws HttpsqsException
-
-
将字符串加入队列 -

-

-
Parameters:
queueName - 队列名称
str - 字符串 -
Throws: -
HttpsqsException
-
-
-
- -

-getString

-
-public java.lang.String getString(java.lang.String queueName)
-                           throws HttpsqsException
-
-
将字符串出队列 -

-

-
Parameters:
queueName - 队列名称 -
Returns:
-
Throws: -
HttpsqsException
-
-
-
- -

-getStringAt

-
-public java.lang.String getStringAt(java.lang.String queueName,
-                                    long pos)
-                             throws HttpsqsException
-
-
获取某位置的字符串 -

-

-
Parameters:
queueName - 队列名称
pos - 位置 -
Returns:
-
Throws: -
HttpsqsException
-
-
-
- -

-reset

-
-public boolean reset(java.lang.String queueName)
-              throws HttpsqsException
-
-
重置队列 -

-

-
Parameters:
queueName - 队列名称 -
Returns:
-
Throws: -
HttpsqsException
-
-
-
- -

-setMaxNumber

-
-public boolean setMaxNumber(java.lang.String queueName,
-                            long number)
-                     throws HttpsqsException
-
-
设置最大队列数量 -

-

-
Parameters:
queueName - 队列名称
number - 最大数量 -
Returns:
-
Throws: -
HttpsqsException
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsException.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsException.html deleted file mode 100644 index 95ae4a3..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsException.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - -HttpsqsException - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.daguu.lib.httpsqs4j -
-Class HttpsqsException

-
-java.lang.Object
-  extended by java.lang.Throwable
-      extended by java.lang.Exception
-          extended by com.daguu.lib.httpsqs4j.HttpsqsException
-
-
-
All Implemented Interfaces:
java.io.Serializable
-
-
-
-
public class HttpsqsException
extends java.lang.Exception
- - -

-

-
Author:
-
Henry Young
-
See Also:
Serialized Form
-
- -

- - - - - - - - - - - - - - - - - -
-Constructor Summary
HttpsqsException() - -
-           
HttpsqsException(java.lang.String message) - -
-           
HttpsqsException(java.lang.String message, - java.lang.Throwable cause) - -
-           
-  - - - - - - - -
-Method Summary
- - - - - - - -
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
- - - - - - - -
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-  -

- - - - - - - - -
-Constructor Detail
- -

-HttpsqsException

-
-public HttpsqsException()
-
-
-
- -

-HttpsqsException

-
-public HttpsqsException(java.lang.String message)
-
-
-
- -

-HttpsqsException

-
-public HttpsqsException(java.lang.String message,
-                        java.lang.Throwable cause)
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsStatus.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsStatus.html deleted file mode 100644 index 28531af..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/HttpsqsStatus.html +++ /dev/null @@ -1,405 +0,0 @@ - - - - - - - -HttpsqsStatus - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.daguu.lib.httpsqs4j -
-Class HttpsqsStatus

-
-java.lang.Object
-  extended by com.daguu.lib.httpsqs4j.HttpsqsStatus
-
-
-
-
public class HttpsqsStatus
extends java.lang.Object
- - -

-

-
Author:
-
Henry Young
-
-
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Field Summary
- longgetLap - -
-          当前出队圈数
- longgetPosition - -
-          当前出队位置
- longmaxNumber - -
-          队列最大数量
- longputLap - -
-          当前入队圈数
- longputPosition - -
-          当前入队位置
- java.lang.StringqueueName - -
-          队列名称
- longunreadNumber - -
-          当前未出队数量
- java.lang.Stringversion - -
-          HttpSQS版本
-  - - - - - - - - - - -
-Constructor Summary
HttpsqsStatus() - -
-           
-  - - - - - - - -
-Method Summary
- - - - - - - -
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- - - - - - - - -
-Field Detail
- -

-version

-
-public java.lang.String version
-
-
HttpSQS版本 -

-

-
-
-
- -

-queueName

-
-public java.lang.String queueName
-
-
队列名称 -

-

-
-
-
- -

-maxNumber

-
-public long maxNumber
-
-
队列最大数量 -

-

-
-
-
- -

-putPosition

-
-public long putPosition
-
-
当前入队位置 -

-

-
-
-
- -

-putLap

-
-public long putLap
-
-
当前入队圈数 -

-

-
-
-
- -

-getPosition

-
-public long getPosition
-
-
当前出队位置 -

-

-
-
-
- -

-getLap

-
-public long getLap
-
-
当前出队圈数 -

-

-
-
-
- -

-unreadNumber

-
-public long unreadNumber
-
-
当前未出队数量 -

-

-
-
- - - - - - - - -
-Constructor Detail
- -

-HttpsqsStatus

-
-public HttpsqsStatus()
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Test.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Test.html deleted file mode 100644 index 0b11daf..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/Test.html +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - - -Test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- -

- -com.daguu.lib.httpsqs4j -
-Class Test

-
-java.lang.Object
-  extended by com.daguu.lib.httpsqs4j.Test
-
-
-
-
public class Test
extends java.lang.Object
- - -

-

-
Author:
-
Henry Young
-
-
- -

- - - - - - - - - - - -
-Constructor Summary
Test() - -
-           
-  - - - - - - - - - - - -
-Method Summary
-static voidmain(java.lang.String[] args) - -
-           
- - - - - - - -
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- - - - - - - - -
-Constructor Detail
- -

-Test

-
-public Test()
-
-
- - - - - - - - -
-Method Detail
- -

-main

-
-public static void main(java.lang.String[] args)
-
-
-
-
-
- -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Httpsqs4j.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Httpsqs4j.html deleted file mode 100644 index f0b8348..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Httpsqs4j.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - -Uses of Class com.daguu.lib.httpsqs4j.Httpsqs4j - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.daguu.lib.httpsqs4j.Httpsqs4j

-
-No usage of com.daguu.lib.httpsqs4j.Httpsqs4j -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsClient.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsClient.html deleted file mode 100644 index e6183f6..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsClient.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - -Uses of Class com.daguu.lib.httpsqs4j.HttpsqsClient - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.daguu.lib.httpsqs4j.HttpsqsClient

-
- - - - - -
-Uses of HttpsqsClient in com.daguu.lib.httpsqs4j
-  -

- - - - - - - - - -
Methods in com.daguu.lib.httpsqs4j that return HttpsqsClient
-static HttpsqsClientHttpsqs4j.createNewClient() - -
-          创建新的客户端对象
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsException.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsException.html deleted file mode 100644 index ba8e68e..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsException.html +++ /dev/null @@ -1,219 +0,0 @@ - - - - - - - -Uses of Class com.daguu.lib.httpsqs4j.HttpsqsException - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.daguu.lib.httpsqs4j.HttpsqsException

-
- - - - - -
-Uses of HttpsqsException in com.daguu.lib.httpsqs4j
-  -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Methods in com.daguu.lib.httpsqs4j that throw HttpsqsException
- HttpsqsStatusHttpsqsClient.getStatus(java.lang.String queueName) - -
-          获取HttpSQS状态
- java.lang.StringHttpsqsClient.getString(java.lang.String queueName) - -
-          将字符串出队列
- java.lang.StringHttpsqsClient.getStringAt(java.lang.String queueName, - long pos) - -
-          获取某位置的字符串
- voidHttpsqsClient.putString(java.lang.String queueName, - java.lang.String str) - -
-          将字符串加入队列
- booleanHttpsqsClient.reset(java.lang.String queueName) - -
-          重置队列
-static voidHttpsqs4j.setConnectionInfo(java.lang.String ip, - int port, - java.lang.String charset) - -
-          设置连接信息
- booleanHttpsqsClient.setMaxNumber(java.lang.String queueName, - long number) - -
-          设置最大队列数量
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsStatus.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsStatus.html deleted file mode 100644 index bf6af69..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/HttpsqsStatus.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - -Uses of Class com.daguu.lib.httpsqs4j.HttpsqsStatus - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.daguu.lib.httpsqs4j.HttpsqsStatus

-
- - - - - -
-Uses of HttpsqsStatus in com.daguu.lib.httpsqs4j
-  -

- - - - - - - - - -
Methods in com.daguu.lib.httpsqs4j that return HttpsqsStatus
- HttpsqsStatusHttpsqsClient.getStatus(java.lang.String queueName) - -
-          获取HttpSQS状态
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Test.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Test.html deleted file mode 100644 index a128d59..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/class-use/Test.html +++ /dev/null @@ -1,143 +0,0 @@ - - - - - - - -Uses of Class com.daguu.lib.httpsqs4j.Test - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Class
com.daguu.lib.httpsqs4j.Test

-
-No usage of com.daguu.lib.httpsqs4j.Test -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-frame.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-frame.html deleted file mode 100644 index dceeabd..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-frame.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - -com.daguu.lib.httpsqs4j - - - - - - - - - - - -com.daguu.lib.httpsqs4j - - - - -
-Classes  - -
-Httpsqs4j -
-HttpsqsClient -
-HttpsqsStatus -
-Test
- - - - - - -
-Exceptions  - -
-HttpsqsException
- - - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-summary.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-summary.html deleted file mode 100644 index 4c35d81..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-summary.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - -com.daguu.lib.httpsqs4j - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-

-Package com.daguu.lib.httpsqs4j -

- - - - - - - - - - - - - - - - - - - - - -
-Class Summary
Httpsqs4jHttpsqs4j基础类,用于设置连接信息及创建客户端对象
HttpsqsClient客户端类,使用Httpsqs4j类的createNewClient()方法创建,创建前请先调用Httpsqs4j的setConnectionInfo设置连接信息
HttpsqsStatus 
Test 
-  - -

- - - - - - - - - -
-Exception Summary
HttpsqsException 
-  - -

-

-
-
- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-tree.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-tree.html deleted file mode 100644 index 6d278c7..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-tree.html +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - -com.daguu.lib.httpsqs4j Class Hierarchy - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For Package com.daguu.lib.httpsqs4j -

-
-

-Class Hierarchy -

-
    -
  • java.lang.Object -
-
- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-use.html b/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-use.html deleted file mode 100644 index 7440935..0000000 --- a/client/httpsqs4j/doc/com/daguu/lib/httpsqs4j/package-use.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - -Uses of Package com.daguu.lib.httpsqs4j - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Uses of Package
com.daguu.lib.httpsqs4j

-
- - - - - - - - - - - - - - -
-Classes in com.daguu.lib.httpsqs4j used by com.daguu.lib.httpsqs4j
HttpsqsClient - -
-          客户端类,使用Httpsqs4j类的createNewClient()方法创建,创建前请先调用Httpsqs4j的setConnectionInfo设置连接信息
HttpsqsException - -
-           
HttpsqsStatus - -
-           
-  -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/constant-values.html b/client/httpsqs4j/doc/constant-values.html deleted file mode 100644 index fc12647..0000000 --- a/client/httpsqs4j/doc/constant-values.html +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - -Constant Field Values - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Constant Field Values

-
-
-Contents
    -
- -
- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/deprecated-list.html b/client/httpsqs4j/doc/deprecated-list.html deleted file mode 100644 index e3ad320..0000000 --- a/client/httpsqs4j/doc/deprecated-list.html +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - -Deprecated List - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Deprecated API

-
-
-Contents
    -
- -
- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/help-doc.html b/client/httpsqs4j/doc/help-doc.html deleted file mode 100644 index 295977a..0000000 --- a/client/httpsqs4j/doc/help-doc.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - -API Help - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    -
  • Interfaces (italic)
  • Classes
  • Enums
  • Exceptions
  • Errors
  • Annotation Types
-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description -

    -

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary -

    -

  • Field Detail
  • Constructor Detail
  • Method Detail
-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

    -
  • Annotation Type declaration
  • Annotation Type description
  • Required Element Summary
  • Optional Element Summary
  • Element Detail
-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

    -
  • Enum declaration
  • Enum description
  • Enum Constant Summary
  • Enum Constant Detail
-
-

-Use

-
-Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    -
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
-
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/index-files/index-1.html b/client/httpsqs4j/doc/index-files/index-1.html deleted file mode 100644 index 59d5008..0000000 --- a/client/httpsqs4j/doc/index-files/index-1.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -C-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-C

-
-
com.daguu.lib.httpsqs4j - package com.daguu.lib.httpsqs4j
 
createNewClient() - -Static method in class com.daguu.lib.httpsqs4j.Httpsqs4j -
创建新的客户端对象 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-10.html b/client/httpsqs4j/doc/index-files/index-10.html deleted file mode 100644 index 55f97f4..0000000 --- a/client/httpsqs4j/doc/index-files/index-10.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -U-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-U

-
-
unreadNumber - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
当前未出队数量 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-11.html b/client/httpsqs4j/doc/index-files/index-11.html deleted file mode 100644 index 96d760e..0000000 --- a/client/httpsqs4j/doc/index-files/index-11.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -V-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-V

-
-
version - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
HttpSQS版本 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-2.html b/client/httpsqs4j/doc/index-files/index-2.html deleted file mode 100644 index e22b440..0000000 --- a/client/httpsqs4j/doc/index-files/index-2.html +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - -G-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-G

-
-
getLap - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
当前出队圈数 -
getLastPos() - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
获取最后一次出入队列操作的位置值 -
getPosition - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
当前出队位置 -
getStatus(String) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
获取HttpSQS状态 -
getString(String) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
将字符串出队列 -
getStringAt(String, long) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
获取某位置的字符串 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-3.html b/client/httpsqs4j/doc/index-files/index-3.html deleted file mode 100644 index 998a558..0000000 --- a/client/httpsqs4j/doc/index-files/index-3.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - -H-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-H

-
-
Httpsqs4j - Class in com.daguu.lib.httpsqs4j
Httpsqs4j基础类,用于设置连接信息及创建客户端对象
Httpsqs4j() - -Constructor for class com.daguu.lib.httpsqs4j.Httpsqs4j -
  -
HttpsqsClient - Class in com.daguu.lib.httpsqs4j
客户端类,使用Httpsqs4j类的createNewClient()方法创建,创建前请先调用Httpsqs4j的setConnectionInfo设置连接信息
HttpsqsException - Exception in com.daguu.lib.httpsqs4j
 
HttpsqsException() - -Constructor for exception com.daguu.lib.httpsqs4j.HttpsqsException -
  -
HttpsqsException(String) - -Constructor for exception com.daguu.lib.httpsqs4j.HttpsqsException -
  -
HttpsqsException(String, Throwable) - -Constructor for exception com.daguu.lib.httpsqs4j.HttpsqsException -
  -
HttpsqsStatus - Class in com.daguu.lib.httpsqs4j
 
HttpsqsStatus() - -Constructor for class com.daguu.lib.httpsqs4j.HttpsqsStatus -
  -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-4.html b/client/httpsqs4j/doc/index-files/index-4.html deleted file mode 100644 index 3391884..0000000 --- a/client/httpsqs4j/doc/index-files/index-4.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - -M-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-M

-
-
main(String[]) - -Static method in class com.daguu.lib.httpsqs4j.Test -
  -
maxNumber - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
队列最大数量 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-5.html b/client/httpsqs4j/doc/index-files/index-5.html deleted file mode 100644 index a02102f..0000000 --- a/client/httpsqs4j/doc/index-files/index-5.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - -P-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-P

-
-
putLap - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
当前入队圈数 -
putPosition - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
当前入队位置 -
putString(String, String) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
将字符串加入队列 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-6.html b/client/httpsqs4j/doc/index-files/index-6.html deleted file mode 100644 index b642181..0000000 --- a/client/httpsqs4j/doc/index-files/index-6.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -Q-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-Q

-
-
queueName - -Variable in class com.daguu.lib.httpsqs4j.HttpsqsStatus -
队列名称 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-7.html b/client/httpsqs4j/doc/index-files/index-7.html deleted file mode 100644 index bc6fd02..0000000 --- a/client/httpsqs4j/doc/index-files/index-7.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -R-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-R

-
-
reset(String) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
重置队列 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-8.html b/client/httpsqs4j/doc/index-files/index-8.html deleted file mode 100644 index f36ab60..0000000 --- a/client/httpsqs4j/doc/index-files/index-8.html +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - -S-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-S

-
-
setConnectionInfo(String, int, String) - -Static method in class com.daguu.lib.httpsqs4j.Httpsqs4j -
设置连接信息 -
setMaxNumber(String, long) - -Method in class com.daguu.lib.httpsqs4j.HttpsqsClient -
设置最大队列数量 -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index-files/index-9.html b/client/httpsqs4j/doc/index-files/index-9.html deleted file mode 100644 index be22d3e..0000000 --- a/client/httpsqs4j/doc/index-files/index-9.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - -T-Index - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
-

-T

-
-
Test - Class in com.daguu.lib.httpsqs4j
 
Test() - -Constructor for class com.daguu.lib.httpsqs4j.Test -
  -
-
- - - - - - - - - - - - - - - -
- -
- - - -C G H M P Q R S T U V
- - - diff --git a/client/httpsqs4j/doc/index.html b/client/httpsqs4j/doc/index.html deleted file mode 100644 index 8106784..0000000 --- a/client/httpsqs4j/doc/index.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - -Generated Documentation (Untitled) - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="com/daguu/lib/httpsqs4j/package-summary.html">Non-frame version.</A> - - - diff --git a/client/httpsqs4j/doc/overview-tree.html b/client/httpsqs4j/doc/overview-tree.html deleted file mode 100644 index e276e6e..0000000 --- a/client/httpsqs4j/doc/overview-tree.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - -Class Hierarchy - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
com.daguu.lib.httpsqs4j
-
-

-Class Hierarchy -

-
    -
  • java.lang.Object -
-
- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/package-list b/client/httpsqs4j/doc/package-list deleted file mode 100644 index f60d002..0000000 --- a/client/httpsqs4j/doc/package-list +++ /dev/null @@ -1 +0,0 @@ -com.daguu.lib.httpsqs4j diff --git a/client/httpsqs4j/doc/resources/inherit.gif b/client/httpsqs4j/doc/resources/inherit.gif deleted file mode 100644 index c814867..0000000 Binary files a/client/httpsqs4j/doc/resources/inherit.gif and /dev/null differ diff --git a/client/httpsqs4j/doc/serialized-form.html b/client/httpsqs4j/doc/serialized-form.html deleted file mode 100644 index 75570df..0000000 --- a/client/httpsqs4j/doc/serialized-form.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - -Serialized Form - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
- -
- - - -
-
-

-Serialized Form

-
-
- - - - - -
-Package com.daguu.lib.httpsqs4j
- -

- - - - - -
-Class com.daguu.lib.httpsqs4j.HttpsqsException extends java.lang.Exception implements Serializable
- -

-serialVersionUID: 1L - -

- -

-


- - - - - - - - - - - - - - - -
- -
- - - -
- - - diff --git a/client/httpsqs4j/doc/stylesheet.css b/client/httpsqs4j/doc/stylesheet.css deleted file mode 100644 index cbd3428..0000000 --- a/client/httpsqs4j/doc/stylesheet.css +++ /dev/null @@ -1,29 +0,0 @@ -/* Javadoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF; color:#000000 } - -/* Headings */ -h1 { font-size: 145% } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ -.TableRowColor { background: #FFFFFF; color:#000000 } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ -.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} - diff --git a/client/httpsqs4j/output/httpsqs4j.jar b/client/httpsqs4j/output/httpsqs4j.jar deleted file mode 100644 index 756c16d..0000000 Binary files a/client/httpsqs4j/output/httpsqs4j.jar and /dev/null differ diff --git a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Httpsqs4j.java b/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Httpsqs4j.java deleted file mode 100644 index 46dca10..0000000 --- a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Httpsqs4j.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * @(#)HttpsqsConnectionInfo.java Apr 29, 2010 - * - * Copyright 2010 QinYu, Inc. All rights reserved. - * - */ -package com.daguu.lib.httpsqs4j; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.URL; - -/** - * - * Httpsqs4j基础类,用于设置连接信息及创建客户端对象 - * - * @author Henry Young - * - */ -public class Httpsqs4j { - - protected static String prefix; - - protected static String charset; - - protected static boolean configured = false; - - /** - * 设置连接信息 - * - * @param ip - * @param port - * @param charset 字符集 - * @throws HttpsqsException - */ - public static void setConnectionInfo(String ip, int port, String charset) throws HttpsqsException { - try { - "".getBytes(charset); - } catch (UnsupportedEncodingException e) { - throw new HttpsqsException("Unknown charset.", (Throwable) e); - } - URL url; - HttpURLConnection connection = null; - String prefix = "http://" + ip + ":" + port + "/"; - try { - url = new URL(prefix); - connection = (HttpURLConnection) url.openConnection(); - connection.connect(); - } catch (IOException e) { - throw new HttpsqsException(prefix + " cannot located.", (Throwable) e); - } finally { - if (connection != null) { - connection.disconnect(); - } - } - Httpsqs4j.prefix = prefix + "?"; - Httpsqs4j.charset = charset; - Httpsqs4j.configured = true; - } - - /** - * 创建新的客户端对象 - * - * @return - */ - public static HttpsqsClient createNewClient() { - return new HttpsqsClient(); - } - -} diff --git a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsClient.java b/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsClient.java deleted file mode 100644 index a997a34..0000000 --- a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsClient.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * - * @(#)HttpsqsClient.java Apr 29, 2010 - * - * Copyright 2010 QinYu, Inc. All rights reserved. - * - */ -package com.daguu.lib.httpsqs4j; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.regex.Matcher; - -/** - * - * 客户端类,使用Httpsqs4j类的createNewClient()方法创建,创建前请先调用Httpsqs4j的setConnectionInfo设置连接信息 - * - * @author Henry Young - * - */ -public class HttpsqsClient { - - private long pos; - - protected HttpsqsClient() { - - } - - private String httpPost(String urlStr, String postData) throws HttpsqsException { - return this.getSource(urlStr, postData); - } - - private String httpGet(String urlStr) throws HttpsqsException { - return this.getSource(urlStr, null); - } - - private String getSource(String urlStr, String postData) throws HttpsqsException { - HttpURLConnection connection = null; - InputStream is = null; - InputStreamReader isr = null; - BufferedReader reader = null; - OutputStream os = null; - OutputStreamWriter osw = null; - StringBuffer sb = new StringBuffer(); - try { - URL url = new URL(Httpsqs4j.prefix + urlStr); - connection = (HttpURLConnection) url.openConnection(); - if (postData != null) { - try { - connection.setDoOutput(true); - os = connection.getOutputStream(); - osw = new OutputStreamWriter(os); - osw.write(postData); - osw.flush(); - } catch (IOException e) { - throw new HttpsqsException("Send data error.", (Throwable) e); - } finally { - if (osw != null) { - osw.close(); - } - if (os != null) { - os.close(); - } - } - } - is = connection.getInputStream(); - isr = new InputStreamReader(is, Httpsqs4j.charset); - reader = new BufferedReader(isr); - String line = ""; - while ((line = reader.readLine()) != null) { - sb.append(line).append('\n'); - } - String pos = connection.getHeaderField("Pos"); - if (pos != null) { - this.pos = Long.valueOf(pos); - } - } catch (IOException e) { - throw new HttpsqsException("Cannot connect to server.", (Throwable) e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (isr != null) { - try { - isr.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (is != null) { - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - if (connection != null) { - connection.disconnect(); - } - } - String sbs = sb.toString(); - if (sbs.contains("HTTPSQS_ERROR")) { - throw new HttpsqsException("Global error."); - } - return sb.toString(); - } - - /** - * 获取最后一次出入队列操作的位置值 - * - * @return - */ - public long getLastPos() { - return this.pos; - } - - /** - * 获取HttpSQS状态 - * - * @param queueName 队列名称 - * @return - * @throws HttpsqsException - */ - public HttpsqsStatus getStatus(String queueName) throws HttpsqsException { - String urlStr = "opt=status&name=" + queueName; - String source = this.httpGet(urlStr); - Matcher matcher = HttpsqsStatus.pattern.matcher(source); - if (matcher.find()) { - HttpsqsStatus status = new HttpsqsStatus(); - status.version = matcher.group(1); - status.queueName = matcher.group(2); - status.maxNumber = Long.parseLong(matcher.group(3)); - status.getLap = Long.parseLong(matcher.group(4)); - status.getPosition = Long.parseLong(matcher.group(5)); - status.putLap = Long.parseLong(matcher.group(6)); - status.putPosition = Long.parseLong(matcher.group(7)); - status.unreadNumber = Long.parseLong(matcher.group(8)); - return status; - } - return null; - } - - /** - * 将字符串加入队列 - * - * @param queueName 队列名称 - * @param str 字符串 - * @throws HttpsqsException - */ - public void putString(String queueName, String str) throws HttpsqsException { - String urlStr = "opt=put&name=" + queueName; - String source = this.httpPost(urlStr, str); - if (source.contains("HTTPSQS_PUT_END")) { - throw new HttpsqsException("Queue [" + queueName + "] fulled."); - } else if (source.contains("HTTPSQS_PUT_ERROR")) { - throw new HttpsqsException("Put data to queue [" + queueName + "] failed."); - } - } - - /** - * 将字符串出队列 - * - * @param queueName 队列名称 - * @return - * @throws HttpsqsException - */ - public String getString(String queueName) throws HttpsqsException { - String urlStr = "opt=get&charset=" + Httpsqs4j.charset + "&name=" + queueName; - String source = this.httpGet(urlStr); - if (source.contains("HTTPSQS_GET_END")) { - throw new HttpsqsException("There's no data in queue [" + queueName + "]."); - } - return source; - } - - /** - * 获取某位置的字符串 - * - * @param queueName 队列名称 - * @param pos 位置 - * @return - * @throws HttpsqsException - */ - public String getStringAt(String queueName, long pos) throws HttpsqsException { - if (pos < 1 || pos > 1000000000l) { - throw new HttpsqsException("Pos' out of range[1 - 1000000000]."); - } - String urlStr = "opt=view&charset=" + Httpsqs4j.charset + "&name=" + queueName + "&pos=" + pos; - return this.httpGet(urlStr); - } - - /** - * 重置队列 - * - * @param queueName 队列名称 - * @return - * @throws HttpsqsException - */ - public boolean reset(String queueName) throws HttpsqsException { - String urlStr = "opt=reset&name=" + queueName; - String source = this.httpGet(urlStr); - return source.contains("HTTPSQS_RESET_OK"); - } - - /** - * 设置最大队列数量 - * - * @param queueName 队列名称 - * @param number 最大数量 - * @return - * @throws HttpsqsException - */ - public boolean setMaxNumber(String queueName, long number) throws HttpsqsException { - if (pos < 10 || pos > 1000000000l) { - throw new HttpsqsException("Pos' out of range[10 - 1000000000]."); - } - String urlStr = "opt=maxqueue&name=" + queueName + "&num=" + number; - String source = this.httpGet(urlStr); - return source.contains("HTTPSQS_MAXQUEUE_OK"); - } - -} diff --git a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsException.java b/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsException.java deleted file mode 100644 index 1b91f56..0000000 --- a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsException.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * - * @(#)HttpsqsException.java Apr 29, 2010 - * - * Copyright 2010 QinYu, Inc. All rights reserved. - * - */ -package com.daguu.lib.httpsqs4j; - -/** - * @author Henry Young - * - */ -public class HttpsqsException extends Exception { - - private static final long serialVersionUID = 1L; - - public HttpsqsException() { - super(); - } - - public HttpsqsException(String message) { - super(message); - } - - public HttpsqsException(String message, Throwable cause) { - super(message, cause); - } - -// public HttpsqsException - -} diff --git a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsStatus.java b/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsStatus.java deleted file mode 100644 index 7d90416..0000000 --- a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/HttpsqsStatus.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * - * @(#)HttpsqsStatus.java Apr 29, 2010 - * - * Copyright 2010 QinYu, Inc. All rights reserved. - * - */ -package com.daguu.lib.httpsqs4j; - -import java.util.regex.Pattern; - -/** - * @author Henry Young - * - */ -public class HttpsqsStatus { - - /** - * HttpSQS版本 - */ - public String version; - - /** - * 队列名称 - */ - public String queueName; - - /** - * 队列最大数量 - */ - public long maxNumber; - - /** - * 当前入队位置 - */ - public long putPosition; - - /** - * 当前入队圈数 - */ - public long putLap; - - /** - * 当前出队位置 - */ - public long getPosition; - - /** - * 当前出队圈数 - */ - public long getLap; - - /** - * 当前未出队数量 - */ - public long unreadNumber; - - protected static Pattern pattern = Pattern.compile("HTTP Simple Queue Service v(.+?)\\s(?:.+?)\\sQueue Name: (.+?)\\sMaximum number of queues: (\\d+)\\sPut position of queue \\((\\d+)st lap\\): (\\d+)\\sGet position of queue \\((\\d+)st lap\\): (\\d+)\\sNumber of unread queue: (\\d+)"); - -} diff --git a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Test.java b/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Test.java deleted file mode 100644 index 4578199..0000000 --- a/client/httpsqs4j/src/com/daguu/lib/httpsqs4j/Test.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * @(#)Tester.java Apr 29, 2010 - * - * Copyright 2010 QinYu, Inc. All rights reserved. - * - */ -package com.daguu.lib.httpsqs4j; - -/** - * @author Henry Young - * - */ -public class Test { - - public static void main(String[] args) { - try { - Httpsqs4j.setConnectionInfo("192.168.1.201", 1218, "UTF-8"); - HttpsqsClient client = Httpsqs4j.createNewClient(); - HttpsqsStatus status = client.getStatus("asdf"); - System.out.println(status.version); - System.out.println(status.queueName); - System.out.println(status.maxNumber);; - System.out.println(status.getLap);; - System.out.println(status.getPosition); - System.out.println(status.putLap); - System.out.println(status.putPosition); - System.out.println(status.unreadNumber); - client.putString("asdf", "test"); - System.out.println(client.getString("asdf")); - } catch (HttpsqsException e) { - e.printStackTrace(); - } - } - -} diff --git a/client/java/Httpsqs_client.java b/client/java/Httpsqs_client.java deleted file mode 100644 index a9e0fc7..0000000 --- a/client/java/Httpsqs_client.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 不包括keep-alive的部分,get方法只能获得数据,无法获得pos - * 作者:李博 lb13810398408@gmail.com - */ - -import java.io.*; -import java.net.*; - -class Httpsqs_client { - private String server, port, charset; - - public Httpsqs_client(String server, String port, String charset) { - this.server = server; - this.port = port; - this.charset = charset; - } - - private String doprocess(String urlstr) { - URL url = null; - try { - url = new URL(urlstr); - } catch (MalformedURLException e) { - return "The httpsqs server must be error"; - } - try { - BufferedReader instream = new BufferedReader(new InputStreamReader(url.openStream())); - String s = null; - StringBuffer result = new StringBuffer(""); - - while((s = instream.readLine()) != null) - { - result.append(s); - } - instream.close(); - return result.toString(); - } catch (IOException e) { - return "Get data error"; - } - } - - public String maxqueue(String queue_name, String num) { - String urlstr = "http://" + this.server + ":" + this.port + "/?name=" + queue_name + "&opt=maxqueue&num=" + num; - String result = null; - - result = this.doprocess(urlstr); - return result; - } - - public String reset(String queue_name) { - String urlstr = "http://" + this.server + ":" + this.port + "/?name=" + queue_name + "&opt=reset"; - String result = null; - - result = this.doprocess(urlstr); - return result; - } - - public String view(String queue_name, String pos) { - String urlstr = "http://" + this.server + ":" + this.port + "/?charset=" + this.charset + "&name=" + queue_name + "&opt=view&pos=" + pos; - String result = null; - - result = this.doprocess(urlstr); - return result; - } - - public String status(String queue_name) { - String urlstr = "http://" + this.server + ":" + this.port + "/?name=" + queue_name + "&opt=status"; - String result = null; - - result = this.doprocess(urlstr); - return result; - } - - public String get(String queue_name) { - String urlstr = "http://" + this.server + ":" + this.port + "/?charset=" + this.charset + "&name=" + queue_name + "&opt=get"; - String result = null; - - result = this.doprocess(urlstr); - return result; - } - - public String put(String queue_name, String data) { - String urlstr = "http://" + this.server + ":" + this.port + "/?name=" + queue_name + "&opt=put"; - URL url = null; - try { - url = new URL(urlstr); - } catch (MalformedURLException e) { - return "The httpsqs server must be error"; - } - - URLConnection conn = null; - - try { - conn = url.openConnection(); - conn.setDoOutput(true); - OutputStreamWriter out = null; - out = new OutputStreamWriter(conn.getOutputStream()); - out.write(data); - out.flush(); - out.close(); - } catch (IOException e) { - return "Put data error"; - } - - BufferedReader reader = null; - - try { - reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String line = null; - while ((line = reader.readLine()) != null) { - return line; - } - } catch (IOException e) { - return "Get return data error"; - } - return null; - } -} \ No newline at end of file diff --git a/client/java/Test.java b/client/java/Test.java deleted file mode 100644 index 66d0c78..0000000 --- a/client/java/Test.java +++ /dev/null @@ -1,18 +0,0 @@ -public class Test { - public static void main(String args[]) - { - Httpsqs_client sqs = new Httpsqs_client("192.168.1.102", "1218", "utf-8"); - String result = null; - result = sqs.put("testq", "dsadasd"); - System.out.println(result); - System.out.println("---------------------------"); - result = sqs.status("testq"); - System.out.println(result); - System.out.println("---------------------------"); - result = sqs.get("testq"); - System.out.println(result); - System.out.println("---------------------------"); - result = sqs.reset("testq"); - System.out.println(result); - } -} diff --git a/client/perl/HttpSQS.pm b/client/perl/HttpSQS.pm deleted file mode 100644 index 45f7a70..0000000 --- a/client/perl/HttpSQS.pm +++ /dev/null @@ -1,579 +0,0 @@ -# set cindent expandtab ts=4 sw=4 -# HTTP Simple Queue Service - httpsqs client class for Perl v0.1.0 -# httpsqs Project website : http://code.google.com/p/httpsqs/, -# Author : Tony E-mail: tonny0830@gmail.com -# Complete Date : 2010.3.10 -# Bug Commit : If you find any bug, Please Send Email for me! Thanks, -*^_^*- -# This is free software , you are may modify and redistribute it under the GPL License - -package HttpSQS ; - -use IO::Socket ; -use v5.8.8 ; - -$| = 1 ; - -my $DEBUG = 0 ; - -sub new { - my $class = shift ; - (my $host, my $port, my $protocol, my $charset) = @_ ; - my $ref = { - Host => $host || '127.0.0.1', - Port => $port || '1218', - Protocol => $protocol || 'tcp', - CharSet => $charset || 'utf-8', - }; - - bless $ref,$class ; - return $ref ; -} - -sub http_get { - my $self = shift ; - my $query = shift ; - my $body = undef ; - my $header = undef ; - - print "instant method http_get pass \$query values $query\n" if $DEBUG ; - - my $connect = IO::Socket::INET->new( - PeerAddr => $self->{'Host'}, - PeerPort => $self->{'Port'}, - Proto => $self->{'Protocol'}, - Type => SOCK_STREAM) or warn "I can't connect to $self->{'Host'} on port $self->{'Port'} :$!\n" ; - - $connect->autoflush(1) ; - - if($connect) - { - my $write_mesg = "GET $query HTTP/1.1\r\n" ; - $write_mesg .= "Host: $self->{'Host'}\r\n" ; - $write_mesg .= "Connection: close\r\n" ; - - $write_mesg .= "\r\n" ; - - print "http_get \$write_mesg variabel values $write_mesg\n" if $DEBUG ; - - $connect->print($write_mesg) ; - - my $line = _trim($connect->getline()) ; - - print "http_get \$line variable values $line\n" if $DEBUG ; - - $header .= $line ; - - print "http_get \$header variable values $header\n" if $DEBUG ; - - (my $proto, my $rcode, my $result) = split(" ",$line) ; - - my $len = -1 ; - my $cl = undef ; - my $close = undef ; - - while(($line = _trim($connect->getline())) ne "") - { - print "http_get method readsocket \$line $line\n" if $DEBUG ; - - $header .= $line ; - - print "http_get method variable values \$header $header\n" if $DEBUG ; - - if(_strstr($line, "Content-Length:")) - { - ($cl, $len) = split(/ /,$line) ; - } - if(_strstr($line, "Connection: close")) - { - $close = 1 ; - } - } - if($len < 0) - { - return 0 ; - } - - while((my $read = $connect->getline())) - { - $body .= $read ; - } - - if($close) - { - close($connect) ; - } - print "http_get return \$body values $body\n" if $DEBUG ; - - return $body ; - - }else { - return 0 ; - - close($connect) ; - } -} -sub http_post { - my $self = shift ; - my $query = shift ; - my $body = shift ; - my $header = undef ; - my $return_value = undef ; - my $connect = IO::Socket::INET->new( - PeerAddr => $self->{'Host'}, - PeerPort => $self->{'Port'}, - Proto => $self->{'Protocol'}, - Type => SOCK_STREAM) or warn "I can't connect to $self->{'Host'} on port $self->{'Port'} :$!\n" ; - - $connect->autoflush(1) ; - - print "http_post method \$query variable values $query\n" if $DEBUG ; - - if($connect) - { - my $write_mesg = "POST $query HTTP/1.1\r\n" ; - $write_mesg .= "Host: $self->{'Host'}\r\n" ; - $write_mesg .= "Content-Length: ".length($body)."\r\n" ; - $write_mesg .= "Connection: close\r\n" ; - $write_mesg .= "\r\n" ; - $write_mesg .= $body ; - - print "http_post method \$write_mesg variable values $write_mesg\n" if $DEBUG ; - - $connect->print($write_mesg) ; - - my $line = _trim($connect->getline()) ; - - print "http_post method \$line variable values $line\n" if $DEBUG ; - - $header .= $line ; - - print "http_post method \$header variable values $header\n" if $DEBUG ; - - (my $proto, my $rcode, my $result) = split(" ",$line) ; - - my $len = -1 ; - my $cl = undef ; - my $close = undef ; - - while(($line= _trim($connect->getline())) ne "") - { - $header .= $line ; - - if(_strstr($line, "Content-Length:")) - { - ($cl, $len) = split(/ /,$line) ; - } - if(_strstr($line, "Connection: close")) - { - $close = 1 ; - } - } - if($len < 0) - { - return 0 ; - } - while((my $read = $connect->getline())) - { - $return_value .= $read ; - } - - if($close) - { - close($connect) ; - } - - print "http_post method \$return_value variable vanues $return_value\n" if $DEBUG ; - - return $return_value ; - - }else{ - - return 0 ; - - close($connect) ; - } -} -sub http_pget { - my $self = shift ; - my $query = shift ; - my $body = undef ; - my $header = undef ; - my $connect = IO::Socket::INET->new( - PeerAddr => $self->{'Host'}, - PeerPort => $self->{'Port'}, - Proto => $self->{'Protocol'}, - Type => SOCK_STREAM) or warn "I can't connect to $self->{'Host'} on port $self->{'Port'} :$!\n" ; - - $connect->autoflush(1) ; - - print "http_pget method \$query variable values $query\n" if $DEBUG ; - - if($connect) - { - my $write_mesg = "GET $query HTTP/1.1\r\n" ; - $write_mesg .= "Host: $self->{'Host'}\r\n" ; - $write_mesg .= "Connection: Keep-Alive\r\n" ; - $write_mesg .= "\r\n" ; - - print "http_pget method \$write_mesg variable values $write_mesg\n" if $DEBUG ; - - $connect->print($write_mesg) ; - - my $line = _trim($connect->getline()) ; - - print "http_pget method \$line variable values $line\n" if $DEBUG ; - - $header .= $line ; - - print "http_pget method \$header variable values $header\n" if $DEBUG ; - - (my $proto, my $rcode, my $result) = split(" ",$line) ; - - my $len = -1 ; - my $cl = undef ; - my $close = undef ; - - while(($line= _trim($connect->getline())) ne "") - { - $header .= $line ; - - if(_strstr($line,"Content-Length:")) - { - ($cl,$len) = split(/ /,$line) ; - } - if(_strstr($line,"Connection: close")) - { - $close = 1 ; - } - } - if($len < 0) - { - return 0 ; - } - - while((my $read = $connect->getline())) - { - $body .= $read ; - } - - if($close) - { - close($connect) ; - } - print "http_pget method \$body variable values $body\n" if $DEBUG ; - - return $body ; - - }else{ - - return 0 ; - - close($connect) ; - } -} -sub http_ppost { - my $self = shift ; - my $query = shift ; - my $body = shift ; - my $header = undef ; - my $return_value = undef ; - my $connect = IO::Socket::INET->new( - PeerAddr => $self->{'Host'}, - PeerPort => $self->{'Port'}, - Proto => $self->{'Protocol'}, - Type => SOCK_STREAM) or warn "I can't connect to $self->{'Host'} on port $self->{'Port'} :$!\n" ; - $connect->autoflush(1) ; - print "http_ppost method \$query and \$body variable values $query |||||||| $body\n" if $DEBUG ; - - if($connect) - { - my $write_mesg = "POST $query HTTP/1.1\r\n" ; - $write_mesg .= "Host: $self->{'Host'}\r\n" ; - $write_mesg .= "Content-Length: ".length($body)."\r\n" ; - $write_mesg .= "Connection: Keep-Alive\r\n" ; - $write_mesg .= "\r\n" ; - $write_mesg .= $body ; - - print "http_ppost method \$write_mesg variable values $write_mesg\n" if $DEBUG ; - - $connect->print($write_mesg) ; - - my $line = _trim($connect->getline()) ; - - $header .= $line ; - - print "http_ppost method \$header and \$line variable values $header ===== $line\n" if $DEBUG ; - - (my $proto, my $rcode, my $result) = split(" ",$line) ; - - print "http_ppost method \$proto \$rcode \$result variable values $proto\\$rcode\\$result\n" if $DEBUG ; - - my $len = -1 ; - my $cl = undef ; - my $close = undef ; - - while(($line= _trim($connect->getline())) ne "") - { - print "\$line trim value $line\n" if $DEBUG ; - - print "http_ppost method \$line variable values $line\n" if $DEBUG ; - - $header .= $line ; - - print "http_ppost method \$header variable values $header\n" if $DEBUG ; - - if(_strstr($line, "Content-Length:")) - { - ($cl, $len) = split(/ /,$line) ; - } - if(_strstr($line, "Connection: close")) - { - $close = 1 ; - } - } - if($len < 0) - { - return 0 ; - } - while((my $read = $connect->getline())) - { - print "http_ppost method \$read variable values $read\n" if $DEBUG ; - - $return_value .= $read ; - } - - if($close) - { - close($connect) ; - } - - print "http_ppost method \$return_value variable values $return_value\n" if $DEBUG ; - - return $return_value ; - - }else{ - - return 0 ; - - close($connect) ; - } -} - -sub put { - my $self= shift ; - my $name = shift ; - my $data = shift ; - my $result = $self->http_post("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=put",$data) ; - - chomp $result ; - - if($result eq "HTTPSQS_PUT_OK") - { - return 1 ; - } - return 0 ; -} -sub get { - my $self = shift ; - my $name = shift ; - my $result = $self->http_get("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=get") ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub status { - my $self = shift ; - my $name = shift ; - my $result = $self->http_get("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=status") ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub view { - my $self = shift ; - my $name = shift ; - my $pos = shift ; - my $result = $self->http_get("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=view&pos=".$pos) ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub reset { - my $self = shift ; - my $name = shift ; - my $result = $self->http_get("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=reset") ; - - chomp $result ; - - if($result eq "HTTPSQS_RESET_OK") - { - return 1 ; - } - return 0 ; -} -sub maxqueue { - my $self = shift ; - my $name = shift ; - my $num = shift ; - - my $result = $self->http_get("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=maxqueue&num=".$num) ; - - chomp $result ; - - if($result eq "HTTPSQS_MAXQUEUE_OK") - { - return 1 ; - } - return 0 ; -} -sub pput { - my $self = shift ; - my $name = shift ; - my $data = shift ; - - my $result = $self->http_ppost("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=put",$data) ; - - chomp $result ; - - if($result eq "HTTPSQS_PUT_OK") - { - return 1 ; - } - return 0 ; -} -sub pget { - my $self = shift ; - my $name = shift ; - - my $result = $self->http_pget("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=get") ; - - print "HttpSQS pget method return \$result=$result\n" ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub pstatus { - my $self = shift ; - my $name = shift ; - - my $result = $self->http_pget("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=status") ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub pview { - my $self = shift ; - my $name = shift ; - my $pos = shift ; - - my $result = $self->http_pget("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=view&pos=".$pos) ; - - chomp $result ; - - if($result eq "HTTPSQS_ERROR" or !$result) - { - return 0 ; - } - return $result ; -} -sub preset { - my $self = shift ; - my $name = shift ; - - my $result = $self->http_pget("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=reset") ; - - chomp $result ; - - if($result eq "HTTPSQS_RESET_OK") - { - return 1 ; - } - return 0 ; -} -sub pmaxqueue { - my $self = shift ; - my $name = shift ; - my $num = shift ; - - my $result = $self->http_pget("/?charset=".$self->{'CharSet'}."&name=".$name."&opt=maxqueue&num=".$num) ; - - chomp $result ; - - if($result eq "HTTPSQS_MAXQUEUE_OK") - { - return 1 ; - } - return 0 ; -} -sub DESTROY { - my $self = shift ; - - %$self = undef ; -} -############################################################################ -# -# Class Internal tools function -# -############################################################################ - -# Explain : _trim function delete character string head and tail blanket -sub _trim { - my $retn = shift ; - $retn =~ s/^\s*|\s*$//g ; - return $retn ; -} -sub _strstr { - my $str = shift ; - my $match_str = shift ; - my $str_rtn = undef ; - - if($str =~ m#$match_str#) - { - $str_rtn = $&.$' ; - return $str_rtn ; - } - return 0 ; -} -# Explain: _urlencode encode URL character string , _urldecode decode URL character string. -sub _urlencode { - ($_, my $mlm) = (join('', @_), $*); - $* = 1; - s/[^\w!\$'()*,\-.]/sprintf('%%%02x', ord $&)/ge; - s/ /+/g; - $* = $mlm; - return $_; -} -sub _urldecode { - ($_, my $mlm) = (join('', @_), $*); - $* = 1; - s/\+/ /g; - s/%([\da-f]{2})/pack('C', hex $1)/gie; - $* = $mlm; - return $_; -} -1 ; diff --git a/client/perl/License b/client/perl/License deleted file mode 100644 index e69de29..0000000 diff --git a/client/perl/README b/client/perl/README deleted file mode 100644 index f2e4db3..0000000 --- a/client/perl/README +++ /dev/null @@ -1,109 +0,0 @@ -HttpSQS 模块参数说明 -开发平台:CentOS 5.4 -Perl版本:5.8.8 -Editor: VIM -################################################################## -new 方法: - -参数个数:4个 - -参数说明: - 1.HttpSQS-服务器IP地址。 - 2.HttpSQS-工作端口号。 - 3.Proto-连接服务器协议类型,TCP 还是UDP. 默认是TCP连接。 - 4.Charset-字符集。默认是UTF-8。 -################################################################### -put方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.以POST方式提交的字符串 -#################################################################### -get方法: - -参数个数:1个 - -传递参数: - 1.队列名 -#################################################################### -status方法: - -参数个数:1个 - -传递参数: - 1.队列名 -##################################################################### -view方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.查看队列的编号 -##################################################################### -reset方法: - -参数个数:1个 - -传递参数: - 1.队列名 -##################################################################### -maxqueue方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.指定的最大队列数 -##################################################################### -pput方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.POST方式提交的数据。 -##################################################################### -pget方法: - -参数个数:1个 - -传递参数: - 1.队列名 -##################################################################### -pstatus方法: - -参数个数:1个 - -传递参数: - 1.队列名 -##################################################################### -pview方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.查看队列的编号。 -##################################################################### -pmaxqueue方法: - -参数个数:2个 - -传递参数: - 1.队列名 - 2.指定队列的最大数。 -##################################################################### -preset方法: - -参数个数:1个 - -传递参数: - 1.队列名 -##################################################################### - -使用的例子见: -httpsqs_cmdline_test.pl -httpsqs_cmdline_loop_test.pl diff --git a/client/perl/Version b/client/perl/Version deleted file mode 100644 index 6e8bf73..0000000 --- a/client/perl/Version +++ /dev/null @@ -1 +0,0 @@ -0.1.0 diff --git a/client/perl/httpsqs_cmdline_loop_test.pl b/client/perl/httpsqs_cmdline_loop_test.pl deleted file mode 100644 index d2de5ca..0000000 --- a/client/perl/httpsqs_cmdline_loop_test.pl +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/perl -w - -use HttpSQS ; -use Benchmark qw(:all) ; -use v5.8.8 ; - -# clear block buffer - -$| = 1 ; - -my $number = 10 ; - -my $mesg = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ; - -my $sqs = HttpSQS->new("127.0.0.1","1218",'tcp','utf-8') ; - -# Just testing in my perl source code -my $tm_0 = new Benchmark ; - -for(my $i=1;$i<=$number;$i++) -{ - my $str = $i.$mesg ; - my $rtn = $sqs->pput("perl_cmdline_test","$str") ; - print "pput method return value $rtn\n" ; -} -for(my $j=1;$j<=$number;$j++) -{ - my $result = $sqs->pget("perl_cmdline_test") ; - print "HttpSQS return result $result\n" ; -} -my $tm_1 = new Benchmark ; - -my $td = timediff($tm_1,$tm_0) ; - -print "The code diff run time:",timestr($td),"\n" ; diff --git a/client/perl/httpsqs_cmdline_test.pl b/client/perl/httpsqs_cmdline_test.pl deleted file mode 100644 index f95eaaa..0000000 --- a/client/perl/httpsqs_cmdline_test.pl +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/perl - -# This script Just test programe HttpSQS module -# Autho : Tony -# Date : 2010.3.10 -# Email : tonny0830@gmail.com - -use strict ; -use HttpSQS ; -use v5.8.8 ; - -$| = 1 ; - -my $sqs = HttpSQS->new("127.0.0.1","1218",'tcp','utf-8') ; - -# Just testing in my perl source code -my $put = $sqs->put("perl_cmdline_test","hello") ; - -print "HttpSQS put return result $put\n" ; - -my $status = $sqs->status("perl_cmdline_test") ; - -print "HttpSQS status return result $status\n" ; - -my $get = $sqs->get("perl_cmdline_test") ; - -print "HttpSQS get return result $get\n" ; - -my $view = $sqs->view("perl_cmdline_test",1) ; - -print "HttpSQS view return result $view\n" ; - -# If reset OK, will return 1, reset fail will return 0 ; -my $reset = $sqs->reset("perl_cmdline_test") ; - -print "HttpSQS reset return result $reset\n" ; - -# If maxqueue set OK, will return 1, If fail will return 0 ; -my $maxqueue = $sqs->maxqueue("perl_cmdline_test",1_0_0_0) ; - -print "HttpSQS maxqueue return result $maxqueue\n" ; - -#$print "HttpSQS urlencode return result $urlencode\n" ; -my $pput = $sqs->pput("p_perl_cmdline_test","abcdefghi") ; - -print "HttpSQS pput return result $pput\n" ; - -# If get Data OK,then will return data,else return 0 ; -my $pget = $sqs->pget("p_perl_cmdline_test") ; - -print "HttpSQS pget return result $pget\n" ; - -my $pstatus = $sqs->pstatus("p_perl_cmdline_test") ; - -print "HttpSQS pstatus return result $pstatus\n" ; - -# If view data OK,then will return data, else return 0 -my $pview = $sqs->pview("p_perl_cmdline_test",1) ; - -print "HttpSQS pview return result $pview\n" ; - -# If set pmaxqueue OK, will return 1, fail return 0 -my $pmaxqueue = $sqs->pmaxqueue("p_perl_cmdline_test",1_0_0_0) ; - -print "HttpSQS pmaxqueue return result $pmaxqueue\n" ; - -# If reset OK,will return 1, fail will return 0 -my $preset = $sqs->preset("p_perl_cmdline_test") ; - -print "HttpSQS preset return result $preset\n" ; diff --git a/client/php/httpsqs_client.php b/client/php/httpsqs_client.php deleted file mode 100644 index 6a9d01c..0000000 --- a/client/php/httpsqs_client.php +++ /dev/null @@ -1,226 +0,0 @@ -put($queue_name, $queue_data); //1. PUT text message into a queue. If PUT successful, return boolean: true. If an error occurs, return boolean: false. If queue full, return text: HTTPSQS_PUT_END -$result = $httpsqs->get($queue_name); //2. GET text message from a queue. Return the queue contents. If an error occurs, return boolean: false. If there is no unread queue message, return text: HTTPSQS_GET_END -$result = $httpsqs->gets($queue_name); //3. GET text message and pos from a queue. Return example: array("pos" => 7, "data" => "text message"). If an error occurs, return boolean: false. If there is no unread queue message, return: array("pos" => 0, "data" => "HTTPSQS_GET_END") -$result = $httpsqs->status($queue_name); //4. View queue status -$result = $httpsqs->status_json($queue_name); //5. View queue status in json. Return example: {"name":"queue_name","maxqueue":5000000,"putpos":130,"putlap":1,"getpos":120,"getlap":1,"unread":10} -$result = $httpsqs->view($queue_name, $queue_pos); //6. View the contents of the specified queue pos (id). Return the contents of the specified queue pos. -$result = $httpsqs->reset($queue_name); //7. Reset the queue. If reset successful, return boolean: true. If an error occurs, return boolean: false -$result = $httpsqs->maxqueue($queue_name, $num); //8. Change the maximum queue length of per-queue. If change the maximum queue length successful, return boolean: true. If it be cancelled, return boolean: false -$result = $httpsqs->synctime($num); //9. Change the interval to sync updated contents to the disk. If change the interval successful, return boolean: true. If it be cancelled, return boolean: false -?> ----------------------------------------------------------------------------------------------------------------- -*/ - -class httpsqs -{ - public $httpsqs_host; - public $httpsqs_port; - public $httpsqs_auth; - public $httpsqs_charset; - - public function __construct($host='127.0.0.1', $port=1218, $auth='', $charset='utf-8') { - $this->httpsqs_host = $host; - $this->httpsqs_port = $port; - $this->httpsqs_auth = $auth; - $this->httpsqs_charset = $charset; - return true; - } - - public function http_get($query) - { - $socket = fsockopen($this->httpsqs_host, $this->httpsqs_port, $errno, $errstr, 5); - if (!$socket) - { - return false; - } - $out = "GET ${query} HTTP/1.1\r\n"; - $out .= "Host: ${host}\r\n"; - $out .= "Connection: close\r\n"; - $out .= "\r\n"; - fwrite($socket, $out); - $line = trim(fgets($socket)); - $header .= $line; - list($proto, $rcode, $result) = explode(" ", $line); - $len = -1; - while (($line = trim(fgets($socket))) != "") - { - $header .= $line; - if (strstr($line, "Content-Length:")) - { - list($cl, $len) = explode(" ", $line); - - } - if (strstr($line, "Pos:")) - { - list($pos_key, $pos_value) = explode(" ", $line); - } - if (strstr($line, "Connection: close")) - { - $close = true; - } - } - if ($len < 0) - { - return false; - } - - $body = fread($socket, $len); - $fread_times = 0; - while(strlen($body) < $len){ - $body1 = fread($socket, $len); - $body .= $body1; - unset($body1); - if ($fread_times > 100) { - break; - } - $fread_times++; - } - //if ($close) fclose($socket); - fclose($socket); - $result_array["pos"] = (int)$pos_value; - $result_array["data"] = $body; - return $result_array; - } - - public function http_post($query, $body) - { - $socket = fsockopen($this->httpsqs_host, $this->httpsqs_port, $errno, $errstr, 1); - if (!$socket) - { - return false; - } - $out = "POST ${query} HTTP/1.1\r\n"; - $out .= "Host: ${host}\r\n"; - $out .= "Content-Length: " . strlen($body) . "\r\n"; - $out .= "Connection: close\r\n"; - $out .= "\r\n"; - $out .= $body; - fwrite($socket, $out); - $line = trim(fgets($socket)); - $header .= $line; - list($proto, $rcode, $result) = explode(" ", $line); - $len = -1; - while (($line = trim(fgets($socket))) != "") - { - $header .= $line; - if (strstr($line, "Content-Length:")) - { - list($cl, $len) = explode(" ", $line); - } - if (strstr($line, "Pos:")) - { - list($pos_key, $pos_value) = explode(" ", $line); - } - if (strstr($line, "Connection: close")) - { - $close = true; - } - } - if ($len < 0) - { - return false; - } - $body = @fread($socket, $len); - //if ($close) fclose($socket); - fclose($socket); - $result_array["pos"] = (int)$pos_value; - $result_array["data"] = $body; - return $result_array; - } - - public function put($queue_name, $queue_data) - { - $result = $this->http_post("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=put", $queue_data); - if ($result["data"] == "HTTPSQS_PUT_OK") { - return true; - } else if ($result["data"] == "HTTPSQS_PUT_END") { - return $result["data"]; - } - return false; - } - - public function get($queue_name) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=get"); - if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) { - return false; - } - return $result["data"]; - } - - public function gets($queue_name) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=get"); - if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) { - return false; - } - return $result; - } - - public function status($queue_name) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=status"); - if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) { - return false; - } - return $result["data"]; - } - - public function view($queue_name, $queue_pos) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=view&pos=".$pos); - if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) { - return false; - } - return $result["data"]; - } - - public function reset($queue_name) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=reset"); - if ($result["data"] == "HTTPSQS_RESET_OK") { - return true; - } - return false; - } - - public function maxqueue($queue_name, $num) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=maxqueue&num=".$num); - if ($result["data"] == "HTTPSQS_MAXQUEUE_OK") { - return true; - } - return false; - } - - public function status_json($queue_name) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=".$queue_name."&opt=status_json"); - if ($result == false || $result["data"] == "HTTPSQS_ERROR" || $result["data"] == false) { - return false; - } - return $result["data"]; - } - - public function synctime($num) - { - $result = $this->http_get("/?auth=".$this->httpsqs_auth."&charset=".$this->httpsqs_charset."&name=httpsqs_synctime&opt=synctime&num=".$num); - if ($result["data"] == "HTTPSQS_SYNCTIME_OK") { - return true; - } - return false; - } -} -?> \ No newline at end of file diff --git a/client/php/test_commandline.php b/client/php/test_commandline.php deleted file mode 100644 index 5a5224f..0000000 --- a/client/php/test_commandline.php +++ /dev/null @@ -1,35 +0,0 @@ -put("command_line_test", $i.$message); -} -$run_time = microtime(true) - $start_time; -echo "PUT ".$number." messages. Run Time for Queue PUT: $run_time sec, ".$number/$run_time." requests/sec\n"; -ob_flush(); - -/* test queue get */ -echo "Test Queue GET, please waitting ...\n"; -$start_time = microtime(true); -for ($i=1;$i<=$number;$i++){ - $result = $httpsqs->get("command_line_test"); - //echo($result."\n"); -} -$run_time = microtime(true) - $start_time; -echo "GET ".$number." messages. Run Time for Queue GET: $run_time sec, ".$number/$run_time." requests/sec\n"; -?> diff --git a/client/php/test_example.php b/client/php/test_example.php deleted file mode 100644 index 6100147..0000000 --- a/client/php/test_example.php +++ /dev/null @@ -1,53 +0,0 @@ -put("your_queue_name1", urlencode("text_message1")); -echo "###1.put result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->get("your_queue_name1"); -echo "###2.get result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->put("your_queue_name1", urlencode("text_message2")); -echo "###3.put result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->gets("your_queue_name1"); -echo "###4.gets result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->status("your_queue_name1"); -echo "###5.status result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->status_json("your_queue_name1"); -echo "###6.status_json result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->view("your_queue_name1", 1); -echo "###7.view result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->reset("your_queue_name1"); -echo "###8.reset result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->maxqueue("your_queue_name1", 5000000); -echo "###9.maxqueue result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; - -$result = $httpsqs->synctime(10); -echo "###10.synctime result:\r\n"; -var_dump($result); -echo "\r\n\r\n"; -?> diff --git a/client/python/httpsqs_client.py b/client/python/httpsqs_client.py deleted file mode 100644 index eb0b6f8..0000000 --- a/client/python/httpsqs_client.py +++ /dev/null @@ -1,132 +0,0 @@ -# -*- coding:utf-8 -*- - -""" - @author: Yusong Cui - @copyright: This is free software, under the New BSD License -""" - -import urllib2 -import urllib - -class httpsqs: - host = "127.0.0.1" - port = '1218' - charset = 'utf-8' - name = '' - - #初始化参数,地址,端口,队列名称,字符编码 - def __init__(self, host, port, name, charset='utf-8'): - self.host = host - self.port = port - self.name = name - self.charset = charset - - def request(self, opt, data=None, name=None, method='GET', charset=None): - if name is None: - name = self.name - if charset is None: - charset = self.charset - param = {'charset':charset, 'name':name, 'opt':opt} - if data : - param.update(data) - - url = 'http://' + self.host + ':' + self.port + '/?' - param_str = urllib.urlencode(param) - getString = url + param_str - req = urllib2.Request(getString) - try: - handle = urllib2.urlopen(req) - except: - return False - - return handle - - #获取队首一个元素及位置信息 - def gets(self, q_name=None): - result = {} - handle = self.request('get',name=q_name) - result['pos'] = self.pos(handle) - result['data'] = handle.read() - - if result['data'] == 'HTTPSQS_GET_END': - return False - else: - return result - - #获取一个队列元素 - def get(self, q_name=None): - result = self.request('get',name=q_name).read() - if result != 'HTTPSQS_GET_END': - return result - else: - return False - - #向队尾增加一个元素 - def put(self, data, q_name=None): - result = {} - handle = self.request('put', {'data':data}, q_name) - result['data'] = handle.read() - if result['data'] == 'HTTPSQS_PUT_OK': - return True - else: - return False - - #重置队列 - def reset(self, q_name=None): - handle = self.request('reset', name=q_name) - str = handle.read() - if str == 'HTTPSQS_RESET_OK': - return True - else: - return False - - #设置队列最大值 - def maxqueue(self, num, q_name=None): - if not num: - return False - - str = self.request('maxqueue', {'num':num}, q_name).read() - if str == 'HTTPSQS_MAXQUEUE_OK': - return True - else: - return False - - #以json格式返回队列状态等信息 - def status_json(self, q_name=None): - str = self.request('status_json', name=q_name).read() - if str != 'HTTPSQS_ERROR' and str: - return str - else: - return False - - #设置同步时间间隔 - def synctime(self, num, q_name=None): - if not num: - return False - str = self.request('synctime', {'num':num}, q_name).read() - if str == 'HTTPSQS_SYNCTIME_OK': - return True - else: - return False - - #获取队列状态信息 - def status(self, q_name=None): - str = self.request('status', name=q_name).read() - if str != 'HTTPSQS_ERROR' and str: - return str - else: - return False - - #根据队列位置查看状态 - def view(self, pos, q_name=None): - str = self.request('view', {'pos':pos}, q_name).read() - if str != 'HTTPSQS_ERROR' and str: - return str - else: - return False - - #根据request句柄获取header部分的pos - def pos(self, handle): - pos = int(handle.info().headers[2].replace('\r\n', '').split(':')[1]) - return pos - diff --git a/client/python/test_http_client.py b/client/python/test_http_client.py deleted file mode 100644 index e0194ae..0000000 --- a/client/python/test_http_client.py +++ /dev/null @@ -1,44 +0,0 @@ -# -*- coding:utf-8 -*- -from httpsqs_client import httpsqs - -sqs = httpsqs('10.249.200.168', '1218', 'test') - -def test_put(): - l = ['a','b', 'c', 1, 2, 3] - for node in l: - print sqs.put(node) - print sqs.put(node, 'other') - -def test_get(): - print sqs.get() - print sqs.get('other') -def test_gets(): - print sqs.gets() - print sqs.gets('other') - - -def test_status(): - print sqs.status() - print sqs.status('other') - -def test_view(pos): - print sqs.view(pos) - print sqs.view(pos,'other') - -def test_status_json(): - print sqs.status_json() - print sqs.status_json('other') - -def test_reset(): - print sqs.reset() - print sqs.reset('other') - -if __name__ == '__main__': -# test_put() -# test_get() -# test_status() -# test_view(20) - test_status_json() -# test_gets() - test_reset() - \ No newline at end of file diff --git a/httpsqs.c b/httpsqs.c deleted file mode 100644 index fd3053a..0000000 --- a/httpsqs.c +++ /dev/null @@ -1,864 +0,0 @@ -/* -HTTP Simple Queue Service - httpsqs v1.7 -Author: Zhang Yan (http://blog.s135.com), E-mail: net@s135.com -This is free software, and you are welcome to modify and redistribute it under the New BSD License -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "prename.h" - -#define VERSION "1.7" - -/* 每个队列的默认最大长度为100万条 */ -#define HTTPSQS_DEFAULT_MAXQUEUE 1000000 - -/* 全局设置 */ -TCBDB *httpsqs_db_tcbdb; /* 数据表 */ -int httpsqs_settings_syncinterval; /* 同步更新内容到磁盘的间隔时间 */ -char *httpsqs_settings_pidfile; /* PID文件 */ -char *httpsqs_settings_auth; /* 验证密码 */ - -/* 创建多层目录的函数 */ -void create_multilayer_dir( char *muldir ) -{ - int i,len; - char str[512]; - - strncpy( str, muldir, 512 ); - len=strlen(str); - for( i=0; i0 && access(str, F_OK)!=0 ) - { - mkdir( str, 0777 ); - } - - return; -} - -char *urldecode(char *input_str) -{ - int len = strlen(input_str); - char *str = strdup(input_str); - - char *dest = str; - char *data = str; - - int value; - int c; - - while (len--) { - if (*data == '+') { - *dest = ' '; - } - else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) - && isxdigit((int) *(data + 2))) - { - - c = ((unsigned char *)(data+1))[0]; - if (isupper(c)) - c = tolower(c); - value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; - c = ((unsigned char *)(data+1))[1]; - if (isupper(c)) - c = tolower(c); - value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; - - *dest = (char)value ; - data += 2; - len -= 2; - } else { - *dest = *data; - } - data++; - dest++; - } - *dest = '\0'; - return str; -} - -/* 读取队列写入点的值 */ -static int httpsqs_read_putpos(const char* httpsqs_input_name) -{ - int queue_value = 0; - char *queue_value_tmp; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - sprintf(queue_name, "%s:%s", httpsqs_input_name, "putpos"); - - queue_value_tmp = tcbdbget2(httpsqs_db_tcbdb, queue_name); - if(queue_value_tmp){ - queue_value = atoi(queue_value_tmp); - free(queue_value_tmp); - } - - return queue_value; -} - -/* 读取队列读取点的值 */ -static int httpsqs_read_getpos(const char* httpsqs_input_name) -{ - int queue_value = 0; - char *queue_value_tmp; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - sprintf(queue_name, "%s:%s", httpsqs_input_name, "getpos"); - - queue_value_tmp = tcbdbget2(httpsqs_db_tcbdb, queue_name); - if(queue_value_tmp){ - queue_value = atoi(queue_value_tmp); - free(queue_value_tmp); - } - - return queue_value; -} - -/* 读取用于设置的最大队列数 */ -static int httpsqs_read_maxqueue(const char* httpsqs_input_name) -{ - int queue_value = 0; - char *queue_value_tmp; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - sprintf(queue_name, "%s:%s", httpsqs_input_name, "maxqueue"); - - queue_value_tmp = tcbdbget2(httpsqs_db_tcbdb, queue_name); - if(queue_value_tmp){ - queue_value = atoi(queue_value_tmp); - free(queue_value_tmp); - } else { - queue_value = HTTPSQS_DEFAULT_MAXQUEUE; /* 默认队列长度 */ - } - - return queue_value; -} - -/* 设置最大的队列数量,返回值为设置的队列数量。如果返回值为0,则表示设置取消(取消原因为:设置的最大的队列数量小于”当前队列写入位置点“和”当前队列读取位置点“,或者”当前队列写入位置点“小于”当前队列的读取位置点) */ -static int httpsqs_maxqueue(const char* httpsqs_input_name, int httpsqs_input_num) -{ - int queue_put_value = 0; - int queue_get_value = 0; - int queue_maxnum_int = 0; - - /* 读取当前队列写入位置点 */ - queue_put_value = httpsqs_read_putpos(httpsqs_input_name); - - /* 读取当前队列读取位置点 */ - queue_get_value = httpsqs_read_getpos(httpsqs_input_name); - - /* 设置最大的队列数量,最小值为10条,最大值为10亿条 */ - queue_maxnum_int = httpsqs_input_num; - - /* 设置的最大的队列数量必须大于等于”当前队列写入位置点“和”当前队列读取位置点“,并且”当前队列写入位置点“必须大于等于”当前队列读取位置点“ */ - if (queue_maxnum_int >= queue_put_value && queue_maxnum_int >= queue_get_value && queue_put_value >= queue_get_value) { - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - char queue_maxnum[16] = {0}; - sprintf(queue_name, "%s:%s", httpsqs_input_name, "maxqueue"); - sprintf(queue_maxnum, "%d", queue_maxnum_int); - tcbdbput2(httpsqs_db_tcbdb, queue_name, queue_maxnum); - - tcbdbsync(httpsqs_db_tcbdb); /* 实时刷新到磁盘 */ - - return queue_maxnum_int; - } - - return 0; -} - -/* 重置队列,0表示重置成功 */ -static int httpsqs_reset(const char* httpsqs_input_name) -{ - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - sprintf(queue_name, "%s:%s", httpsqs_input_name, "putpos"); - tcbdbout2(httpsqs_db_tcbdb, queue_name); - - memset(queue_name, '\0', 300); - sprintf(queue_name, "%s:%s", httpsqs_input_name, "getpos"); - tcbdbout2(httpsqs_db_tcbdb, queue_name); - - memset(queue_name, '\0', 300); - sprintf(queue_name, "%s:%s", httpsqs_input_name, "maxqueue"); - tcbdbout2(httpsqs_db_tcbdb, queue_name); - - tcbdbsync(httpsqs_db_tcbdb); /* 实时刷新到磁盘 */ - - return 0; -} - -/* 查看单条队列内容 */ -char *httpsqs_view(const char* httpsqs_input_name, int pos) -{ - char *queue_value; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - sprintf(queue_name, "%s:%d", httpsqs_input_name, pos); - - queue_value = tcbdbget2(httpsqs_db_tcbdb, queue_name); - - return queue_value; -} - -/* 修改定时更新内存内容到磁盘的间隔时间,返回间隔时间(秒) */ -static int httpsqs_synctime(int httpsqs_input_num) -{ - if (httpsqs_input_num >= 1) { - httpsqs_settings_syncinterval = httpsqs_input_num; - } - return httpsqs_settings_syncinterval; -} - -/* 获取本次“入队列”操作的队列写入点 */ -static int httpsqs_now_putpos(const char* httpsqs_input_name) -{ - int maxqueue_num = 0; - int queue_put_value = 0; - int queue_get_value = 0; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - char queue_input[32] = {0}; - - /* 获取最大队列数量 */ - maxqueue_num = httpsqs_read_maxqueue(httpsqs_input_name); - - /* 读取当前队列写入位置点 */ - queue_put_value = httpsqs_read_putpos(httpsqs_input_name); - - /* 读取当前队列读取位置点 */ - queue_get_value = httpsqs_read_getpos(httpsqs_input_name); - - sprintf(queue_name, "%s:%s", httpsqs_input_name, "putpos"); - - /* 队列写入位置点加1 */ - queue_put_value = queue_put_value + 1; - if (queue_put_value == queue_get_value) { /* 如果队列写入ID+1之后追上队列读取ID,则说明队列已满,返回0,拒绝继续写入 */ - queue_put_value = 0; - } - else if (queue_get_value <= 1 && queue_put_value > maxqueue_num) { /* 如果队列写入ID大于最大队列数量,并且从未进行过出队列操作(=0)或进行过1次出队列操作(=1),返回0,拒绝继续写入 */ - queue_put_value = 0; - } - else if (queue_put_value > maxqueue_num) { /* 如果队列写入ID大于最大队列数量,则重置队列写入位置点的值为1 */ - if(tcbdbput2(httpsqs_db_tcbdb, queue_name, "1")) { - queue_put_value = 1; - } - } else { /* 队列写入位置点加1后的值,回写入数据库 */ - sprintf(queue_input, "%d", queue_put_value); - tcbdbput2(httpsqs_db_tcbdb, queue_name, (char *)queue_input); - } - - return queue_put_value; -} - -/* 获取本次“出队列”操作的队列读取点,返回值为0时队列全部读取完成 */ -static int httpsqs_now_getpos(const char* httpsqs_input_name) -{ - int maxqueue_num = 0; - int queue_put_value = 0; - int queue_get_value = 0; - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - - /* 获取最大队列数量 */ - maxqueue_num = httpsqs_read_maxqueue(httpsqs_input_name); - - /* 读取当前队列写入位置点 */ - queue_put_value = httpsqs_read_putpos(httpsqs_input_name); - - /* 读取当前队列读取位置点 */ - queue_get_value = httpsqs_read_getpos(httpsqs_input_name); - - /* 如果queue_get_value的值不存在,重置队列读取位置点为1 */ - sprintf(queue_name, "%s:%s", httpsqs_input_name, "getpos"); - /* 如果queue_get_value的值不存在,重置为1 */ - if (queue_get_value == 0 && queue_put_value > 0) { - queue_get_value = 1; - tcbdbput2(httpsqs_db_tcbdb, queue_name, "1"); - /* 如果队列的读取值(出队列)小于队列的写入值(入队列) */ - } else if (queue_get_value < queue_put_value) { - queue_get_value = queue_get_value + 1; - char queue_input[32] = {0}; - sprintf(queue_input, "%d", queue_get_value); - tcbdbput2(httpsqs_db_tcbdb, queue_name, queue_input); - /* 如果队列的读取值(出队列)大于队列的写入值(入队列),并且队列的读取值(出队列)小于最大队列数量 */ - } else if (queue_get_value > queue_put_value && queue_get_value < maxqueue_num) { - queue_get_value = queue_get_value + 1; - char queue_input[32] = {0}; - sprintf(queue_input, "%d", queue_get_value); - tcbdbput2(httpsqs_db_tcbdb, queue_name, queue_input); - /* 如果队列的读取值(出队列)大于队列的写入值(入队列),并且队列的读取值(出队列)等于最大队列数量 */ - } else if (queue_get_value > queue_put_value && queue_get_value == maxqueue_num) { - queue_get_value = 1; - tcbdbput2(httpsqs_db_tcbdb, queue_name, "1"); - /* 队列的读取值(出队列)等于队列的写入值(入队列),即队列中的数据已全部读出 */ - } else { - queue_get_value = 0; - } - - return queue_get_value; -} - -/* 处理模块 */ -void httpsqs_handler(struct evhttp_request *req, void *arg) -{ - struct evbuffer *buf; - buf = evbuffer_new(); - - /* 分析URL参数 */ - const char *httpsqs_query_part; - struct evkeyvalq httpsqs_http_query; - httpsqs_query_part = evhttp_uri_get_query(req->uri_elems); - evhttp_parse_query_str(httpsqs_query_part, &httpsqs_http_query); - - /* 接收GET表单参数 */ - const char *httpsqs_input_auth = evhttp_find_header (&httpsqs_http_query, "auth"); /* 队列名称 */ - const char *httpsqs_input_name = evhttp_find_header (&httpsqs_http_query, "name"); /* 队列名称 */ - const char *httpsqs_input_charset = evhttp_find_header (&httpsqs_http_query, "charset"); /* 操作类别 */ - const char *httpsqs_input_opt = evhttp_find_header (&httpsqs_http_query, "opt"); /* 操作类别 */ - const char *httpsqs_input_data = evhttp_find_header (&httpsqs_http_query, "data"); /* 操作类别 */ - const char *httpsqs_input_pos_tmp = evhttp_find_header (&httpsqs_http_query, "pos"); /* 队列位置点 字符型 */ - const char *httpsqs_input_num_tmp = evhttp_find_header (&httpsqs_http_query, "num"); /* 队列总长度 字符型 */ - int httpsqs_input_pos = 0; - int httpsqs_input_num = 0; - - /* 返回给用户的Header头信息 */ - if (httpsqs_input_charset != NULL && strlen(httpsqs_input_charset) <= 40) { - char content_type[64] = {0}; - sprintf(content_type, "text/plain; charset=%s", httpsqs_input_charset); - evhttp_add_header(req->output_headers, "Content-Type", content_type); - } else { - evhttp_add_header(req->output_headers, "Content-Type", "text/plain"); - } - evhttp_add_header(req->output_headers, "Connection", "keep-alive"); - evhttp_add_header(req->output_headers, "Cache-Control", "no-cache"); - //evhttp_add_header(req->output_headers, "Connection", "close"); - - /* 权限校验 */ - bool is_auth_pass = false; /* 是否验证通过 */ - if (httpsqs_settings_auth != NULL) { - /* 如果命令行启动参数设置了验证密码 */ - if (httpsqs_input_auth != NULL && strcmp(httpsqs_settings_auth, httpsqs_input_auth) == 0) { - is_auth_pass = true; - } else { - is_auth_pass = false; - } - } else { - /* 如果命令行启动参数没有设置验证密码 */ - is_auth_pass = true; - } - - if (is_auth_pass == false) { - /* 校验失败 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_AUTH_FAILED"); - } - else - { - /* 校验成功,或者命令行启动参数没有设置校验密码 */ - if (httpsqs_input_pos_tmp != NULL) { - httpsqs_input_pos = atoi(httpsqs_input_pos_tmp); /* 队列位置点 数值型 */ - } - if (httpsqs_input_num_tmp != NULL) { - httpsqs_input_num = atoi(httpsqs_input_num_tmp); /* 队列总长度 数值型 */ - } - - /*参数是否存在判断 */ - if (httpsqs_input_name != NULL && httpsqs_input_opt != NULL && strlen(httpsqs_input_name) <= 256) { - /* 入队列 */ - if (strcmp(httpsqs_input_opt, "put") == 0) { - /* 优先接收POST正文信息 */ - int buffer_data_len; - buffer_data_len = EVBUFFER_LENGTH(req->input_buffer); - if (buffer_data_len > 0) { - int queue_put_value = httpsqs_now_putpos((char *)httpsqs_input_name); - if (queue_put_value > 0) { - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - sprintf(queue_name, "%s:%d", httpsqs_input_name, queue_put_value); - char *httpsqs_input_postbuffer; - char *buffer_data = (char *)tccalloc(1, buffer_data_len + 1); - memcpy (buffer_data, EVBUFFER_DATA(req->input_buffer), buffer_data_len); - httpsqs_input_postbuffer = urldecode(buffer_data); - tcbdbput2(httpsqs_db_tcbdb, queue_name, httpsqs_input_postbuffer); - memset(queue_name, '\0', 300); - sprintf(queue_name, "%d", queue_put_value); - evhttp_add_header(req->output_headers, "Pos", queue_name); - evbuffer_add_printf(buf, "%s", "HTTPSQS_PUT_OK"); - free(httpsqs_input_postbuffer); - free(buffer_data); - } else { - evbuffer_add_printf(buf, "%s", "HTTPSQS_PUT_END"); - } - /* 如果POST正文无内容,则取URL中data参数的值 */ - } else if (httpsqs_input_data != NULL) { - int queue_put_value = httpsqs_now_putpos((char *)httpsqs_input_name); - if (queue_put_value > 0) { - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - sprintf(queue_name, "%s:%d", httpsqs_input_name, queue_put_value); - buffer_data_len = strlen(httpsqs_input_data); - char *httpsqs_input_postbuffer; - char *buffer_data = (char *)tccalloc(1, buffer_data_len + 1); - memcpy (buffer_data, httpsqs_input_data, buffer_data_len); - httpsqs_input_postbuffer = urldecode(buffer_data); - tcbdbput2(httpsqs_db_tcbdb, queue_name, httpsqs_input_postbuffer); - memset(queue_name, '\0', 300); - sprintf(queue_name, "%d", queue_put_value); - evhttp_add_header(req->output_headers, "Pos", queue_name); - evbuffer_add_printf(buf, "%s", "HTTPSQS_PUT_OK"); - free(httpsqs_input_postbuffer); - free(buffer_data); - } else { - evbuffer_add_printf(buf, "%s", "HTTPSQS_PUT_END"); - } - } else { - evbuffer_add_printf(buf, "%s", "HTTPSQS_PUT_ERROR"); - } - } - /* 出队列 */ - else if (strcmp(httpsqs_input_opt, "get") == 0) { - int queue_get_value = 0; - queue_get_value = httpsqs_now_getpos((char *)httpsqs_input_name); - if (queue_get_value == 0) { - evbuffer_add_printf(buf, "%s", "HTTPSQS_GET_END"); - } else { - char queue_name[300] = {0}; /* 队列名称的总长度,用户输入的队列长度少于256字节 */ - sprintf(queue_name, "%s:%d", httpsqs_input_name, queue_get_value); - char *httpsqs_output_value; - httpsqs_output_value = tcbdbget2(httpsqs_db_tcbdb, queue_name); - if (httpsqs_output_value) { - memset(queue_name, '\0', 300); - sprintf(queue_name, "%d", queue_get_value); - evhttp_add_header(req->output_headers, "Pos", queue_name); - evbuffer_add_printf(buf, "%s", httpsqs_output_value); - free(httpsqs_output_value); - } else { - evbuffer_add_printf(buf, "%s", "HTTPSQS_GET_END"); - } - } - } - /* 查看队列状态(普通浏览方式) */ - else if (strcmp(httpsqs_input_opt, "status") == 0) { - int maxqueue = httpsqs_read_maxqueue((char *)httpsqs_input_name); /* 最大队列数量 */ - int putpos = httpsqs_read_putpos((char *)httpsqs_input_name); /* 入队列写入位置 */ - int getpos = httpsqs_read_getpos((char *)httpsqs_input_name); /* 出队列读取位置 */ - int ungetnum; - const char *put_times; - const char *get_times; - if (putpos >= getpos) { - ungetnum = abs(putpos - getpos); /* 尚未出队列条数 */ - put_times = "1st lap"; - get_times = "1st lap"; - } else if (putpos < getpos) { - ungetnum = abs(maxqueue - getpos + putpos); /* 尚未出队列条数 */ - put_times = "2nd lap"; - get_times = "1st lap"; - } - evbuffer_add_printf(buf, "HTTP Simple Queue Service v%s\n", VERSION); - evbuffer_add_printf(buf, "------------------------------\n"); - evbuffer_add_printf(buf, "Queue Name: %s\n", httpsqs_input_name); - evbuffer_add_printf(buf, "Maximum number of queues: %d\n", maxqueue); - evbuffer_add_printf(buf, "Put position of queue (%s): %d\n", put_times, putpos); - evbuffer_add_printf(buf, "Get position of queue (%s): %d\n", get_times, getpos); - evbuffer_add_printf(buf, "Number of unread queue: %d\n", ungetnum); - } - /* 查看队列状态(JSON方式,方便客服端程序处理) */ - else if (strcmp(httpsqs_input_opt, "status_json") == 0) { - int maxqueue = httpsqs_read_maxqueue((char *)httpsqs_input_name); /* 最大队列数量 */ - int putpos = httpsqs_read_putpos((char *)httpsqs_input_name); /* 入队列写入位置 */ - int getpos = httpsqs_read_getpos((char *)httpsqs_input_name); /* 出队列读取位置 */ - int ungetnum; - const char *put_times; - const char *get_times; - if (putpos >= getpos) { - ungetnum = abs(putpos - getpos); /* 尚未出队列条数 */ - put_times = "1"; - get_times = "1"; - } else if (putpos < getpos) { - ungetnum = abs(maxqueue - getpos + putpos); /* 尚未出队列条数 */ - put_times = "2"; - get_times = "1"; - } - evbuffer_add_printf(buf, "{\"name\":\"%s\",\"maxqueue\":%d,\"putpos\":%d,\"putlap\":%s,\"getpos\":%d,\"getlap\":%s,\"unread\":%d}\n", httpsqs_input_name, maxqueue, putpos, put_times, getpos, get_times, ungetnum); - } - /* 查看单条队列内容 */ - else if (strcmp(httpsqs_input_opt, "view") == 0 && httpsqs_input_pos >= 1 && httpsqs_input_pos <= 1000000000) { - char *httpsqs_output_value; - httpsqs_output_value = httpsqs_view ((char *)httpsqs_input_name, httpsqs_input_pos); - if (httpsqs_output_value) { - evbuffer_add_printf(buf, "%s", httpsqs_output_value); - free(httpsqs_output_value); - } - } - /* 重置队列 */ - else if (strcmp(httpsqs_input_opt, "reset") == 0) { - int reset = httpsqs_reset((char *)httpsqs_input_name); - if (reset == 0) { - evbuffer_add_printf(buf, "%s", "HTTPSQS_RESET_OK"); - } else { - evbuffer_add_printf(buf, "%s", "HTTPSQS_RESET_ERROR"); - } - } - /* 设置最大的队列数量,最小值为10条,最大值为10亿条 */ - else if (strcmp(httpsqs_input_opt, "maxqueue") == 0 && httpsqs_input_num >= 10 && httpsqs_input_num <= 1000000000) { - if (httpsqs_maxqueue((char *)httpsqs_input_name, httpsqs_input_num) != 0) { - /* 设置成功 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_MAXQUEUE_OK"); - } else { - /* 设置取消 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_MAXQUEUE_CANCEL"); - } - } - /* 设置定时更新内存内容到磁盘的间隔时间,最小值为1秒,最大值为10亿秒 */ - else if (strcmp(httpsqs_input_opt, "synctime") == 0 && httpsqs_input_num >= 1 && httpsqs_input_num <= 1000000000) { - if (httpsqs_synctime(httpsqs_input_num) >= 1) { - /* 设置成功 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_SYNCTIME_OK"); - } else { - /* 设置取消 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_SYNCTIME_CANCEL"); - } - } else { - /* 命令错误 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_ERROR"); - } - } else { - /* 命令错误 */ - evbuffer_add_printf(buf, "%s", "HTTPSQS_ERROR"); - } - } - - /* 输出内容给客户端 */ - evhttp_send_reply(req, HTTP_OK, "OK", buf); - - /* 内存释放 */ - evhttp_clear_headers(&httpsqs_http_query); - evbuffer_free(buf); -} - -/* 子进程信号处理 */ -static void kill_signal_worker(const int sig) { - /* 同步内存数据到磁盘,并关闭数据库 */ - tcbdbsync(httpsqs_db_tcbdb); - tcbdbclose(httpsqs_db_tcbdb); - tcbdbdel(httpsqs_db_tcbdb); - - exit(0); -} - -/* 父进程信号处理 */ -static void kill_signal_master(const int sig) { - /* 删除PID文件 */ - remove(httpsqs_settings_pidfile); - - /* 给进程组发送SIGTERM信号,结束子进程 */ - kill(0, SIGTERM); - - exit(0); -} - -/* 定时同步线程,定时将内存中的内容写入磁盘 */ -static void sync_worker(const int sig) { - pthread_detach(pthread_self()); - - while(1) - { - /* 间隔httpsqs_settings_syncinterval秒同步一次数据到磁盘 */ - sleep(httpsqs_settings_syncinterval); - - /* 同步内存数据到磁盘 */ - tcbdbsync(httpsqs_db_tcbdb); - } -} - -static void show_help(void) -{ - char *b = "--------------------------------------------------------------------------------------------------\n" - "HTTP Simple Queue Service - httpsqs v" VERSION " (April 14, 2011)\n\n" - "Author: Zhang Yan (http://blog.s135.com), E-mail: net@s135.com\n" - "This is free software, and you are welcome to modify and redistribute it under the New BSD License\n" - "\n" - "-l interface to listen on, default is 0.0.0.0\n" - "-p TCP port number to listen on (default: 1218)\n" - "-x database directory (example: /opt/httpsqs/data)\n" - "-t keep-alive timeout for an http request (default: 60)\n" - "-s the interval to sync updated contents to the disk (default: 5)\n" - "-c the maximum number of non-leaf nodes to be cached (default: 1024)\n" - "-m database memory cache size in MB (default: 100)\n" - "-i save PID in (default: /tmp/httpsqs.pid)\n" - "-a the auth password to access httpsqs (example: mypass123)\n" - "-d run as a daemon\n" - "-h print this help and exit\n\n" - "Use command \"killall httpsqs\", \"pkill httpsqs\" and \"kill `cat /tmp/httpsqs.pid`\" to stop httpsqs.\n" - "Please note that don't use the command \"pkill -9 httpsqs\" and \"kill -9 PID of httpsqs\"!\n" - "\n" - "Please visit \"http://code.google.com/p/httpsqs\" for more help information.\n\n" - "--------------------------------------------------------------------------------------------------\n" - "\n"; - fprintf(stderr, b, strlen(b)); -} - -int main(int argc, char *argv[], char *envp[]) -{ - int c; - /* 默认参数设置 */ - char *httpsqs_settings_listen = "0.0.0.0"; - int httpsqs_settings_port = 1218; - char *httpsqs_settings_datapath = NULL; - bool httpsqs_settings_daemon = false; - int httpsqs_settings_timeout = 60; /* 单位:秒 */ - httpsqs_settings_syncinterval = 5; /* 单位:秒 */ - int httpsqs_settings_cachenonleaf = 1024; /* 缓存非叶子节点数。单位:条 */ - int httpsqs_settings_cacheleaf = 2048; /* 缓存叶子节点数。叶子节点缓存数为非叶子节点数的两倍。单位:条 */ - int httpsqs_settings_mappedmemory = 104857600; /* 单位:字节 */ - httpsqs_settings_pidfile = "/tmp/httpsqs.pid"; - httpsqs_settings_auth = NULL; /* 验证密码 */ - - /* 命令行参数,暂时存储下面,便于进程重命名 */ - int httpsqs_prename_num = 1; - char httpsqs_path_file[1024] = { 0 }; // httpsqs_path_file 为 httpsqs 程序的绝对路径 - struct evbuffer *httpsqs_prename_buf; /* 原命令行参数 */ - httpsqs_prename_buf = evbuffer_new(); - readlink("/proc/self/exe", httpsqs_path_file, sizeof(httpsqs_path_file)); - evbuffer_add_printf(httpsqs_prename_buf, "%s", httpsqs_path_file); - for (httpsqs_prename_num = 1; httpsqs_prename_num < argc; httpsqs_prename_num++) { - evbuffer_add_printf(httpsqs_prename_buf, " %s", argv[httpsqs_prename_num]); - } - - /* process arguments */ - while ((c = getopt(argc, argv, "l:p:x:t:s:c:m:i:a:dh")) != -1) { - switch (c) { - case 'l': - httpsqs_settings_listen = strdup(optarg); - break; - case 'p': - httpsqs_settings_port = atoi(optarg); - break; - case 'x': - httpsqs_settings_datapath = strdup(optarg); /* httpsqs数据库文件存放路径 */ - if (access(httpsqs_settings_datapath, W_OK) != 0) { /* 如果目录不可写 */ - if (access(httpsqs_settings_datapath, R_OK) == 0) { /* 如果目录可读 */ - chmod(httpsqs_settings_datapath, S_IWOTH); /* 设置其他用户具可写入权限 */ - } else { /* 如果不存在该目录,则创建 */ - create_multilayer_dir(httpsqs_settings_datapath); - } - - if (access(httpsqs_settings_datapath, W_OK) != 0) { /* 如果目录不可写 */ - fprintf(stderr, "httpsqs database directory not writable\n"); - } - } - break; - case 't': - httpsqs_settings_timeout = atoi(optarg); - break; - case 's': - httpsqs_settings_syncinterval = atoi(optarg); - break; - case 'c': - httpsqs_settings_cachenonleaf = atoi(optarg); - httpsqs_settings_cacheleaf = httpsqs_settings_cachenonleaf * 2; - break; - case 'm': - httpsqs_settings_mappedmemory = atoi(optarg) * 1024 * 1024; /* 单位:M */ - break; - case 'i': - httpsqs_settings_pidfile = strdup(optarg); - break; - case 'a': - httpsqs_settings_auth = strdup(optarg); - break; - case 'd': - httpsqs_settings_daemon = true; - break; - case 'h': - default: - show_help(); - return 1; - } - } - - /* 判断是否加了必填参数 -x */ - if (httpsqs_settings_datapath == NULL) { - show_help(); - fprintf(stderr, "Attention: Please use the indispensable argument: -x \n\n"); - exit(1); - } - - /* 数据表路径 */ - int httpsqs_settings_dataname_len = 1024; - char *httpsqs_settings_dataname = (char *)tccalloc(1, httpsqs_settings_dataname_len); - sprintf(httpsqs_settings_dataname, "%s/httpsqs.db", httpsqs_settings_datapath); - - /* 打开数据表 */ - httpsqs_db_tcbdb = tcbdbnew(); - tcbdbsetmutex(httpsqs_db_tcbdb); /* 开启线程互斥锁 */ - tcbdbtune(httpsqs_db_tcbdb, 1024, 2048, 50000000, 8, 10, BDBTLARGE); - tcbdbsetcache(httpsqs_db_tcbdb, httpsqs_settings_cacheleaf, httpsqs_settings_cachenonleaf); - tcbdbsetxmsiz(httpsqs_db_tcbdb, httpsqs_settings_mappedmemory); /* 内存缓存大小 */ - - /* 判断表是否能打开 */ - if(!tcbdbopen(httpsqs_db_tcbdb, httpsqs_settings_dataname, BDBOWRITER|BDBOCREAT)){ - show_help(); - fprintf(stderr, "Attention: Unable to open the database.\n\n"); - exit(1); - } - - /* 释放变量所占内存 */ - free(httpsqs_settings_dataname); - - /* 如果加了-d参数,以守护进程运行 */ - if (httpsqs_settings_daemon == true) { - pid_t pid; - - /* Fork off the parent process */ - pid = fork(); - if (pid < 0) { - exit(EXIT_FAILURE); - } - /* If we got a good PID, then - we can exit the parent process. */ - if (pid > 0) { - exit(EXIT_SUCCESS); - } - } - - /* 将进程号写入PID文件 */ - FILE *fp_pidfile; - fp_pidfile = fopen(httpsqs_settings_pidfile, "w"); - fprintf(fp_pidfile, "%d\n", getpid()); - fclose(fp_pidfile); - - /* 重命名httpsqs主进程,便于ps -ef命令查看 */ - prename_setproctitle_init(argc, argv, envp); - prename_setproctitle("[httpsqs: master process] %s", (char *)EVBUFFER_DATA(httpsqs_prename_buf)); - - /* 派生httpsqs子进程(工作进程) */ - pid_t httpsqs_worker_pid_wait; - pid_t httpsqs_worker_pid = fork(); - /* 如果派生进程失败,则退出程序 */ - if (httpsqs_worker_pid < 0) - { - fprintf(stderr, "Error: %s:%d\n", __FILE__, __LINE__); - exit(EXIT_FAILURE); - } - /* httpsqs父进程内容 */ - if (httpsqs_worker_pid > 0) - { - /* 处理父进程接收到的kill信号 */ - - /* 忽略Broken Pipe信号 */ - signal(SIGPIPE, SIG_IGN); - - /* 处理kill信号 */ - signal (SIGINT, kill_signal_master); - signal (SIGKILL, kill_signal_master); - signal (SIGQUIT, kill_signal_master); - signal (SIGTERM, kill_signal_master); - signal (SIGHUP, kill_signal_master); - - /* 处理段错误信号 */ - signal(SIGSEGV, kill_signal_master); - - /* 如果子进程终止,则重新派生新的子进程 */ - while (1) - { - httpsqs_worker_pid_wait = wait(NULL); - if (httpsqs_worker_pid_wait < 0) - { - continue; - } - usleep(100000); - httpsqs_worker_pid = fork(); - if (httpsqs_worker_pid == 0) - { - break; - } - } - } - - /* ---------------以下为httpsqs子进程内容------------------- */ - - /* 忽略Broken Pipe信号 */ - signal(SIGPIPE, SIG_IGN); - - /* 处理kill信号 */ - signal (SIGINT, kill_signal_worker); - signal (SIGKILL, kill_signal_worker); - signal (SIGQUIT, kill_signal_worker); - signal (SIGTERM, kill_signal_worker); - signal (SIGHUP, kill_signal_worker); - - /* 处理段错误信号 */ - signal(SIGSEGV, kill_signal_worker); - - /* 创建定时同步线程,定时将内存中的内容写入磁盘 */ - pthread_t sync_worker_tid; - pthread_create(&sync_worker_tid, NULL, (void *) sync_worker, NULL); - - /* 重命名httpsqs子进程,便于ps -ef命令查看 */ - prename_setproctitle_init(argc, argv, envp); - prename_setproctitle("[httpsqs: worker process] %s", (char *)EVBUFFER_DATA(httpsqs_prename_buf)); - evbuffer_free(httpsqs_prename_buf); - - /* 请求处理部分 */ - struct evhttp *httpd; - - event_init(); - httpd = evhttp_start(httpsqs_settings_listen, httpsqs_settings_port); - if (httpd == NULL) { - fprintf(stderr, "Error: Unable to listen on %s:%d\n\n", httpsqs_settings_listen, httpsqs_settings_port); - kill(0, SIGTERM); - exit(1); - } - evhttp_set_timeout(httpd, httpsqs_settings_timeout); - - /* Set a callback for requests to "/specific". */ - /* evhttp_set_cb(httpd, "/select", select_handler, NULL); */ - - /* Set a callback for all other requests. */ - evhttp_set_gencb(httpd, httpsqs_handler, NULL); - - event_dispatch(); - - /* Not reached in this code as it is now. */ - evhttp_free(httpd); - - return 0; -} diff --git a/prename.c b/prename.c deleted file mode 100644 index 33a07a4..0000000 --- a/prename.c +++ /dev/null @@ -1,87 +0,0 @@ -/* -ڽ̡ӽʹòͬps -ef鿴 -*/ - -#include -#include -#include -#include -#include - -# define MAXLINE 2048 - -#ifdef Linux - #include -#endif - -extern char **environ; - -static char **g_main_Argv = NULL; /* pointer to argument vector */ -static char *g_main_LastArgv = NULL; /* end of argv */ - -void prename_setproctitle_init(int argc, char **argv, char **envp) -{ - int i; - - for (i = 0; envp[i] != NULL; i++) - continue; - environ = (char **) malloc(sizeof (char *) * (i + 1)); - for (i = 0; envp[i] != NULL; i++) - environ[i] = strdup(envp[i]);//xstrdup(envp[i]); - environ[i] = NULL; - - g_main_Argv = argv; - if (i > 0) - g_main_LastArgv = envp[i - 1] + strlen(envp[i - 1]); - else - g_main_LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); -} - -void prename_setproctitle(const char *fmt, ...) -{ - char *p; - int i; - char buf[MAXLINE]; - - extern char **g_main_Argv; - extern char *g_main_LastArgv; - va_list ap; - p = buf; - - va_start(ap, fmt); - vsprintf(p, fmt, ap); - va_end(ap); - - - i = strlen(buf); - - if (i > g_main_LastArgv - g_main_Argv[0] - 2) - { - i = g_main_LastArgv - g_main_Argv[0] - 2; - buf[i] = '\0'; - } - (void) strcpy(g_main_Argv[0], buf); - p = &g_main_Argv[0][i]; - while (p < g_main_LastArgv) - *p++ = '\0';//SPT_PADCHAR; - g_main_Argv[1] = NULL; - -#ifdef Linux - prctl(PR_SET_NAME,buf); -#endif - -} - -/* -int main(int argc, char *argv[], char *envp[]) -{ - prename_setproctitle_init(argc, argv, envp); - - prename_setproctitle("%s@%s", "test_very_long_user_name_in_process_name", "192.168.123.145"); - - while(1) - sleep(10); - - return 0; -} -*/ diff --git a/prename.h b/prename.h deleted file mode 100644 index 38ef903..0000000 --- a/prename.h +++ /dev/null @@ -1,2 +0,0 @@ -extern void prename_setproctitle_init(int argc, char **argv, char **envp); -extern void prename_setproctitle(const char *fmt, ...);