• R/O
  • SSH
  • HTTPS

okuyama: 提交


Commit MetaInfo

修訂958 (tree)
時間2012-06-30 00:58:42
作者okuyamaoo

Log Message

(empty log message)

Change Summary

差異

--- trunk/src/okuyama/imdst/helper/MasterManagerHelper.java (revision 957)
+++ trunk/src/okuyama/imdst/helper/MasterManagerHelper.java (revision 958)
@@ -853,6 +853,7 @@
853853 retParams[2] = "It is executable only by MainMasterNode";
854854 }
855855 break;
856+
856857 case 90 :
857858
858859 // KeyNodeの使用停止をマーク
--- trunk/src/okuyama/imdst/client/OkuyamaClient.java (revision 957)
+++ trunk/src/okuyama/imdst/client/OkuyamaClient.java (revision 958)
@@ -3064,8 +3064,173 @@
30643064 }
30653065
30663066
3067+ /**
3068+ * MasterNodeへデータを送信する(バイナリデータ).<br>
3069+ * 本メソッドは呼び出し後はrequestByteValue後に呼び出すこと.<br>
3070+ *
3071+ * @param keyStr Key値
3072+ * @param values Value値
3073+ * @return boolean 登録成否
3074+ * @throws OkuyamaClientException
3075+ */
3076+ public boolean requestByteValue(String keyStr, byte[] values) throws OkuyamaClientException {
3077+ boolean ret = false;
3078+ String serverRetStr = null;
3079+ String[] serverRet = null;
3080+ String value = null;
3081+ StringBuilder serverRequestBuf = new StringBuilder(ImdstDefine.stringBufferLarge_3Size);
30673082
3083+ String saveStr = null;
3084+
3085+ try {
3086+ if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!");
3087+
3088+ // Byte Lenghtチェック
3089+ if (keyStr == null || keyStr.trim().equals(""))
3090+ throw new OkuyamaClientException("The blank is not admitted on a key");
3091+
3092+ if (keyStr.getBytes().length > maxKeySize) throw new OkuyamaClientException("Save Key Max Size " + maxKeySize + " Byte");
3093+
3094+ if (values == null || values.length == 0)
3095+ throw new OkuyamaClientException("The blank is not admitted on a value");
3096+
3097+ if (values.length > maxValueSize)
3098+ throw new OkuyamaClientException("Save Value Max Size " + maxValueSize + " Byte");
3099+
3100+
3101+ // valuesがnullであることはない
3102+ // ValueをBase64でエンコード
3103+ value = new String(this.dataEncoding(values));
3104+
3105+ // 処理番号連結
3106+ serverRequestBuf.append("1");
3107+ // セパレータ連結
3108+ serverRequestBuf.append(OkuyamaClient.sepStr);
3109+
3110+ // Key連結(Keyはデータ送信時には必ず文字列が必要)
3111+ serverRequestBuf.append(new String(this.dataEncoding(keyStr.getBytes())));
3112+ // セパレータ連結
3113+ serverRequestBuf.append(OkuyamaClient.sepStr);
3114+
3115+ // Tagは必ず存在しない
3116+ // ブランク規定文字列を連結
3117+ serverRequestBuf.append(OkuyamaClient.blankStr);
3118+
3119+ // セパレータ連結
3120+ serverRequestBuf.append(OkuyamaClient.sepStr);
3121+
3122+ // TransactionCode連結
3123+ serverRequestBuf.append(this.transactionCode);
3124+
3125+ // セパレータ連結
3126+ serverRequestBuf.append(OkuyamaClient.sepStr);
3127+
3128+ // Value連結
3129+ serverRequestBuf.append(value);
3130+
3131+ // サーバ送信
3132+ pw.println(serverRequestBuf.toString());
3133+ pw.flush();
3134+
3135+ } catch (OkuyamaClientException ice) {
3136+ throw ice;
3137+ } catch (Throwable e) {
3138+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
3139+ try {
3140+ this.autoConnect();
3141+ ret = this.sendByteValue(keyStr, values);
3142+ } catch (Exception ee) {
3143+ throw new OkuyamaClientException(e);
3144+ }
3145+ } else {
3146+ throw new OkuyamaClientException(e);
3147+ }
3148+ }
3149+ return true;
3150+ }
3151+
3152+
30683153 /**
3154+ * MasterNodeへデータを送信する(バイナリデータ).<br>
3155+ * setByteValueメソッドとの違いはValueをSplitしないで登録する部分.<br>
3156+ *
3157+ * @param keyStr Key値
3158+ * @param values Value値
3159+ * @return boolean 登録成否
3160+ * @throws OkuyamaClientException
3161+ */
3162+ public boolean responseByteValue(String keyStr, byte[] values) throws OkuyamaClientException {
3163+ boolean ret = false;
3164+ String serverRetStr = null;
3165+ String[] serverRet = null;
3166+ String value = null;
3167+ StringBuilder serverRequestBuf = new StringBuilder(ImdstDefine.stringBufferLarge_3Size);
3168+
3169+ String saveStr = null;
3170+
3171+ try {
3172+ // サーバから結果受け取り
3173+ serverRetStr = br.readLine();
3174+
3175+ serverRet = serverRetStr.split(OkuyamaClient.sepStr);
3176+
3177+ // 処理の妥当性確認
3178+ if (serverRet.length == 3 && serverRet[0].equals("1")) {
3179+ if (serverRet[1].equals("true")) {
3180+
3181+ // 処理成功
3182+ ret = true;
3183+ } else{
3184+
3185+ // 処理失敗(メッセージ格納)
3186+ throw new OkuyamaClientException(serverRet[2]);
3187+ }
3188+ } else {
3189+
3190+ // 妥当性違反
3191+ throw new OkuyamaClientException("Execute Violation of validity [" + serverRetStr + "]");
3192+ }
3193+ } catch (OkuyamaClientException ice) {
3194+ throw ice;
3195+ } catch (ConnectException ce) {
3196+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
3197+ try {
3198+ this.autoConnect();
3199+ ret = this.sendByteValue(keyStr, values);
3200+ } catch (Exception e) {
3201+ throw new OkuyamaClientException(ce);
3202+ }
3203+ } else {
3204+ throw new OkuyamaClientException(ce);
3205+ }
3206+ } catch (SocketException se) {
3207+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
3208+ try {
3209+ this.autoConnect();
3210+ ret = this.sendByteValue(keyStr, values);
3211+ } catch (Exception e) {
3212+ throw new OkuyamaClientException(se);
3213+ }
3214+ } else {
3215+ throw new OkuyamaClientException(se);
3216+ }
3217+ } catch (Throwable e) {
3218+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
3219+ try {
3220+ this.autoConnect();
3221+ ret = this.sendByteValue(keyStr, values);
3222+ } catch (Exception ee) {
3223+ throw new OkuyamaClientException(e);
3224+ }
3225+ } else {
3226+ throw new OkuyamaClientException(e);
3227+ }
3228+ }
3229+ return ret;
3230+ }
3231+
3232+
3233+ /**
30693234 * MasterNodeへデータを送信する(Object).<br>
30703235 * 引数のObjectを自動的にシリアライズし保存する<br>
30713236 * そのため保存出来るObjectはシリアライズ可能な型である必要がある.<br>
@@ -5664,7 +5829,194 @@
56645829 }
56655830
56665831
5832+
56675833 /**
5834+ * MasterNodeからKeyでデータを削除する.<br>
5835+ * 取得値のエンコーディング指定あり.<br>
5836+ *
5837+ * @param keyStr Key値
5838+ * @return String[] 削除したデータ 内容) 要素1(データ削除有無):"true" or "false",要素2(削除データ):"データ文字列"
5839+ * @throws OkuyamaClientException
5840+ */
5841+ public boolean requestRemoveValue(String keyStr) throws OkuyamaClientException {
5842+ boolean ret = true;
5843+ String serverRetStr = null;
5844+ String[] serverRet = null;
5845+
5846+ StringBuilder serverRequestBuf = null;
5847+
5848+ try {
5849+ if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!");
5850+
5851+ // エラーチェック
5852+ // Keyに対する無指定チェック
5853+ if (keyStr == null || keyStr.trim().equals(""))
5854+ throw new OkuyamaClientException("The blank is not admitted on a key");
5855+
5856+ // Keyに対するLengthチェック
5857+ if (keyStr.getBytes().length > maxKeySize) throw new OkuyamaClientException("Save Key Max Size " + keyStr + " Byte");
5858+
5859+ // 文字列バッファ初期化
5860+ serverRequestBuf = new StringBuilder(ImdstDefine.stringBufferSmallSize);
5861+
5862+ // 処理番号連結
5863+ serverRequestBuf.append("5");
5864+ // セパレータ連結
5865+ serverRequestBuf.append(OkuyamaClient.sepStr);
5866+ // Key連結(Keyはデータ送信時には必ず文字列が必要)
5867+ serverRequestBuf.append(new String(this.dataEncoding(keyStr.getBytes())));
5868+ // セパレータ連結
5869+ serverRequestBuf.append(OkuyamaClient.sepStr);
5870+ // TransactionCode連結
5871+ serverRequestBuf.append(this.transactionCode);
5872+
5873+
5874+ // サーバ送信
5875+ pw.println(serverRequestBuf.toString());
5876+ pw.flush();
5877+
5878+ return true;
5879+ } catch (OkuyamaClientException ice) {
5880+ throw ice;
5881+ } catch (Throwable e) {
5882+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
5883+ try {
5884+ this.autoConnect();
5885+ ret = this.requestRemoveValue(keyStr);
5886+ } catch (Exception ee) {
5887+ throw new OkuyamaClientException(e);
5888+ }
5889+ } else {
5890+ throw new OkuyamaClientException(e);
5891+ }
5892+ }
5893+ return true;
5894+ }
5895+
5896+
5897+ /**
5898+ * MasterNodeからKeyでデータを削除する.<br>
5899+ * 取得値のエンコーディング指定あり.<br>
5900+ *
5901+ * @param keyStr Key値
5902+ * @return String[] 削除したデータ 内容) 要素1(データ削除有無):"true" or "false",要素2(削除データ):"データ文字列"
5903+ * @throws OkuyamaClientException
5904+ */
5905+ public String[] responseRemoveValue(String keyStr) throws OkuyamaClientException {
5906+ return responseRemoveValue(keyStr, null);
5907+ }
5908+
5909+ /**
5910+ * MasterNodeからKeyでデータを削除する.<br>
5911+ * 取得値のエンコーディング指定あり.<br>
5912+ *
5913+ * @param keyStr Key値
5914+ * @return String[] 削除したデータ 内容) 要素1(データ削除有無):"true" or "false",要素2(削除データ):"データ文字列"
5915+ * @throws OkuyamaClientException
5916+ */
5917+ public String[] responseRemoveValue(String keyStr, String encoding) throws OkuyamaClientException {
5918+ String[] ret = new String[2];
5919+ String serverRetStr = null;
5920+ String[] serverRet = null;
5921+
5922+ StringBuilder serverRequestBuf = null;
5923+
5924+ try {
5925+ if (this.socket == null) throw new OkuyamaClientException("No ServerConnect!!");
5926+
5927+ // サーバから結果受け取り
5928+ serverRetStr = br.readLine();
5929+
5930+ serverRet = serverRetStr.split(OkuyamaClient.sepStr);
5931+
5932+ // 処理の妥当性確認
5933+ if (serverRet[0].equals("5")) {
5934+ if (serverRet[1].equals("true")) {
5935+
5936+ // データ有り
5937+ ret[0] = serverRet[1];
5938+
5939+ // Valueがブランク文字か調べる
5940+ if (serverRet[2].equals(OkuyamaClient.blankStr)) {
5941+ ret[1] = "";
5942+ } else {
5943+
5944+ // Value文字列をBase64でデコード
5945+ if (encoding == null) {
5946+ ret[1] = new String(this.dataDecoding(serverRet[2].getBytes()));
5947+ } else {
5948+ ret[1] = new String(this.dataDecoding(serverRet[2].getBytes()), encoding);
5949+ }
5950+ }
5951+ } else if(serverRet[1].equals("false")) {
5952+
5953+ // データなし
5954+ ret[0] = serverRet[1];
5955+ ret[1] = null;
5956+ } else if(serverRet[1].equals("error")) {
5957+
5958+ // エラー発生
5959+ ret[0] = serverRet[1];
5960+ ret[1] = serverRet[2];
5961+ }
5962+ } else {
5963+
5964+ // 妥当性違反
5965+ throw new OkuyamaClientException("Execute Violation of validity");
5966+ }
5967+ } catch (OkuyamaClientException ice) {
5968+ throw ice;
5969+ } catch (ConnectException ce) {
5970+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
5971+ try {
5972+ this.autoConnect();
5973+ if(this.requestRemoveValue(keyStr)) {
5974+ ret = this.responseRemoveValue(keyStr);
5975+ } else {
5976+ throw new OkuyamaClientException(ce);
5977+ }
5978+ } catch (Exception e) {
5979+ throw new OkuyamaClientException(ce);
5980+ }
5981+ } else {
5982+ throw new OkuyamaClientException(ce);
5983+ }
5984+ } catch (SocketException se) {
5985+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
5986+ try {
5987+ this.autoConnect();
5988+ if(this.requestRemoveValue(keyStr)) {
5989+ ret = this.responseRemoveValue(keyStr);
5990+ } else {
5991+ throw new OkuyamaClientException(se);
5992+ }
5993+ } catch (Exception e) {
5994+ throw new OkuyamaClientException(se);
5995+ }
5996+ } else {
5997+ throw new OkuyamaClientException(se);
5998+ }
5999+ } catch (Throwable e) {
6000+ if (this.masterNodesList != null && masterNodesList.size() > 1) {
6001+ try {
6002+ this.autoConnect();
6003+ if(this.requestRemoveValue(keyStr)) {
6004+ ret = this.responseRemoveValue(keyStr);
6005+ } else {
6006+ throw new OkuyamaClientException(e);
6007+ }
6008+ } catch (Exception ee) {
6009+ throw new OkuyamaClientException(e);
6010+ }
6011+ } else {
6012+ throw new OkuyamaClientException(e);
6013+ }
6014+ }
6015+ return ret;
6016+ }
6017+
6018+
6019+ /**
56686020 * MasterNodeへKey値とTag値を指定してTagの紐付きを削除する.<br>
56696021 *
56706022 * @param keyStr Key値
--- trunk/src/okuyama/imdst/client/OkuyamaClientFactory.java (revision 957)
+++ trunk/src/okuyama/imdst/client/OkuyamaClientFactory.java (revision 958)
@@ -170,6 +170,20 @@
170170 */
171171 public OkuyamaClient getClient() throws OkuyamaClientException {
172172
173+ return this.getClient(false);
174+ }
175+
176+
177+ /**
178+ * OkuyamaClientを取得する.<br>
179+ * 内部的に接続状態の確認を行ったのちに返却される<br>
180+ * プールに1つもOkuyamaClientが存在しない場合は新規に作成されて返される<br>
181+ * 本メソッドから取得したOkuyamaClientのcloseメソッドを呼び出すことでプールに返却される<br>
182+ *
183+ * @throws OkuyamaClientException 有効なOkuyamaClientの返却に失敗
184+ */
185+ public OkuyamaClient getClient(boolean noCheck) throws OkuyamaClientException {
186+
173187 OkuyamaClient client = null;
174188
175189 try {
@@ -187,10 +201,13 @@
187201 client = null;
188202 } else {
189203
190- try {
191- client.getOkuyamaVersion();
192- } catch (Exception innerE) {
193- client = null;
204+ if (noCheck == false) {
205+
206+ try {
207+ client.getOkuyamaVersion();
208+ } catch (Exception innerE) {
209+ client = null;
210+ }
194211 }
195212 }
196213 }
@@ -220,6 +237,7 @@
220237 }
221238
222239
240+
223241 /**
224242 * Client返却メソッド.<br>
225243 * クライアント利用者が呼び出す必要はなく、okuyama.imdst.client.ClientRedirectorが呼び出す<br>
Show on old repository browser