예제
본 장에서는 C 언어용 클라이언트, 서버와 JAVA 언어용 클라이언트 예제를 설명한다.
1. 클라이언트
각 함수를 모두 사용하는 예제이다.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <usrinc/tmaxapi.h> void tperror(char *msg) { printf("%s error, [%d:%s]\n", msg, tperrno, tpstrerror(tperrno)); exit(1); } void tgerror(char *msg) { printf("%s error, [%d:%s]\n", msg, tgerrno, tgstrerror(tgerrno)); exit(1); } int my_callback_func(char *key, int keylen, int event_type, void *args) { if (event_type & TG_EVENT_DELETE_CHILD) printf("callback key(%*s) received TG_EVENT_DELETE_CHILD event\n",keylen, key, event_type); if (event_type & TG_EVENT_DELETE_SELF) printf("callback key(%*s) received TG_EVENT_DELETE_SELF event\n",keylen, key, event_type); if (event_type & TG_EVENT_CREATE_CHILD) printf("callback key(%*s) received TG_EVENT_CREATE_CHILD event\n",keylen, key, event_type); if (event_type & TG_EVENT_SET_SELF) printf("callback key(%*s) received TG_EVENT_SET_SELF event\n",keylen, key, event_type,(char*)args); if (event_type & TG_EVENT_GET_SELF) printf("callback key(%*s) received TG_EVENT_GET_SELF event\n",keylen, key, event_type); if (event_type & TG_EVENT_LOCK) printf("callback key(%*s) received TG_EVENT_LOCK event\n",keylen, key, event_type); if (event_type & TG_EVENT_RECOVERED) printf("callback key(%*s) received TG_EVENT_RECOVERED event\n",keylen, key, event_type); return 0; } int main(int argc, char *argv[]) { TG_WATHCER_CALLBACK callback; TPSTART_T *start; char *sndbuf, *rcvbuf, sndbuf2[1024], rcvbuf2[1024]; int sndlen, rcvlen; char *key, *key1,*lock_key, *queue_key, *parent_key; int keylen,keylen1, lock_keylen, queue_keylen, parent_keylen; int nth, count, timeout; TG_KEYLIST_T keylist; TG_KEYINFO_T keyinfo; tg_bulk_handler_t *lptr; tg_key_browser_t *browser; int type; if (tmaxreadenv("tmax.env", "TMAX") < 0) tperror("tmaxreadenv"); start = (TPSTART_T*)tpalloc("TPSTART", NULL, 0); if (start == NULL) tperror("tpalloc"); if (tpstart(start) < 0) tperror("tpstart"); key = "/keytest/mee"; key1 = "/key1/message"; keylen = strlen(key); keylen1 = strlen(key1); lock_key = "/key/lock"; lock_keylen = strlen(lock_key); queue_key = "/data01"; queue_keylen = strlen(queue_key); parent_key = "/key/message"; //parent_key = "/key11"; parent_keylen = strlen(parent_key); /* tmax_grid_create */ if (tmax_grid_create(key, keylen, TG_TEMPORARY) < 0) tgerror("tmax_grid_create"); if (tmax_grid_create(key1, keylen1, TG_TEMPORARY) < 0) tgerror("tmax_grid_create"); #if _CASE1 /* tmax_grid_is_exist */ if (tmax_grid_is_exist(key, keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_is_exis(%s) exist\n",key); if (tmax_grid_is_exist(key1, keylen1, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_is_exis(%s) exist\n",key1); /* tmax_grid_set_watcher */ callback = my_callback_func; if (tmax_grid_set_watcher(key, keylen, callback, NULL, (TG_WATCHER_PERSISTENT | TG_EVENT_SET_SELF)) < 0) tgerror("tmax_grid_set_watcher"); printf("tmax_grid_set_watcher(%s) ok!\n",key); #endif #if _CASE2 /* tmax_grid_set */ if ((sndbuf = tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "get pid(%d) data(%s)", getpid(),argv[0]); if (tmax_grid_set(key, keylen, 0, sndbuf, sndlen, TG_NOFLAGS) < 0){ tgerror("tmax_grid_set key"); tpfree(sndbuf); } /* tmax_grid_get */ if ((rcvbuf =tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc rcvbuf"); if(tmax_grid_get(key, keylen, &type , &rcvbuf, &rcvlen, TG_GET_PEEK) < 0){ tgerror("tmax_grid_get"); tpfree(rcvbuf); tpfree(sndbuf); exit(1); } printf("recv data = [%s] len= [%d]\n", rcvbuf,rcvlen); tpfree(sndbuf); tpfree(rcvbuf); #endif #if _CASE3 /* tmax_grid_set */ sndlen = sprintf(sndbuf2, "get2 pid(%d) data(%s)", getpid(),argv[0]); if (tmax_grid_set(key1, keylen1,TMAX_GRID_STRING , (void *)sndbuf2, sndlen, TG_NOFLAGS) < 0){ tgerror("tmax_grid_set key1"); } /* tmax_grid_get2 */ type = TMAX_GRID_STRING; if (tmax_grid_get2(key1, keylen1, &type, &rcvbuf2, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_get2"); printf("recv data = [%s] len= [%d]\n", rcvbuf2,rcvlen); #endif #if _CASE4 if (tmax_grid_create(lock_key, lock_keylen, TG_LOCK) < 0) tgerror("tmax_grid_create"); /* grid lock set */ printf("lock exist\n"); if (tmax_grid_is_exist(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_lock\n"); /* tmax_grid_lock */ if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_SHARED_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); /*if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_EXCLUSIVE_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); */ system("echo tgli |tmadmin"); /* tmax_grid_unlock */ if (tmax_grid_unlock(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_unlock"); printf("tmax_grid_unlock ok key[%s]!!\n",lock_key); sleep(1); system("echo tgli |tmadmin"); if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_EXCLUSIVE_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); system("echo tgli |tmadmin"); /* tmax_grid_unlock */ if (tmax_grid_unlock(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_unlock"); printf("tmax_grid_unlock ok key[%s]!!\n",lock_key); sleep(1); system("echo tgli |tmadmin"); #endif #if CASE5 if (tmax_grid_create(queue_key, queue_keylen, TG_QUEUE) < 0) tgerror("tmax_grid_create"); /* tmax_grid_dequeue */ if ((sndbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "pid(%d) date()", getpid()); type = TMAX_GRID_STRING; if (tmax_grid_enqueue(queue_key, queue_keylen,0, sndbuf, sndlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_enqueue"); if ((rcvbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc rcvbuf"); type=TMAX_GRID_STRING; if (tmax_grid_dequeue(queue_key, queue_keylen, &type, &rcvbuf, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_dequeue"); printf("tmax_grid_dequeue recv data = [%s]\n", rcvbuf); tpfree(sndbuf); tpfree(rcvbuf); /* tmax_grid_dequeue2*/ sndlen = sprintf(sndbuf2, "get2 pid(%d) ", getpid()); if (tmax_grid_enqueue(queue_key, queue_keylen,TMAX_GRID_STRING, (void *)sndbuf2, sndlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_enqueue"); type=TMAX_GRID_STRING; if (tmax_grid_dequeue2(queue_key, queue_keylen, &type, &rcvbuf2, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_dequeue"); printf("tmax_grid_dequeue2 recv data = [%s]\n", rcvbuf2); #endif #if _CASE6 if (tmax_grid_create(parent_key, parent_keylen, TG_PERSISTENT) < 0) tgerror("tmax_grid_create"); /* tmax_grid_get_children */ keylist = tmax_grid_get_children(parent_key, parent_keylen, &count); if (keylist == NULL) tgerror("tmax_grid_get_children"); for (nth = 0; nth < count; nth++) { if (tmax_grid_get_child_with_index(keylist, nth, &keyinfo) == -1) break; printf("nth(%d) key(%*s) datalen(%d)\n", nth, keyinfo.keylen, keyinfo.key, keyinfo.datalen); } tmax_grid_keylist_free(keylist); printf("keylist_free = [%s]\n",parent_key); system("echo tgi|tmadmin"); printf("destroy children [%s]\n\n",parent_key); if (tmax_grid_destroy(parent_key, parent_keylen, TG_CHILDREN) < 0) tgerror("tmax_grid_destroy"); sleep(1); system("echo tgi|tmadmin"); #endif #if _CASE7 printf("tg_bulk_handler_t\n"); lptr=(tg_bulk_handler_t *)malloc(sizeof(tg_bulk_handler_t)); printf("tg_bulk_handler init\n"); if(tmax_grid_init_bulk_handle(lptr)<0) tgerror("tmax_grid_init_bulk_handle"); if ((sndbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "(%d) date()", getpid()); printf("grig_set_bulk_handle\n"); if(tmax_grid_set_bulk_handle(lptr,key,strlen(key), -1,0,sndbuf,sndlen)<0) tgerror("tmax_grid_set_bulk_handle"); sndlen = sprintf(sndbuf2, "13(%d) ", getpid()); type=TMAX_GRID_STRING; printf("grig_set_bulk_handle\n"); if(tmax_grid_set_bulk_handle(lptr,key1,strlen(key1),type,0,(void *)sndbuf2,sndlen)<0) tgerror("tmax_grid_set_bulk_handle"); printf(" bulk count = %d \n",lptr->count); printf("grig_set_bulk\n"); if(tmax_grid_bulk_set(lptr,0)<0) tgerror("tmax_grid_bulk_set"); if(tmax_grid_bulk_get(lptr,0)<0) tgerror("tmax_grid_bulk_get"); printf("get bulk data = %s , key = %s \n",lptr->tail->data, lptr->tail->key); system("\necho tgi | tmadmin"); #endif #if _CASE8 browser=(tg_key_browser_t *)malloc(sizeof(tg_key_browser_t)); tmax_grid_init_key_browser(browser,key,strlen(key)); rcvlen=tmax_grid_get_next(browser,0); printf("browser keylen = %d \n",rcvlen); printf("start_key = %s , start_key_len =%d\n", browser->start_key,browser->start_key_len); printf("next_key = %s , next_key_len =%d\n", browser->next_key,browser->next_key_len); count=tmax_grid_count(0); printf("tmax_grid conut = %d \n",count); system("\necho tgi | tmadmin"); #endif tpend(); return 0; }
2. 서버
TmaxGridTEST란 서비스가 호출되면 각 TmaxGrid API를 호출해 보는 예제이다.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <usrinc/tmaxapi.h> void tperror(char *msg) { printf("%s error, [%d:%s]\n", msg, tperrno, tpstrerror(tperrno)); tpreturn(TPFAIL, tperrno, NULL, 0, TPNOFLAGS); } void tgerror(char *msg) { printf("%s error, [%d:%s]\n", msg, tgerrno, tgstrerror(tgerrno)); tpreturn(TPFAIL, tgerrno, NULL, 0, TPNOFLAGS); } int my_callback_func(char *key, int keylen, int event_type, void *args) { if (event_type & TG_EVENT_DELETE_CHILD) printf("callback key(%.*s) received TG_EVENT_DELETE_CHILD event\n", keylen, key, event_type); if (event_type & TG_EVENT_DELETE_SELF) printf("callback key(%.*s) received TG_EVENT_DELETE_SELF event\n", keylen, key, event_type); if (event_type & TG_EVENT_CREATE_CHILD) printf("callback key(%.*s) received TG_EVENT_CREATE_CHILD event\n", keylen, key, event_type); if (event_type & TG_EVENT_SET_SELF) printf("callback key(%.*s) received TG_EVENT_SET_SELF event\n", keylen, key, event_type); if (event_type & TG_EVENT_GET_SELF) printf("callback key(%.*s) received TG_EVENT_GET_SELF event\n", keylen, key, event_type); if (event_type & TG_EVENT_LOCK) printf("callback key(%.*s) received TG_EVENT_LOCK event\n", keylen, key, event_type); if (event_type & TG_EVENT_RECOVERED) printf("callback key(%.*s) received TG_EVENT_RECOVERED event\n", keylen, key, event_type); return 0; } TmaxGridTEST(TPSVCINFO *msg) { T TG_WATHCER_CALLBACK callback; TPSTART_T *start; char *sndbuf, *rcvbuf, sndbuf2[1024], rcvbuf2[1024]; int sndlen, rcvlen; char *key, *key1,*lock_key, *queue_key, *parent_key; int keylen,keylen1, lock_keylen, queue_keylen, parent_keylen; int nth, count, timeout; TG_KEYLIST_T keylist; TG_KEYINFO_T keyinfo; tg_bulk_handler_t *lptr; tg_key_browser_t *browser; int type; if (tmaxreadenv("tmax.env", "TMAX") < 0) tperror("tmaxreadenv"); start = (TPSTART_T*)tpalloc("TPSTART", NULL, 0); if (start == NULL) tperror("tpalloc"); if (tpstart(start) < 0) tperror("tpstart"); key = "/keytest/mee"; key1 = "/key1/message"; keylen = strlen(key); keylen1 = strlen(key1); lock_key = "/key/lock"; lock_keylen = strlen(lock_key); queue_key = "/data01"; queue_keylen = strlen(queue_key); parent_key = "/key/message"; //parent_key = "/key11"; parent_keylen = strlen(parent_key); /* tmax_grid_create */ if (tmax_grid_create(key, keylen, TG_TEMPORARY) < 0) tgerror("tmax_grid_create"); if (tmax_grid_create(key1, keylen1, TG_TEMPORARY) < 0) tgerror("tmax_grid_create"); #if _CASE1 /* tmax_grid_is_exist */ if (tmax_grid_is_exist(key, keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_is_exis(%s) exist\n",key); if (tmax_grid_is_exist(key1, keylen1, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_is_exis(%s) exist\n",key1); /* tmax_grid_set_watcher */ callback = my_callback_func; if (tmax_grid_set_watcher(key, keylen, callback, NULL, (TG_WATCHER_PERSISTENT | TG_EVENT_SET_SELF)) < 0) tgerror("tmax_grid_set_watcher"); printf("tmax_grid_set_watcher(%s) ok!\n",key); #endif #if _CASE2 /* tmax_grid_set */ if ((sndbuf = tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "get pid(%d) data(%s)", getpid(),argv[0]); if (tmax_grid_set(key, keylen, 0, sndbuf, sndlen, TG_NOFLAGS) < 0){ tgerror("tmax_grid_set key"); tpfree(sndbuf); } /* tmax_grid_get */ if ((rcvbuf =tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc rcvbuf"); if(tmax_grid_get(key, keylen, &type , &rcvbuf, &rcvlen, TG_GET_PEEK) < 0){ tgerror("tmax_grid_get"); tpfree(rcvbuf); tpfree(sndbuf); exit(1); } printf("recv data = [%s] len= [%d]\n", rcvbuf,rcvlen); tpfree(sndbuf); tpfree(rcvbuf); #endif #if _CASE3 /* tmax_grid_set */ sndlen = sprintf(sndbuf2, "get2 pid(%d) data(%s)", getpid(),argv[0]); if (tmax_grid_set(key1, keylen1,TMAX_GRID_STRING , (void *)sndbuf2, sndlen, TG_NOFLAGS) < 0){ tgerror("tmax_grid_set key1"); } /* tmax_grid_get2 */ type = TMAX_GRID_STRING; if (tmax_grid_get2(key1, keylen1, &type, &rcvbuf2, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_get2"); printf("recv data = [%s] len= [%d]\n", rcvbuf2,rcvlen); #endif #if _CASE4 if (tmax_grid_create(lock_key, lock_keylen, TG_LOCK) < 0) tgerror("tmax_grid_create"); /* grid lock set */ printf("lock exist\n"); if (tmax_grid_is_exist(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_is_exist"); printf("tmax_grid_lock\n"); /* tmax_grid_lock */ if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_SHARED_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); /*if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_EXCLUSIVE_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); */ system("echo tgli |tmadmin"); /* tmax_grid_unlock */ if (tmax_grid_unlock(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_unlock"); printf("tmax_grid_unlock ok key[%s]!!\n",lock_key); sleep(1); system("echo tgli |tmadmin"); if (tmax_grid_lock(lock_key, lock_keylen, timeout, TG_EXCLUSIVE_LOCK) < 0) tgerror("tmax_grid_lock"); printf("tmax_grid_lock ok key[%s]!!\n",lock_key); system("echo tgli |tmadmin"); /* tmax_grid_unlock */ if (tmax_grid_unlock(lock_key, lock_keylen, TG_NOFLAGS) < 0) tgerror("tmax_grid_unlock"); printf("tmax_grid_unlock ok key[%s]!!\n",lock_key); sleep(1); system("echo tgli |tmadmin"); #endif #if CASE5 if (tmax_grid_create(queue_key, queue_keylen, TG_QUEUE) < 0) tgerror("tmax_grid_create"); /* tmax_grid_dequeue */ if ((sndbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "pid(%d) date()", getpid()); type = TMAX_GRID_STRING; if (tmax_grid_enqueue(queue_key, queue_keylen,0, sndbuf, sndlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_enqueue"); if ((rcvbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc rcvbuf"); type=TMAX_GRID_STRING; if (tmax_grid_dequeue(queue_key, queue_keylen, &type, &rcvbuf, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_dequeue"); printf("tmax_grid_dequeue recv data = [%s]\n", rcvbuf); tpfree(sndbuf); tpfree(rcvbuf); /* tmax_grid_dequeue2*/ sndlen = sprintf(sndbuf2, "get2 pid(%d) ", getpid()); if (tmax_grid_enqueue(queue_key, queue_keylen,TMAX_GRID_STRING, (void *)sndbuf2, sndlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_enqueue"); type=TMAX_GRID_STRING; if (tmax_grid_dequeue2(queue_key, queue_keylen, &type, &rcvbuf2, &rcvlen, TG_NOFLAGS) < 0) tgerror("tmax_grid_dequeue"); printf("tmax_grid_dequeue2 recv data = [%s]\n", rcvbuf2); #endif #if _CASE6 if (tmax_grid_create(parent_key, parent_keylen, TG_PERSISTENT) < 0) tgerror("tmax_grid_create"); /* tmax_grid_get_children */ keylist = tmax_grid_get_children(parent_key, parent_keylen, &count); if (keylist == NULL) tgerror("tmax_grid_get_children"); for (nth = 0; nth < count; nth++) { if (tmax_grid_get_child_with_index(keylist, nth, &keyinfo) == -1) break; printf("nth(%d) key(%*s) datalen(%d)\n", nth, keyinfo.keylen, keyinfo.key, keyinfo.datalen); } tmax_grid_keylist_free(keylist); printf("keylist_free = [%s]\n",parent_key); system("echo tgi|tmadmin"); printf("destroy children [%s]\n\n",parent_key); if (tmax_grid_destroy(parent_key, parent_keylen, TG_CHILDREN) < 0) tgerror("tmax_grid_destroy"); sleep(1); system("echo tgi|tmadmin"); #endif #if _CASE7 printf("tg_bulk_handler_t\n"); lptr=(tg_bulk_handler_t *)malloc(sizeof(tg_bulk_handler_t)); printf("tg_bulk_handler init\n"); if(tmax_grid_init_bulk_handle(lptr)<0) tgerror("tmax_grid_init_bulk_handle"); if ((sndbuf = (char *)tpalloc("STRING", NULL, 1024)) == NULL) tperror("tpalloc sndbuf"); sndlen = sprintf(sndbuf, "(%d) date()", getpid()); printf("grig_set_bulk_handle\n"); if(tmax_grid_set_bulk_handle(lptr,key,strlen(key), -1,0,sndbuf,sndlen)<0) tgerror("tmax_grid_set_bulk_handle"); sndlen = sprintf(sndbuf2, "13(%d) ", getpid()); type=TMAX_GRID_STRING; printf("grig_set_bulk_handle\n"); if(tmax_grid_set_bulk_handle(lptr,key1,strlen(key1),type,0,(void *)sndbuf2,sndlen)<0) tgerror("tmax_grid_set_bulk_handle"); printf(" bulk count = %d \n",lptr->count); printf("grig_set_bulk\n"); if(tmax_grid_bulk_set(lptr,0)<0) tgerror("tmax_grid_bulk_set"); if(tmax_grid_bulk_get(lptr,0)<0) tgerror("tmax_grid_bulk_get"); printf("get bulk data = %s , key = %s \n",lptr->tail->data, lptr->tail->key); system("\necho tgi | tmadmin"); #endif #if _CASE8 browser=(tg_key_browser_t *)malloc(sizeof(tg_key_browser_t)); tmax_grid_init_key_browser(browser,key,strlen(key)); rcvlen=tmax_grid_get_next(browser,0); printf("browser keylen = %d \n",rcvlen); printf("start_key = %s , start_key_len =%d\n", browser->start_key,browser->start_key_len); printf("next_key = %s , next_key_len =%d\n", browser->next_key,browser->next_key_len); count=tmax_grid_count(0); printf("tmax_grid conut = %d \n",count); system("\necho tgi | tmadmin"); #endif tpreturn(TPSUCCESS, 0, NULL, 0, TPNOFLAGS); }
3. Java Client
WebtRemoteService로부터 GQ2에 해당하는 API를 호출하는 구조이다.
gq2Set 예제
import tmax.webt.WebtBuffer; import tmax.webt.WebtConnection; import tmax.webt.WebtException; import tmax.webt.WebtRemoteService; import tmax.webt.WebtServiceFailException; public class TestGQ2 { public static void main(String[] argv) { WebtConnection connection = new WebtConnection("192.168.1.83", 8888, false); connection.setHeaderType("extendedV4"); connection.connect(); WebtRemoteService service = new WebtRemoteService("GQ2", connection); WebtBuffer buffer = service.createStringBuffer(); buffer.setString("TG_Test"); try { int oi = service.gq2Count(); System.out.println("oi = " + oi); service.gq2Set("/Webt12345", buffer, null); } catch (WebtServiceFailException se) { se.printStackTrace(); } catch (WebtException e) { e.printStackTrace(); } finally { connection.close(); } } }
gq2Get 예제
import tmax.webt.WebtBuffer; import tmax.webt.WebtConnection; import tmax.webt.WebtException; import tmax.webt.WebtRemoteService; import tmax.webt.WebtServiceFailException; public class TestGQ2 { public static void main(String[] argv) { WebtConnection connection = new WebtConnection("192.168.1.83", 8888, false); connection.setHeaderType("extendedV4"); connection.connect(); WebtRemoteService service = new WebtRemoteService("GQ2", connection); try { int oi = service.gq2Count(); System.out.println("oi = " + oi); WebtBuffer buffer = service.gq2Get("/Webt12345", null); System.out.println(buffer); } catch (WebtServiceFailException se) { se.printStackTrace(); } catch (WebtException e) { e.printStackTrace(); } finally { connection.close(); } } }
gq2Lock 예제
import java.io.IOException; import tmax.webt.GQ2KeyList; import tmax.webt.WebtBuffer; import tmax.webt.WebtEventConnection; import tmax.webt.WebtException; import tmax.webt.WebtGQ2Attribute; import tmax.webt.WebtGQ2Handler; import tmax.webt.WebtRemoteService; import tmax.webt.WebtServiceFailException; public class TestGQ2 { public static void main(String[] argv) { WebtEventConnection connection = new WebtEventConnection("192.168.1.83", 8122, false); connection.setHeaderType("extendedV4"); connection.connect(); WebtRemoteService service = new WebtRemoteService("GQ2", connection); WebtBuffer buffer = service.createStringBuffer(); buffer.setString("TG_Test222"); WebtGQ2Attribute attr = new WebtGQ2Attribute(WebtGQ2Attribute.TG_LOCK); WebtGQ2Handler handler = null; String key = new String("/WebtLock"); try { int timeout = 6000000; service.gq2Lock(key, timeout, attr); System.out.println("LOCK"); /* business coding */ service.gq2Unlock(key, attr); System.out.println("UNLOCK"); } catch (WebtServiceFailException se) { se.printStackTrace(); } catch (WebtException e) { e.printStackTrace(); } finally { connection.close(); } } }
gq2SetWatcher 예제
package test; import java.io.IOException; import tmax.webt.Gq; import tmax.webt.WebtAttribute; import tmax.webt.WebtBuffer; import tmax.webt.WebtEventConnection; import tmax.webt.WebtEventHandler; import tmax.webt.WebtException; import tmax.webt.WebtGQ2Attribute; import tmax.webt.WebtGQ2Handler; import tmax.webt.WebtIOException; import tmax.webt.WebtRemoteService; public class GQ2EventSample implements { public void handleEvent(String key, int eventType) { System.out.println("event received. key = " + key + ", eventType = " + eventType); } public static void main(String[] argv) throws IOException { WebtEventConnection connection = new WebtEventConnection("192.168.33.216", 12080, false); connection.setHeaderType("extendedV4"); connection.connect(); WebtRemoteService service = new WebtRemoteService("GQ2", connection); WebtBuffer buffer = service.createStringBuffer(); buffer.setString("EVENT_TEST"); WebtGQ2Attribute attr = new WebtGQ2Attribute(WebtGQ2Attribute.TG_WATCHER_PERSISTENT+ WebtGQ2Attribute.TG_EVENT_SET_SELF); GQ2EventSample eventSample = new GQ2EventSample(); String key = new String("/Webt12345"); service.gq2SetWatcher(key, attr, eventSample); System.in.read(); } }