List系のクライアント実装とテストを実装
@@ -62,6 +62,7 @@ | ||
62 | 62 | OkuyamaClient okuyamaClient = null; |
63 | 63 | |
64 | 64 | String startStr = super.getPropertiesValue(super.getJobName() + "start"); |
65 | + String listNamePrefix = super.getPropertiesValue(super.getJobName() + "list"); | |
65 | 66 | int start = Integer.parseInt(startStr); |
66 | 67 | count = count + start; |
67 | 68 | for (int cy = 0; cy < 1; cy++) { |
@@ -130,6 +131,9 @@ | ||
130 | 131 | |
131 | 132 | if (execMethods[i].equals("getmultitagkeysresult")) |
132 | 133 | retMap.put("getmultitagkeysresult", execMultiGetTagKeysResult(okuyamaClient, start, count)); |
134 | + | |
135 | + if (execMethods[i].equals("list")) | |
136 | + retMap.put("list", execList(okuyamaClient, start, listNamePrefix)); | |
133 | 137 | |
134 | 138 | } |
135 | 139 |
@@ -2090,5 +2094,130 @@ | ||
2090 | 2094 | } |
2091 | 2095 | |
2092 | 2096 | |
2097 | + private boolean execList(OkuyamaClient client, int start, String listNamePrefix) throws Exception { | |
2098 | + OkuyamaClient okuyamaClient = null; | |
2099 | + boolean errorFlg = false; | |
2100 | + try { | |
2101 | + System.out.println("execList - Start"); | |
2102 | + if (client != null) { | |
2103 | + okuyamaClient = client; | |
2104 | + } else { | |
2105 | + int port = masterNodePort; | |
2093 | 2106 | |
2107 | + // クライアントインスタンスを作成 | |
2108 | + okuyamaClient = new OkuyamaClient(); | |
2109 | + | |
2110 | + // マスタサーバに接続 | |
2111 | + okuyamaClient.connect(masterNodeName, port); | |
2112 | + } | |
2113 | + | |
2114 | + long startTime = new Date().getTime(); | |
2115 | + Random rnd = new Random(); | |
2116 | + String listName = listNamePrefix+"list"+System.nanoTime(); | |
2117 | + // リスト構造作成 | |
2118 | + String[] ret = okuyamaClient.createListStruct(listName); | |
2119 | + if (!ret[0].equals("true")) { | |
2120 | + System.out.println("List create error1 =" + listName); | |
2121 | + errorFlg = true; | |
2122 | + } | |
2123 | + ret = okuyamaClient.createListStruct(listName); | |
2124 | + if (!ret[0].equals("false")) { | |
2125 | + System.out.println("List create error2 =" + listName); | |
2126 | + errorFlg = true; | |
2127 | + } | |
2128 | + | |
2129 | + // LPUSH | |
2130 | + for (int idx = 0; idx < 5000; idx++) { | |
2131 | + String[] retTmp = okuyamaClient.listLPush(listName, "Llistdata."+idx); | |
2132 | + | |
2133 | + if (!retTmp[0].equals("true")) { | |
2134 | + | |
2135 | + System.out.println("List create error3 =" + listName); | |
2136 | + System.out.println(retTmp[1]); | |
2137 | + errorFlg = true; | |
2138 | + } | |
2139 | + } | |
2140 | +Object[] test = okuyamaClient.listLen(listName); | |
2141 | +System.out.println(listName+" size=" + test[1]); | |
2142 | + // Indexテスト | |
2143 | + for (long idx = 0; idx < 5000L; idx++) { | |
2144 | + | |
2145 | + String[] retTmp = okuyamaClient.listIndex(listName, idx); | |
2146 | + if (!retTmp[0].equals("true")) { | |
2147 | + System.out.println("List create error4 =" + listName); | |
2148 | + System.out.println(retTmp[1]); | |
2149 | + errorFlg = true; | |
2150 | + } else { | |
2151 | + if (!retTmp[1].equals("Llistdata."+(4999-idx))) { | |
2152 | + System.out.println("List create error4-1 =" + listName); | |
2153 | + System.out.println(retTmp[1]); | |
2154 | + errorFlg = true; | |
2155 | + } | |
2156 | + } | |
2157 | + } | |
2158 | + | |
2159 | + // RPUSH | |
2160 | + for (int idx = 0; idx < 5000; idx++) { | |
2161 | + String[] retTmp = okuyamaClient.listRPush(listName, "Rlistdata."+idx); | |
2162 | + | |
2163 | + if (!retTmp[0].equals("true")) { | |
2164 | + | |
2165 | + System.out.println("List create error5 =" + listName); | |
2166 | + System.out.println(retTmp[1]); | |
2167 | + errorFlg = true; | |
2168 | + } | |
2169 | + } | |
2170 | +test = okuyamaClient.listLen(listName); | |
2171 | +System.out.println(listName+" size=" + test[1]); | |
2172 | + | |
2173 | + // Indexテスト | |
2174 | + for (long idx = 0; idx < 5000L; idx++) { | |
2175 | + | |
2176 | + String[] retTmp = okuyamaClient.listIndex(listName, idx); | |
2177 | + if (!retTmp[0].equals("true")) { | |
2178 | + System.out.println("List create error6 =" + listName); | |
2179 | + System.out.println(retTmp[1]); | |
2180 | + errorFlg = true; | |
2181 | + } else { | |
2182 | + if (!retTmp[1].equals("Llistdata."+(4999-idx))) { | |
2183 | + System.out.println("List create error6-1 =" + listName); | |
2184 | + System.out.println(retTmp[1]); | |
2185 | + errorFlg = true; | |
2186 | + } | |
2187 | + } | |
2188 | + } | |
2189 | + // Indexテスト | |
2190 | + int idxTest2 = 0; | |
2191 | + for (long idx = 5000L; idx < 10000L; idx++) { | |
2192 | + | |
2193 | + String[] retTmp = okuyamaClient.listIndex(listName, idx); | |
2194 | + if (!retTmp[0].equals("true")) { | |
2195 | + System.out.println("List create error7 =" + listName); | |
2196 | + System.out.println(retTmp[1]); | |
2197 | + errorFlg = true; | |
2198 | + } else { | |
2199 | + if (!retTmp[1].equals("Rlistdata."+idxTest2)) { | |
2200 | + System.out.println("List create error7-1 =" + listName); | |
2201 | + System.out.println(retTmp[1]); | |
2202 | + errorFlg = true; | |
2203 | + } | |
2204 | + } | |
2205 | + idxTest2++; | |
2206 | + } | |
2207 | + | |
2208 | + | |
2209 | + | |
2210 | + long endTime = new Date().getTime(); | |
2211 | + System.out.println("List Method= " + (endTime - startTime) + " milli second"); | |
2212 | + | |
2213 | + if (client == null) { | |
2214 | + okuyamaClient.close(); | |
2215 | + } | |
2216 | + } catch (Exception e) { | |
2217 | + throw e; | |
2218 | + } | |
2219 | + System.out.println("execList - End"); | |
2220 | + | |
2221 | + return errorFlg; | |
2222 | + } | |
2094 | 2223 | } |
\ No newline at end of file |
@@ -1212,7 +1212,7 @@ | ||
1212 | 1212 | closeFlg = true; |
1213 | 1213 | reloopSameClient = false; |
1214 | 1214 | } catch (ArrayIndexOutOfBoundsException aie) { |
1215 | -aie.printStackTrace(); | |
1215 | + | |
1216 | 1216 | logger.error("KeyManagerHelper No Method_1 =[" + clientParameterList[0] + "]"); |
1217 | 1217 | reloopSameClient = false; |
1218 | 1218 | } catch (NumberFormatException nfe) { |
@@ -2254,11 +2254,11 @@ | ||
2254 | 2254 | // 既に存在する |
2255 | 2255 | retStrs[0] = "51"; |
2256 | 2256 | retStrs[1] = "false"; |
2257 | - retStrs[2] = "ListName=[" + listName + "] already exists"; | |
2257 | + retStrs[2] = "list already exists"; | |
2258 | 2258 | } else if (retSts == 1) { |
2259 | 2259 | retStrs[0] = "51"; |
2260 | 2260 | retStrs[1] = "false"; |
2261 | - retStrs[2] = "ListName=[" + listName + "] create error"; | |
2261 | + retStrs[2] = "list create error"; | |
2262 | 2262 | } |
2263 | 2263 | } else { |
2264 | 2264 |
@@ -2226,12 +2226,12 @@ | ||
2226 | 2226 | |
2227 | 2227 | |
2228 | 2228 | // 保存結果確認 |
2229 | - if (keyNodeSaveRet[1].equals("false") || keyNodeSaveRet[1].equals("false")) { | |
2229 | + if (keyNodeSaveRet[1].equals("false") || keyNodeSaveRet[1].equals("error")) { | |
2230 | 2230 | // 保存失敗 |
2231 | 2231 | if (keyNodeSaveRet.length > 2) { |
2232 | 2232 | |
2233 | 2233 | retStrs[0] = "52"; |
2234 | - retStrs[1] = "false"; | |
2234 | + retStrs[1] = keyNodeSaveRet[1]; | |
2235 | 2235 | retStrs[2] = keyNodeSaveRet[2]; |
2236 | 2236 | } else { |
2237 | 2237 | retStrs = new String[2]; |
@@ -2714,7 +2714,6 @@ | ||
2714 | 2714 | * 構造体を事前に作成していない場合は失敗する<br> |
2715 | 2715 | * |
2716 | 2716 | * @param listNameStr List名文字列 |
2717 | - * @param listData Listへ追加するデータ | |
2718 | 2717 | * @return String[] 結果 |
2719 | 2718 | * @throws BatchException |
2720 | 2719 | */ |
@@ -3076,7 +3075,7 @@ | ||
3076 | 3075 | */ |
3077 | 3076 | private String[] searchValueIndex(String indexStrs, String searchType, String indexPrefix, int searchIndexLength) throws BatchException { |
3078 | 3077 | //logger.debug("MasterManagerHelper - searchValueIndex - start"); |
3079 | -long start = System.nanoTime(); | |
3078 | + //long start = System.nanoTime(); | |
3080 | 3079 | |
3081 | 3080 | String[] retStrs = new String[3]; |
3082 | 3081 | StringBuilder retKeysBuf = new StringBuilder(); |
@@ -3490,8 +3489,8 @@ | ||
3490 | 3489 | retStrs[1] = "error"; |
3491 | 3490 | retStrs[2] = "MasterNode - Exception"; |
3492 | 3491 | } |
3493 | -long end = System.nanoTime(); | |
3494 | -System.out.println("searchValue=" + ((end - start) / 1000)); | |
3492 | + //long end = System.nanoTime(); | |
3493 | + //System.out.println("searchValue=" + ((end - start) / 1000)); | |
3495 | 3494 | |
3496 | 3495 | //logger.debug("MasterManagerHelper - searchValueIndex - end"); |
3497 | 3496 | return retStrs; |
@@ -7899,6 +7898,7 @@ | ||
7899 | 7898 | |
7900 | 7899 | StringBuilder buf = new StringBuilder(ImdstDefine.stringBufferSmallSize); |
7901 | 7900 | String sendStr = null; |
7901 | + boolean listLPopExecutionRet = false; | |
7902 | 7902 | |
7903 | 7903 | try { |
7904 | 7904 |
@@ -7955,6 +7955,7 @@ | ||
7955 | 7955 | |
7956 | 7956 | // 結果有りで成功 |
7957 | 7957 | mainNodeSave = true; |
7958 | + listLPopExecutionRet = true; | |
7958 | 7959 | } else if (retParam != null && retParam.indexOf(ImdstDefine.keyNodeLPopNullStr) == 0) { |
7959 | 7960 | // 結果なし |
7960 | 7961 | mainNodeSave = true; |
@@ -8016,7 +8017,14 @@ | ||
8016 | 8017 | |
8017 | 8018 | // 返却地値をパースする |
8018 | 8019 | if (retParam != null) { |
8020 | + | |
8019 | 8021 | retParams = retParam.split(ImdstDefine.keyHelperClientParamSep); |
8022 | + | |
8023 | + if (listLPopExecutionRet) { | |
8024 | + // 更新時間(バージョンNo)を取り外す | |
8025 | + String[] realRetValue = dataConvert4Consistency(retParams[2]); | |
8026 | + retParams[2] = realRetValue[0]; | |
8027 | + } | |
8020 | 8028 | } |
8021 | 8029 | } |
8022 | 8030 |
@@ -8056,6 +8064,8 @@ | ||
8056 | 8064 | StringBuilder buf = new StringBuilder(ImdstDefine.stringBufferSmallSize); |
8057 | 8065 | String sendStr = null; |
8058 | 8066 | |
8067 | + boolean listRPopExecutionRet = false; | |
8068 | + | |
8059 | 8069 | try { |
8060 | 8070 | |
8061 | 8071 | // TransactionModeの状態に合わせてLock状態を確かめる |
@@ -8107,11 +8117,12 @@ | ||
8107 | 8117 | |
8108 | 8118 | // Key値でValueを保存 |
8109 | 8119 | // 特定文字列で返却値が始まるかをチェックし始まる場合は登録成功 |
8110 | - if (retParam != null && retParam.indexOf(ImdstDefine.keyNodeLPopSuccessStr) == 0) { | |
8120 | + if (retParam != null && retParam.indexOf(ImdstDefine.keyNodeRPopSuccessStr) == 0) { | |
8111 | 8121 | |
8112 | 8122 | // 結果有りで成功 |
8113 | 8123 | mainNodeSave = true; |
8114 | - } else if (retParam != null && retParam.indexOf(ImdstDefine.keyNodeLPopNullStr) == 0) { | |
8124 | + listRPopExecutionRet = true; | |
8125 | + } else if (retParam != null && retParam.indexOf(ImdstDefine.keyNodeRPopNullStr) == 0) { | |
8115 | 8126 | // 結果なし |
8116 | 8127 | mainNodeSave = true; |
8117 | 8128 | } else { |
@@ -8173,6 +8184,12 @@ | ||
8173 | 8184 | // 返却地値をパースする |
8174 | 8185 | if (retParam != null) { |
8175 | 8186 | retParams = retParam.split(ImdstDefine.keyHelperClientParamSep); |
8187 | + if (listRPopExecutionRet) { | |
8188 | + // 更新時間(バージョンNo)を取り外す | |
8189 | + String[] realRetValue = dataConvert4Consistency(retParams[2]); | |
8190 | + retParams[2] = realRetValue[0]; | |
8191 | + } | |
8192 | + | |
8176 | 8193 | } |
8177 | 8194 | } |
8178 | 8195 |
@@ -8304,7 +8321,6 @@ | ||
8304 | 8321 | retParams[2] = cnvConsistencyRet[0]; |
8305 | 8322 | break; |
8306 | 8323 | } else if (retParams != null && retParams.length > 1 && retParams[1].equals("false")) { |
8307 | - retParams[2] = ""; | |
8308 | 8324 | break; |
8309 | 8325 | } else if (retParams != null && retParams.length > 1 && retParams[1].equals("error")) { |
8310 | 8326 | break; |
@@ -4353,11 +4353,15 @@ | ||
4353 | 4353 | |
4354 | 4354 | if (!dataLines[i].trim().equals("")) { |
4355 | 4355 | |
4356 | + // TODO:ここで移行データから有効期限よりも後ろを削除してしまっている。 | |
4356 | 4357 | oneDatas = dataLines[i].split(KeyMapManager.workFileSeq); |
4357 | 4358 | |
4358 | 4359 | // データの種類に合わせて処理分岐 |
4359 | 4360 | if (oneDatas[0].equals("1")) { |
4360 | 4361 | |
4362 | + // TODO:有効期限データはValueの後に、カンマ区切りで情報が結合されているため、 | |
4363 | + // ここでoneDatasはレングスが4以上になる可能性がある | |
4364 | + | |
4361 | 4365 | // 通常データ |
4362 | 4366 | // 成功、失敗関係なく全て登録処理 |
4363 | 4367 | this.setKeyPairOnlyOnce(oneDatas[1], oneDatas[2], "0", true); |
@@ -141,6 +141,12 @@ | ||
141 | 141 | // データノードに対するList構造体へにLPOP時に成功した場合の返却文字列の先頭部分 |
142 | 142 | public static final String keyNodeLPopNullStr = "55,false"; |
143 | 143 | |
144 | + // データノードに対するList構造体へにRPOP時に成功した場合の返却文字列の先頭部分 | |
145 | + public static final String keyNodeRPopSuccessStr = "56,true"; | |
146 | + | |
147 | + // データノードに対するList構造体へにRPOP時に成功した場合の返却文字列の先頭部分 | |
148 | + public static final String keyNodeRPopNullStr = "56,false"; | |
149 | + | |
144 | 150 | // MasterNodeのgetMultiValueを呼び出した際のClientへの戻り値 |
145 | 151 | public static final String getMultiEndOfDataStr = "END"; |
146 | 152 |
@@ -8718,6 +8718,1013 @@ | ||
8718 | 8718 | } |
8719 | 8719 | |
8720 | 8720 | |
8721 | + /** | |
8722 | + * List構造体を作成.<br> | |
8723 | + * 既に同名のリストがある場合は失敗する<br> | |
8724 | + * | |
8725 | + * @param listName 作成するリスト名 | |
8726 | + * @return 要素1(作成成否):"true" or "false",要素2(作成失敗時は失敗原因メッセージ):"データ文字列" | |
8727 | + * @throw OkuyamaClientException | |
8728 | + */ | |
8729 | + public String[] createListStruct(String listName) throws OkuyamaClientException { | |
8730 | + String[] ret = new String[1]; | |
8731 | + String serverRetStr = null; | |
8732 | + String[] serverRet = null; | |
8733 | + String valueStr = null; | |
8734 | + | |
8735 | + // 文字列バッファ初期化 | |
8736 | + | |
8737 | + StringBuilder createListServerReqBuf = new StringBuilder(); | |
8738 | + | |
8739 | + try { | |
8740 | + // Byte Lenghtチェック | |
8741 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
8742 | + | |
8743 | + // エラーチェック | |
8744 | + // Keyに対する無指定チェック | |
8745 | + if (listName == null || listName.trim().equals("")) | |
8746 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
8747 | + | |
8748 | + if (listName.getBytes().length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
8749 | + | |
8750 | + | |
8751 | + // 処理番号連結 | |
8752 | + createListServerReqBuf.append("51"); | |
8753 | + // セパレータ連結 | |
8754 | + createListServerReqBuf.append(OkuyamaClient.sepStr); | |
8755 | + | |
8756 | + | |
8757 | + // Key連結(Keyはデータ送信時には必ず文字列が必要) | |
8758 | + createListServerReqBuf.append(new String(this.dataEncoding(listName.getBytes()))); | |
8759 | + // セパレータ連結 | |
8760 | + createListServerReqBuf.append(OkuyamaClient.sepStr); | |
8761 | + | |
8762 | + // TransactionCode連結 | |
8763 | + createListServerReqBuf.append(this.transactionCode); | |
8764 | + | |
8765 | + // サーバ送信 | |
8766 | + pw.println(createListServerReqBuf.toString()); | |
8767 | + pw.flush(); | |
8768 | + | |
8769 | + // サーバから結果受け取り | |
8770 | + serverRetStr = br.readLine(); | |
8771 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
8772 | + | |
8773 | + // 処理の妥当性確認 | |
8774 | + if (serverRet[0].equals("51")) { | |
8775 | + if (serverRet[1].equals("true")) { | |
8776 | + | |
8777 | + // 処理成功 | |
8778 | + ret[0] = "true"; | |
8779 | + } else if (serverRet[1].equals("false")) { | |
8780 | + | |
8781 | + // 失敗 | |
8782 | + if (serverRet.length > 2) { | |
8783 | + ret = new String[2]; | |
8784 | + ret[0] = serverRet[1]; | |
8785 | + ret[1] = serverRet[2]; | |
8786 | + } else { | |
8787 | + ret[0] = serverRet[1]; | |
8788 | + } | |
8789 | + } else if (serverRet[1].equals("error")) { | |
8790 | + | |
8791 | + // 処理失敗(メッセージ格納) | |
8792 | + throw new OkuyamaClientException(serverRet[2]); | |
8793 | + } | |
8794 | + } else { | |
8795 | + | |
8796 | + // 妥当性違反 | |
8797 | + throw new OkuyamaClientException("Execute Violation of validity [" + serverRetStr + "]"); | |
8798 | + } | |
8799 | + | |
8800 | + } catch (OkuyamaClientException ice) { | |
8801 | + throw ice; | |
8802 | + } catch (ConnectException ce) { | |
8803 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8804 | + try { | |
8805 | + this.autoConnect(); | |
8806 | + ret = this.createListStruct(listName); | |
8807 | + } catch (Exception e) { | |
8808 | + throw new OkuyamaClientException(ce); | |
8809 | + } | |
8810 | + } else { | |
8811 | + throw new OkuyamaClientException(ce); | |
8812 | + } | |
8813 | + } catch (SocketException se) { | |
8814 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8815 | + try { | |
8816 | + this.autoConnect(); | |
8817 | + ret = this.createListStruct(listName); | |
8818 | + } catch (Exception e) { | |
8819 | + throw new OkuyamaClientException(se); | |
8820 | + } | |
8821 | + } else { | |
8822 | + throw new OkuyamaClientException(se); | |
8823 | + } | |
8824 | + } catch (Throwable e) { | |
8825 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8826 | + try { | |
8827 | + this.autoConnect(); | |
8828 | + ret = this.createListStruct(listName); | |
8829 | + } catch (Exception ee) { | |
8830 | + throw new OkuyamaClientException(e); | |
8831 | + } | |
8832 | + } else { | |
8833 | + throw new OkuyamaClientException(e); | |
8834 | + } | |
8835 | + } | |
8836 | + return ret; | |
8837 | + } | |
8838 | + | |
8839 | + | |
8840 | + /** | |
8841 | + * List構造体の先頭に値を追加する.<br> | |
8842 | + * リストが存在しない場合は結果がerrorとなる<br> | |
8843 | + * | |
8844 | + * @param listName リスト名 | |
8845 | + * @param pushData 登録するデータ | |
8846 | + * @return 要素1(登録成否):"true" or "false" or "error",要素2(登録失敗時は失敗原因メッセージ):"データ文字列" | |
8847 | + * @throw OkuyamaClientException | |
8848 | + */ | |
8849 | + public String[] listLPush(String listName, String pushData) throws OkuyamaClientException { | |
8850 | + return listLPush(listName, pushData, null); | |
8851 | + } | |
8852 | + | |
8853 | + | |
8854 | + /** | |
8855 | + * List構造体の先頭に値を追加する.<br> | |
8856 | + * リストが存在しない場合は結果がerrorとなる<br> | |
8857 | + * | |
8858 | + * @param listName リスト名 | |
8859 | + * @param pushData 登録するデータ | |
8860 | + * @param encode Dataの文字エンコード | |
8861 | + * @return 要素1(登録成否):"true" or "false" or "error",要素2(登録失敗時は失敗原因メッセージ):"データ文字列" | |
8862 | + * @throw OkuyamaClientException | |
8863 | + */ | |
8864 | + public String[] listLPush(String listName, String pushData, String encode) throws OkuyamaClientException { | |
8865 | + String[] ret = null; | |
8866 | + String serverRetStr = null; | |
8867 | + String[] serverRet = null; | |
8868 | + String encodeValue = null; | |
8869 | + | |
8870 | + // 文字列バッファ初期化 | |
8871 | + setValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
8872 | + | |
8873 | + if (encode == null) encode = platformDefaultEncoding; | |
8874 | + | |
8875 | + try { | |
8876 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
8877 | + | |
8878 | + // Byte Lenghtチェック | |
8879 | + if (pushData != null) { | |
8880 | + if (pushData.getBytes(encode).length > maxValueSize) { | |
8881 | + throw new OkuyamaClientException("Save List Value Max Size " + maxValueSize + " Byte"); | |
8882 | + } | |
8883 | + } | |
8884 | + | |
8885 | + // エラーチェック | |
8886 | + // listNameに対する無指定チェック | |
8887 | + if (listName == null || listName.trim().equals("")) | |
8888 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
8889 | + | |
8890 | + if (listName.getBytes(encode).length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
8891 | + | |
8892 | + // pushDataに対する無指定チェック(pushDataはnullやブランクの場合は代行文字列に置き換える) | |
8893 | + if (pushData == null || pushData.equals("")) { | |
8894 | + encodeValue = OkuyamaClient.blankStr; | |
8895 | + } else { | |
8896 | + | |
8897 | + // ValueをBase64でエンコード | |
8898 | + encodeValue = new String(this.dataEncoding(pushData.getBytes(encode))); | |
8899 | + } | |
8900 | + | |
8901 | + | |
8902 | + // 処理番号連結 | |
8903 | + setValueServerReqBuf.append("52"); | |
8904 | + // セパレータ連結 | |
8905 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
8906 | + | |
8907 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
8908 | + setValueServerReqBuf.append(new String(this.dataEncoding(listName.getBytes(encode)))); | |
8909 | + | |
8910 | + // セパレータ連結 | |
8911 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
8912 | + | |
8913 | + // pushData連結 | |
8914 | + setValueServerReqBuf.append(encodeValue); | |
8915 | + | |
8916 | + // セパレータ連結 | |
8917 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
8918 | + | |
8919 | + // TransactionCode連結 | |
8920 | + setValueServerReqBuf.append(this.transactionCode); | |
8921 | + | |
8922 | + | |
8923 | + // サーバ送信 | |
8924 | + pw.println(setValueServerReqBuf.toString()); | |
8925 | + pw.flush(); | |
8926 | + | |
8927 | + // サーバから結果受け取り | |
8928 | + serverRetStr = br.readLine(); | |
8929 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
8930 | + | |
8931 | + // 処理の妥当性確認 | |
8932 | + if (serverRet != null && serverRet[0].equals("52")) { | |
8933 | + if (serverRet[1].equals("true")) { | |
8934 | + | |
8935 | + // 処理成功 | |
8936 | + ret = new String[1]; | |
8937 | + ret[0] = "true"; | |
8938 | + } else{ | |
8939 | + | |
8940 | + // 処理失敗(メッセージ格納) | |
8941 | + ret = new String[2]; | |
8942 | + ret[0] = "false"; | |
8943 | + ret[1] = serverRet[2]; | |
8944 | + } | |
8945 | + } else { | |
8946 | + | |
8947 | + // 妥当性違反 | |
8948 | + throw new OkuyamaClientException("Execute Violation of validity [" + serverRetStr + "]"); | |
8949 | + } | |
8950 | + } catch (OkuyamaClientException ice) { | |
8951 | + throw ice; | |
8952 | + } catch (ConnectException ce) { | |
8953 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8954 | + try { | |
8955 | + this.autoConnect(); | |
8956 | + ret = this.listLPush(listName, pushData, encode); | |
8957 | + } catch (Exception e) { | |
8958 | + throw new OkuyamaClientException(ce); | |
8959 | + } | |
8960 | + } else { | |
8961 | + throw new OkuyamaClientException(ce); | |
8962 | + } | |
8963 | + } catch (SocketException se) { | |
8964 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8965 | + try { | |
8966 | + this.autoConnect(); | |
8967 | + ret = this.listLPush(listName, pushData, encode); | |
8968 | + } catch (Exception e) { | |
8969 | + throw new OkuyamaClientException(se); | |
8970 | + } | |
8971 | + } else { | |
8972 | + throw new OkuyamaClientException(se); | |
8973 | + } | |
8974 | + } catch (Throwable e) { | |
8975 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
8976 | + try { | |
8977 | + this.autoConnect(); | |
8978 | + ret = this.listLPush(listName, pushData, encode); | |
8979 | + } catch (Exception ee) { | |
8980 | + throw new OkuyamaClientException(e); | |
8981 | + } | |
8982 | + } else { | |
8983 | + throw new OkuyamaClientException(e); | |
8984 | + } | |
8985 | + } | |
8986 | + return ret; | |
8987 | + } | |
8988 | + | |
8989 | + /** | |
8990 | + * List構造体の末尾に値を追加する.<br> | |
8991 | + * リストが存在しない場合は結果がerrorとなる<br> | |
8992 | + * | |
8993 | + * @param listName リスト名 | |
8994 | + * @param pushData 登録するデータ | |
8995 | + * @return 要素1(登録成否):"true" or "false" or "error",要素2(登録失敗時は失敗原因メッセージ):"データ文字列" | |
8996 | + * @throw OkuyamaClientException | |
8997 | + */ | |
8998 | + public String[] listRPush(String listName, String pushData) throws OkuyamaClientException { | |
8999 | + return listRPush(listName, pushData, null); | |
9000 | + } | |
9001 | + | |
9002 | + /** | |
9003 | + * List構造体の末尾に値を追加する.<br> | |
9004 | + * リストが存在しない場合は結果がerrorとなる<br> | |
9005 | + * | |
9006 | + * @param listName リスト名 | |
9007 | + * @param pushData 登録するデータ | |
9008 | + * @param encode Dataの文字エンコード | |
9009 | + * @return 要素1(登録成否):"true" or "false" or "error",要素2(登録失敗時は失敗原因メッセージ):"データ文字列" | |
9010 | + * @throw OkuyamaClientException | |
9011 | + */ | |
9012 | + public String[] listRPush(String listName, String pushData, String encode) throws OkuyamaClientException { | |
9013 | + String[] ret = null; | |
9014 | + String serverRetStr = null; | |
9015 | + String[] serverRet = null; | |
9016 | + String encodeValue = null; | |
9017 | + | |
9018 | + | |
9019 | + // 文字列バッファ初期化 | |
9020 | + setValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
9021 | + | |
9022 | + if (encode == null) encode = platformDefaultEncoding; | |
9023 | + | |
9024 | + try { | |
9025 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
9026 | + | |
9027 | + // Byte Lenghtチェック | |
9028 | + if (pushData != null) { | |
9029 | + if (pushData.getBytes(encode).length > maxValueSize) { | |
9030 | + throw new OkuyamaClientException("Save List Value Max Size " + maxValueSize + " Byte"); | |
9031 | + } | |
9032 | + } | |
9033 | + | |
9034 | + // エラーチェック | |
9035 | + // listNameに対する無指定チェック | |
9036 | + if (listName == null || listName.trim().equals("")) | |
9037 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
9038 | + | |
9039 | + if (listName.getBytes(encode).length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
9040 | + | |
9041 | + // pushDataに対する無指定チェック(pushDataはnullやブランクの場合は代行文字列に置き換える) | |
9042 | + if (pushData == null || pushData.equals("")) { | |
9043 | + encodeValue = OkuyamaClient.blankStr; | |
9044 | + } else { | |
9045 | + | |
9046 | + // ValueをBase64でエンコード | |
9047 | + encodeValue = new String(this.dataEncoding(pushData.getBytes(encode))); | |
9048 | + } | |
9049 | + | |
9050 | + | |
9051 | + // 処理番号連結 | |
9052 | + setValueServerReqBuf.append("53"); | |
9053 | + // セパレータ連結 | |
9054 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9055 | + | |
9056 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
9057 | + setValueServerReqBuf.append(new String(this.dataEncoding(listName.getBytes(encode)))); | |
9058 | + | |
9059 | + // セパレータ連結 | |
9060 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9061 | + | |
9062 | + // pushData連結 | |
9063 | + setValueServerReqBuf.append(encodeValue); | |
9064 | + | |
9065 | + // セパレータ連結 | |
9066 | + setValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9067 | + | |
9068 | + // TransactionCode連結 | |
9069 | + setValueServerReqBuf.append(this.transactionCode); | |
9070 | + | |
9071 | + | |
9072 | + // サーバ送信 | |
9073 | + pw.println(setValueServerReqBuf.toString()); | |
9074 | + pw.flush(); | |
9075 | + | |
9076 | + // サーバから結果受け取り | |
9077 | + serverRetStr = br.readLine(); | |
9078 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
9079 | + | |
9080 | + // 処理の妥当性確認 | |
9081 | + if (serverRet != null && serverRet[0].equals("53")) { | |
9082 | + if (serverRet[1].equals("true")) { | |
9083 | + | |
9084 | + // 処理成功 | |
9085 | + ret = new String[1]; | |
9086 | + ret[0] = "true"; | |
9087 | + } else{ | |
9088 | + | |
9089 | + // 処理失敗(メッセージ格納) | |
9090 | + ret = new String[2]; | |
9091 | + ret[0] = "false"; | |
9092 | + ret[1] = serverRet[2]; | |
9093 | + } | |
9094 | + } else { | |
9095 | + | |
9096 | + // 妥当性違反 | |
9097 | + throw new OkuyamaClientException("Execute Violation of validity [" + serverRetStr + "]"); | |
9098 | + } | |
9099 | + } catch (OkuyamaClientException ice) { | |
9100 | + throw ice; | |
9101 | + } catch (ConnectException ce) { | |
9102 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9103 | + try { | |
9104 | + this.autoConnect(); | |
9105 | + ret = this.listRPush(listName, pushData, encode); | |
9106 | + } catch (Exception e) { | |
9107 | + throw new OkuyamaClientException(ce); | |
9108 | + } | |
9109 | + } else { | |
9110 | + throw new OkuyamaClientException(ce); | |
9111 | + } | |
9112 | + } catch (SocketException se) { | |
9113 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9114 | + try { | |
9115 | + this.autoConnect(); | |
9116 | + ret = this.listRPush(listName, pushData, encode); | |
9117 | + } catch (Exception e) { | |
9118 | + throw new OkuyamaClientException(se); | |
9119 | + } | |
9120 | + } else { | |
9121 | + throw new OkuyamaClientException(se); | |
9122 | + } | |
9123 | + } catch (Throwable e) { | |
9124 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9125 | + try { | |
9126 | + this.autoConnect(); | |
9127 | + ret = this.listRPush(listName, pushData, encode); | |
9128 | + } catch (Exception ee) { | |
9129 | + throw new OkuyamaClientException(e); | |
9130 | + } | |
9131 | + } else { | |
9132 | + throw new OkuyamaClientException(e); | |
9133 | + } | |
9134 | + } | |
9135 | + return ret; | |
9136 | + } | |
9137 | + | |
9138 | + | |
9139 | + /** | |
9140 | + * List構造の指定Indexの値を取得する.<br> | |
9141 | + * 構造体を事前に作成していない場合は失敗する<br> | |
9142 | + * 指定位置が存在しない場合は結果はなしとなる<br> | |
9143 | + * | |
9144 | + * @param listName リスト名 | |
9145 | + * @param index 取得位置 | |
9146 | + * @return 要素1(取得成否):"true"=値有り or "false"=指定位置に値なし or "error"=リスト無し等エラー, 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9147 | + * @throw OkuyamaClientException | |
9148 | + */ | |
9149 | + public String[] listIndex(String listName, long index) throws OkuyamaClientException { | |
9150 | + return listIndex(listName, index, null); | |
9151 | + } | |
9152 | + /** | |
9153 | + * List構造の指定Indexの値を取得する.<br> | |
9154 | + * 構造体を事前に作成していない場合は失敗する<br> | |
9155 | + * 指定位置が存在しない場合は結果はなしとなる<br> | |
9156 | + * | |
9157 | + * @param listName リスト名 | |
9158 | + * @param index 取得位置 | |
9159 | + * @param encode Dataの文字エンコード | |
9160 | + * @return 要素1(取得成否):"true"=値有り or "false"=指定位置に値なし 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9161 | + * @throw OkuyamaClientException | |
9162 | + */ | |
9163 | + public String[] listIndex(String listName, long index, String encode) throws OkuyamaClientException { | |
9164 | + String[] ret = new String[2]; | |
9165 | + String serverRetStr = null; | |
9166 | + String[] serverRet = null; | |
9167 | + byte[] listNameBytes = null; | |
9168 | + | |
9169 | + // 文字列バッファ初期化 | |
9170 | + getValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
9171 | + | |
9172 | + if (encode == null) encode = platformDefaultEncoding; | |
9173 | + try { | |
9174 | + | |
9175 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
9176 | + | |
9177 | + // エラーチェック | |
9178 | + // listNameに対する無指定チェック | |
9179 | + if (listName == null || listName.trim().equals("")) { | |
9180 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
9181 | + } | |
9182 | + | |
9183 | + // Keyに対するLengthチェック | |
9184 | + listNameBytes = listName.getBytes(encode); | |
9185 | + if (listNameBytes.length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
9186 | + | |
9187 | + | |
9188 | + // 処理番号連結 | |
9189 | + getValueServerReqBuf.append("54"); | |
9190 | + // セパレータ連結 | |
9191 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9192 | + | |
9193 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
9194 | + getValueServerReqBuf.append(new String(this.dataEncoding(listNameBytes))); | |
9195 | + // セパレータ連結 | |
9196 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9197 | + | |
9198 | + getValueServerReqBuf.append(index); | |
9199 | + // セパレータ連結 | |
9200 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9201 | + | |
9202 | + // TransactionCode連結 | |
9203 | + getValueServerReqBuf.append(this.transactionCode); | |
9204 | + | |
9205 | + | |
9206 | + // サーバ送信 | |
9207 | + pw.println(getValueServerReqBuf.toString()); | |
9208 | + pw.flush(); | |
9209 | + | |
9210 | + // サーバから結果受け取り | |
9211 | + serverRetStr = br.readLine(); | |
9212 | + | |
9213 | + | |
9214 | + | |
9215 | + boolean responseSuccess = false; | |
9216 | + if (serverRetStr.indexOf("54,true") == 0) { | |
9217 | + | |
9218 | + responseSuccess = true; | |
9219 | + } else { | |
9220 | + | |
9221 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
9222 | + } | |
9223 | + // 処理の妥当性確認 | |
9224 | + if (responseSuccess) { | |
9225 | + | |
9226 | + // データ有り | |
9227 | + ret[0] = "true"; | |
9228 | + String retValueStr = serverRetStr.substring(8); | |
9229 | + // Valueがブランク文字か調べる | |
9230 | + if (retValueStr.equals(OkuyamaClient.blankStr)) { | |
9231 | + ret[1] = ""; | |
9232 | + } else { | |
9233 | + | |
9234 | + | |
9235 | + // Value文字列をBase64でデコード | |
9236 | + ret[1] = new String(this.dataDecoding(retValueStr.getBytes(encode)), encode); | |
9237 | + } | |
9238 | + } else if (serverRet[0].equals("54")) { | |
9239 | + if(serverRet[1].equals("false")) { | |
9240 | + | |
9241 | + // データなし | |
9242 | + ret[0] = serverRet[1]; | |
9243 | + ret[1] = null; | |
9244 | + } else if(serverRet[1].equals("error")) { | |
9245 | + | |
9246 | + // エラー発生 | |
9247 | + ret[0] = serverRet[1]; | |
9248 | + ret[1] = serverRet[2]; | |
9249 | + } | |
9250 | + } else { | |
9251 | + | |
9252 | + // 妥当性違反 | |
9253 | + throw new OkuyamaClientException("Execute Violation of validity " + serverRetStr); | |
9254 | + } | |
9255 | + } catch (OkuyamaClientException ice) { | |
9256 | + throw ice; | |
9257 | + } catch (ConnectException ce) { | |
9258 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9259 | + try { | |
9260 | + this.autoConnect(); | |
9261 | + ret = this.listIndex(listName, index, encode); | |
9262 | + } catch (Exception e) { | |
9263 | + throw new OkuyamaClientException(ce); | |
9264 | + } | |
9265 | + } else { | |
9266 | + throw new OkuyamaClientException(ce); | |
9267 | + } | |
9268 | + } catch (SocketException se) { | |
9269 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9270 | + try { | |
9271 | + this.autoConnect(); | |
9272 | + ret = this.listIndex(listName, index, encode); | |
9273 | + } catch (Exception e) { | |
9274 | + throw new OkuyamaClientException(se); | |
9275 | + } | |
9276 | + } else { | |
9277 | + throw new OkuyamaClientException(se); | |
9278 | + } | |
9279 | + } catch (Throwable e) { | |
9280 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9281 | + try { | |
9282 | + this.autoConnect(); | |
9283 | + ret = this.listIndex(listName, index, encode); | |
9284 | + } catch (Exception ee) { | |
9285 | + throw new OkuyamaClientException(e); | |
9286 | + } | |
9287 | + } else { | |
9288 | + throw new OkuyamaClientException(e); | |
9289 | + } | |
9290 | + } | |
9291 | + return ret; | |
9292 | + } | |
9293 | + | |
9294 | + | |
9295 | + | |
9296 | + | |
9297 | + | |
9298 | + /** | |
9299 | + * 指定したList構造体の先頭から要素を取得する。取得された要素は削除されListは先頭から1つ詰められる.<br> | |
9300 | + * リストが存在しない場合はエラーとなる<br> | |
9301 | + * | |
9302 | + * @param listName リスト名 | |
9303 | + * @return 要素1(取得成否):"true"=値有り or "false"=値なし or "error"=リスト無し等エラー, 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9304 | + * @throw OkuyamaClientException | |
9305 | + */ | |
9306 | + public String[] listLPop(String listName) throws OkuyamaClientException { | |
9307 | + return listLPop(listName, null); | |
9308 | + } | |
9309 | + | |
9310 | + /** | |
9311 | + * 指定したList構造体の先頭から要素を取得する。取得された要素は削除されListは先頭から1つ詰められる.<br> | |
9312 | + * リストが存在しない場合はエラーとなる<br> | |
9313 | + * | |
9314 | + * @param listName リスト名 | |
9315 | + * @param encode Dataの文字エンコード | |
9316 | + * @return 要素1(取得成否):"true"=値有り or "false"=値なし or "error"=リスト無し等エラー, 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9317 | + * @throw OkuyamaClientException | |
9318 | + */ | |
9319 | + public String[] listLPop(String listName, String encode) throws OkuyamaClientException { | |
9320 | + String[] ret = new String[2]; | |
9321 | + String serverRetStr = null; | |
9322 | + String[] serverRet = null; | |
9323 | + byte[] listNameBytes = null; | |
9324 | + | |
9325 | + // 文字列バッファ初期化 | |
9326 | + getValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
9327 | + | |
9328 | + if (encode == null) encode = platformDefaultEncoding; | |
9329 | + try { | |
9330 | + | |
9331 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
9332 | + | |
9333 | + // エラーチェック | |
9334 | + // listNameに対する無指定チェック | |
9335 | + if (listName == null || listName.trim().equals("")) { | |
9336 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
9337 | + } | |
9338 | + | |
9339 | + // Keyに対するLengthチェック | |
9340 | + listNameBytes = listName.getBytes(encode); | |
9341 | + if (listNameBytes.length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
9342 | + | |
9343 | + | |
9344 | + // 処理番号連結 | |
9345 | + getValueServerReqBuf.append("55"); | |
9346 | + // セパレータ連結 | |
9347 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9348 | + | |
9349 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
9350 | + getValueServerReqBuf.append(new String(this.dataEncoding(listNameBytes))); | |
9351 | + // セパレータ連結 | |
9352 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9353 | + | |
9354 | + // TransactionCode連結 | |
9355 | + getValueServerReqBuf.append(this.transactionCode); | |
9356 | + | |
9357 | + | |
9358 | + // サーバ送信 | |
9359 | + pw.println(getValueServerReqBuf.toString()); | |
9360 | + pw.flush(); | |
9361 | + | |
9362 | + // サーバから結果受け取り | |
9363 | + serverRetStr = br.readLine(); | |
9364 | + | |
9365 | + | |
9366 | + | |
9367 | + boolean responseSuccess = false; | |
9368 | + if (serverRetStr.indexOf("55,true") == 0) { | |
9369 | + | |
9370 | + responseSuccess = true; | |
9371 | + } else { | |
9372 | + | |
9373 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
9374 | + } | |
9375 | + // 処理の妥当性確認 | |
9376 | + if (responseSuccess) { | |
9377 | + | |
9378 | + // データ有り | |
9379 | + ret[0] = "true"; | |
9380 | + String retValueStr = serverRetStr.substring(8); | |
9381 | + // Valueがブランク文字か調べる | |
9382 | + if (retValueStr.equals(OkuyamaClient.blankStr)) { | |
9383 | + ret[1] = ""; | |
9384 | + } else { | |
9385 | + | |
9386 | + | |
9387 | + // Value文字列をBase64でデコード | |
9388 | + ret[1] = new String(this.dataDecoding(retValueStr.getBytes(encode)), encode); | |
9389 | + } | |
9390 | + } else if (serverRet[0].equals("55")) { | |
9391 | + if(serverRet[1].equals("false")) { | |
9392 | + | |
9393 | + // データなし | |
9394 | + ret[0] = serverRet[1]; | |
9395 | + ret[1] = null; | |
9396 | + } else if(serverRet[1].equals("error")) { | |
9397 | + | |
9398 | + // エラー発生 | |
9399 | + ret[0] = serverRet[1]; | |
9400 | + ret[1] = serverRet[2]; | |
9401 | + } | |
9402 | + } else { | |
9403 | + | |
9404 | + // 妥当性違反 | |
9405 | + throw new OkuyamaClientException("Execute Violation of validity " + serverRet); | |
9406 | + } | |
9407 | + } catch (OkuyamaClientException ice) { | |
9408 | + throw ice; | |
9409 | + } catch (ConnectException ce) { | |
9410 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9411 | + try { | |
9412 | + this.autoConnect(); | |
9413 | + ret = this.listLPop(listName, encode); | |
9414 | + } catch (Exception e) { | |
9415 | + throw new OkuyamaClientException(ce); | |
9416 | + } | |
9417 | + } else { | |
9418 | + throw new OkuyamaClientException(ce); | |
9419 | + } | |
9420 | + } catch (SocketException se) { | |
9421 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9422 | + try { | |
9423 | + this.autoConnect(); | |
9424 | + ret = this.listLPop(listName, encode); | |
9425 | + } catch (Exception e) { | |
9426 | + throw new OkuyamaClientException(se); | |
9427 | + } | |
9428 | + } else { | |
9429 | + throw new OkuyamaClientException(se); | |
9430 | + } | |
9431 | + } catch (Throwable e) { | |
9432 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9433 | + try { | |
9434 | + this.autoConnect(); | |
9435 | + ret = this.listLPop(listName, encode); | |
9436 | + } catch (Exception ee) { | |
9437 | + throw new OkuyamaClientException(e); | |
9438 | + } | |
9439 | + } else { | |
9440 | + throw new OkuyamaClientException(e); | |
9441 | + } | |
9442 | + } | |
9443 | + return ret; | |
9444 | + } | |
9445 | + | |
9446 | + | |
9447 | + /** | |
9448 | + * 指定したList構造体の先頭から要素を取得する。取得された要素は削除されListは先頭から1つ詰められる.<br> | |
9449 | + * 要素が存在しない場合はnullが返る。リストが存在しない場合はエラーとなる<br> | |
9450 | + * | |
9451 | + * @param listName リスト名 | |
9452 | + * @return 要素1(取得成否):"true"=値有り or "false"=値なし or "error"=リスト無し等エラー, 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9453 | + * @throw OkuyamaClientException | |
9454 | + */ | |
9455 | + public String[] listRPop(String listName) throws OkuyamaClientException { | |
9456 | + return listRPop(listName, null); | |
9457 | + } | |
9458 | + | |
9459 | + /** | |
9460 | + * 指定したList構造体の先頭から要素を取得する。取得された要素は削除されListは先頭から1つ詰められる.<br> | |
9461 | + * 要素が存在しない場合はnullが返る。リストが存在しない場合はエラーとなる<br> | |
9462 | + * | |
9463 | + * @param listName リスト名 | |
9464 | + * @param encode Dataの文字エンコード | |
9465 | + * @return 要素1(取得成否):"true"=値有り or "false"=値なし or "error"=リスト無し等エラー, 要素2(値有りの場合は結果、それ以外の場合はエラー等のメッセージ) | |
9466 | + * @throw OkuyamaClientException | |
9467 | + */ | |
9468 | + public String[] listRPop(String listName, String encode) throws OkuyamaClientException { | |
9469 | + String[] ret = new String[2]; | |
9470 | + String serverRetStr = null; | |
9471 | + String[] serverRet = null; | |
9472 | + byte[] listNameBytes = null; | |
9473 | + | |
9474 | + // 文字列バッファ初期化 | |
9475 | + getValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
9476 | + | |
9477 | + if (encode == null) encode = platformDefaultEncoding; | |
9478 | + try { | |
9479 | + | |
9480 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
9481 | + | |
9482 | + // エラーチェック | |
9483 | + // listNameに対する無指定チェック | |
9484 | + if (listName == null || listName.trim().equals("")) { | |
9485 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
9486 | + } | |
9487 | + | |
9488 | + // Keyに対するLengthチェック | |
9489 | + listNameBytes = listName.getBytes(encode); | |
9490 | + if (listNameBytes.length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
9491 | + | |
9492 | + | |
9493 | + // 処理番号連結 | |
9494 | + getValueServerReqBuf.append("56"); | |
9495 | + // セパレータ連結 | |
9496 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9497 | + | |
9498 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
9499 | + getValueServerReqBuf.append(new String(this.dataEncoding(listNameBytes))); | |
9500 | + // セパレータ連結 | |
9501 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9502 | + | |
9503 | + // TransactionCode連結 | |
9504 | + getValueServerReqBuf.append(this.transactionCode); | |
9505 | + | |
9506 | + | |
9507 | + // サーバ送信 | |
9508 | + pw.println(getValueServerReqBuf.toString()); | |
9509 | + pw.flush(); | |
9510 | + | |
9511 | + // サーバから結果受け取り | |
9512 | + serverRetStr = br.readLine(); | |
9513 | + | |
9514 | + | |
9515 | + boolean responseSuccess = false; | |
9516 | + if (serverRetStr.indexOf("56,true") == 0) { | |
9517 | + | |
9518 | + responseSuccess = true; | |
9519 | + } else { | |
9520 | + | |
9521 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
9522 | + } | |
9523 | + // 処理の妥当性確認 | |
9524 | + if (responseSuccess) { | |
9525 | + | |
9526 | + // データ有り | |
9527 | + ret[0] = "true"; | |
9528 | + String retValueStr = serverRetStr.substring(8); | |
9529 | + // Valueがブランク文字か調べる | |
9530 | + if (retValueStr.equals(OkuyamaClient.blankStr)) { | |
9531 | + ret[1] = ""; | |
9532 | + } else { | |
9533 | + | |
9534 | + | |
9535 | + // Value文字列をBase64でデコード | |
9536 | + ret[1] = new String(this.dataDecoding(retValueStr.getBytes(encode)), encode); | |
9537 | + } | |
9538 | + } else if (serverRet[0].equals("56")) { | |
9539 | + if(serverRet[1].equals("false")) { | |
9540 | + | |
9541 | + // データなし | |
9542 | + ret[0] = serverRet[1]; | |
9543 | + ret[1] = null; | |
9544 | + } else if(serverRet[1].equals("error")) { | |
9545 | + | |
9546 | + // エラー発生 | |
9547 | + ret[0] = serverRet[1]; | |
9548 | + ret[1] = serverRet[2]; | |
9549 | + } | |
9550 | + } else { | |
9551 | + | |
9552 | + // 妥当性違反 | |
9553 | + throw new OkuyamaClientException("Execute Violation of validity " + serverRet); | |
9554 | + } | |
9555 | + } catch (OkuyamaClientException ice) { | |
9556 | + throw ice; | |
9557 | + } catch (ConnectException ce) { | |
9558 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9559 | + try { | |
9560 | + this.autoConnect(); | |
9561 | + ret = this.listRPop(listName, encode); | |
9562 | + } catch (Exception e) { | |
9563 | + throw new OkuyamaClientException(ce); | |
9564 | + } | |
9565 | + } else { | |
9566 | + throw new OkuyamaClientException(ce); | |
9567 | + } | |
9568 | + } catch (SocketException se) { | |
9569 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9570 | + try { | |
9571 | + this.autoConnect(); | |
9572 | + ret = this.listRPop(listName, encode); | |
9573 | + } catch (Exception e) { | |
9574 | + throw new OkuyamaClientException(se); | |
9575 | + } | |
9576 | + } else { | |
9577 | + throw new OkuyamaClientException(se); | |
9578 | + } | |
9579 | + } catch (Throwable e) { | |
9580 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9581 | + try { | |
9582 | + this.autoConnect(); | |
9583 | + ret = this.listRPop(listName, encode); | |
9584 | + } catch (Exception ee) { | |
9585 | + throw new OkuyamaClientException(e); | |
9586 | + } | |
9587 | + } else { | |
9588 | + throw new OkuyamaClientException(e); | |
9589 | + } | |
9590 | + } | |
9591 | + return ret; | |
9592 | + } | |
9593 | + | |
9594 | + /** | |
9595 | + * List構造のサイズを取得する.<br> | |
9596 | + * Listを事前に作成していない場合はerrorとなる<br> | |
9597 | + * | |
9598 | + * @param listNameStr List名 | |
9599 | + * @return Object[] 要素1(取得成否):"true"=成功 or "false"=リスト無し or "error"=エラー, 要素2(成功の場合は結果(Long値)、falseの場合はnull、errorの場合はエラー等のメッセージ(String値)) | |
9600 | + * @throws OkuyamaClientException | |
9601 | + */ | |
9602 | + public Object[] listLen(String listName) throws OkuyamaClientException { | |
9603 | + Object[] ret = new Object[2]; | |
9604 | + String serverRetStr = null; | |
9605 | + String[] serverRet = null; | |
9606 | + byte[] listNameBytes = null; | |
9607 | + | |
9608 | + // 文字列バッファ初期化 | |
9609 | + getValueServerReqBuf.delete(0, Integer.MAX_VALUE); | |
9610 | + | |
9611 | + try { | |
9612 | + | |
9613 | + if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!"); | |
9614 | + | |
9615 | + // エラーチェック | |
9616 | + // listNameに対する無指定チェック | |
9617 | + if (listName == null || listName.trim().equals("")) { | |
9618 | + throw new OkuyamaClientException("The blank is not admitted on a listName"); | |
9619 | + } | |
9620 | + | |
9621 | + // Keyに対するLengthチェック | |
9622 | + listNameBytes = listName.getBytes(); | |
9623 | + if (listNameBytes.length > maxKeySize) throw new OkuyamaClientException("Save listName Max Size " + maxKeySize + " Byte"); | |
9624 | + | |
9625 | + | |
9626 | + // 処理番号連結 | |
9627 | + getValueServerReqBuf.append("57"); | |
9628 | + // セパレータ連結 | |
9629 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9630 | + | |
9631 | + // listName連結(listNameはデータ送信時には必ず文字列が必要) | |
9632 | + getValueServerReqBuf.append(new String(this.dataEncoding(listNameBytes))); | |
9633 | + // セパレータ連結 | |
9634 | + getValueServerReqBuf.append(OkuyamaClient.sepStr); | |
9635 | + | |
9636 | + // TransactionCode連結 | |
9637 | + getValueServerReqBuf.append(this.transactionCode); | |
9638 | + | |
9639 | + | |
9640 | + // サーバ送信 | |
9641 | + pw.println(getValueServerReqBuf.toString()); | |
9642 | + pw.flush(); | |
9643 | + | |
9644 | + // サーバから結果受け取り | |
9645 | + serverRetStr = br.readLine(); | |
9646 | + | |
9647 | + | |
9648 | + | |
9649 | + boolean responseSuccess = false; | |
9650 | + if (serverRetStr.indexOf("57,true") == 0) { | |
9651 | + | |
9652 | + responseSuccess = true; | |
9653 | + } else { | |
9654 | + | |
9655 | + serverRet = serverRetStr.split(OkuyamaClient.sepStr); | |
9656 | + } | |
9657 | + // 処理の妥当性確認 | |
9658 | + if (responseSuccess) { | |
9659 | + | |
9660 | + // データ有り | |
9661 | + ret[0] = "true"; | |
9662 | + String retValueStr = serverRetStr.substring(8); | |
9663 | + // Valueがブランク文字か調べる | |
9664 | + if (retValueStr.equals(OkuyamaClient.blankStr)) { | |
9665 | + ret[1] = ""; | |
9666 | + } else { | |
9667 | + | |
9668 | + // Value文字列をBase64でデコード | |
9669 | + ret[1] = new Long(retValueStr); | |
9670 | + } | |
9671 | + } else if (serverRet[0].equals("57")) { | |
9672 | + if(serverRet[1].equals("false")) { | |
9673 | + | |
9674 | + // データなし | |
9675 | + ret[0] = serverRet[1]; | |
9676 | + ret[1] = null; | |
9677 | + } else if(serverRet[1].equals("error")) { | |
9678 | + | |
9679 | + // エラー発生 | |
9680 | + ret[0] = serverRet[1]; | |
9681 | + ret[1] = serverRet[2]; | |
9682 | + } | |
9683 | + } else { | |
9684 | + | |
9685 | + // 妥当性違反 | |
9686 | + throw new OkuyamaClientException("Execute Violation of validity " + serverRet); | |
9687 | + } | |
9688 | + } catch (OkuyamaClientException ice) { | |
9689 | + throw ice; | |
9690 | + } catch (ConnectException ce) { | |
9691 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9692 | + try { | |
9693 | + this.autoConnect(); | |
9694 | + ret = this.listLen(listName); | |
9695 | + } catch (Exception e) { | |
9696 | + throw new OkuyamaClientException(ce); | |
9697 | + } | |
9698 | + } else { | |
9699 | + throw new OkuyamaClientException(ce); | |
9700 | + } | |
9701 | + } catch (SocketException se) { | |
9702 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9703 | + try { | |
9704 | + this.autoConnect(); | |
9705 | + ret = this.listLen(listName); | |
9706 | + } catch (Exception e) { | |
9707 | + throw new OkuyamaClientException(se); | |
9708 | + } | |
9709 | + } else { | |
9710 | + throw new OkuyamaClientException(se); | |
9711 | + } | |
9712 | + } catch (Throwable e) { | |
9713 | + if (this.masterNodesList != null && masterNodesList.size() > 1) { | |
9714 | + try { | |
9715 | + this.autoConnect(); | |
9716 | + ret = this.listLen(listName); | |
9717 | + } catch (Exception ee) { | |
9718 | + throw new OkuyamaClientException(e); | |
9719 | + } | |
9720 | + } else { | |
9721 | + throw new OkuyamaClientException(e); | |
9722 | + } | |
9723 | + } | |
9724 | + return ret; | |
9725 | + } | |
9726 | + | |
9727 | + | |
8721 | 9728 | // Base64でエンコード |
8722 | 9729 | protected byte[] dataEncoding(byte[] datas) { |
8723 | 9730 | return BASE64EncoderStream.encode(datas); |