1. 데이터 입력중 마스터 DB가 중지댈때 데이터 보장되는 지 확인 


1.1 소스코드 

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.data.redis.RedisConnectionFailureException;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.exceptions.JedisConnectionException;

/**
* @Auth Hong Seungkyun
* @Description
* <pre></pre>
*/
public class RedisTest {

     public static void main(String[] args) throws Exception {

          Set<String> sentinelIps = new HashSet<>();
          sentinelIps.add("175.207.8.166:26379");
          sentinelIps.add("175.207.8.167:26379");
          sentinelIps.add("175.207.8.168:26379");

          GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();

          JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster", sentinelIps, poolConfig, 5000, "1020");
          Jedis jedis1 = jedisSentinelPool.getResource();
          String[] keys = new String[100];
         
         
         
          //삭제처리
          StringBuffer delkey = new StringBuffer();
          for (int i = 0; i < 100; i++) {    
               keys[i] ="Test_"+i;
          }    
          jedis1.del(keys);
              

          for (int i = 0; i < 100; i++) {              
               try {
                    RedisTest.setData(jedisSentinelPool, "Test_"+i, "value_"+i);
                    System.out.println("input > key : Test_"+i+" , value :  value_"+i);
               } catch (Exception e) {
                    System.out.println(e.getMessage());
                    System.out.println("에러 발생");
               }         
              
               Thread.sleep(500);
          }
         
          for (int i = 0; i < 100; i++) {
               Jedis jedis = jedisSentinelPool.getResource();
               try {
                    String value = jedis.get("Test_" + i);
                    System.out.println("output > key : Test_"+i+" , value :"+value);
               } catch (RedisConnectionFailureException e) {
                    e.printStackTrace();
                    jedisSentinelPool.returnBrokenResource(jedis);
               } finally {

                    try {

                         jedisSentinelPool.returnResource(jedis);

                    } catch (JedisConnectionException e) {

                         System.out.println(e);

                    }
               }
          }

          /*
          * JedisPool jedisPool = new JedisPool(new JedisPoolConfig(), "175.207.8.166",6379,0,"1020");
          * Jedis jedis = jedisPool.getResource();
          * try {
          * jedis.set("foo", "client_test");
          * } catch (Exception e) {
          * System.out.println(e.getMessage());
          * }
          * System.out.println(">>>>> : "+jedis.get("foo"));
          */

     }
     public  static void  setData(JedisSentinelPool jedisSentinelPool, String key , String value ){
          Jedis jedis =null;
          try {              
               jedis = jedisSentinelPool.getResource();
               jedis.set(key, value);
          } catch (RedisConnectionFailureException e) {
               System.out.println(e);
               System.out.println("헐헐2!!");
               jedisSentinelPool.returnBrokenResource(jedis);
          } finally {
               try {
                    jedisSentinelPool.returnResource(jedis);
               } catch (JedisConnectionException e) {                   
                    System.out.println(e);
                    System.out.println("헐헐3!!");
               }
          }
         
     }

}
1.2 서버 콘솔 
입력 도중 
# redis-cli -a 1020 shutdown 명령 입력 

1.3 데이터 처리 로그 

1월 27, 2015 11:16:22 오전 redis.clients.jedis.JedisSentinelPool initSentinels
정보: Trying to find master from available Sentinels...
1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initSentinels
정보: Redis master running at 175.207.8.167:6379, starting Sentinel listeners...
1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initPool
정보: Created JedisPool to master at 175.207.8.167:6379
input > key : Test_0 , value :  value_0
.......
input > key : Test_16 , value :  value_16
input > key : Test_17 , value :  value_17 ==>> 에러 최초 발생 
Unexpected end of stream.
에러 발생
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error
헐헐3!!
java.net.SocketException: Software caused connection abort: socket write error
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
Could not get a resource from the pool
에러 발생
1월 27, 2015 11:17:03 오전 redis.clients.jedis.JedisSentinelPool initPool
정보: Created JedisPool to master at 175.207.8.168:6379
Could not get a resource from the pool
에러 발생

input > key : Test_41 , value :  value_41 ==> 마스터 체이진 정상 입력
input > key : Test_42 , value :  value_42
........
input > key : Test_99 , value :  value_99

//데이터 읽기
output > key : Test_0 , value :value_0
output > key : Test_1 , value :value_1
output > key : Test_2 , value :value_2
........
output > key : Test_17 , value :value_17
output > key : Test_18 , value :null
output > key : Test_19 , value :null
output > key : Test_20 , value :null
......
output > key : Test_36 , value :null
output > key : Test_37 , value :null
output > key : Test_38 , value :null
output > key : Test_39 , value :null
output > key : Test_40 , value :null

output > key : Test_41 , value :value_41
output > key : Test_42 , value :value_42
........
output > key : Test_95 , value :value_95
output > key : Test_96 , value :value_96
output > key : Test_97 , value :value_97
output > key : Test_98 , value :value_98
output > key : Test_99 , value :value_99

결론 
강제 셧다운시 10초  이후에 시스템이 정상 운영됨 
1. 10 초 사이데이터 처리 방안이 필요함 ( 서버 체크 시간 8초로 설정해서 11초후에 정상 처리  시스템  설정 시간보다 다소 시간이 지연됨.)


참고 싸이트 

 


1. JAVA + ibatis 개발시 자동으로 쿼리문을 만들어준다.

복사해서 이용하면 된다.

2.위 커리문을 실행하기 위해 필요한 함수

정리한 내용

반환값 함수명 파라미터
String abbreviate String str, int maxWidth
"…"를 포함한 지정한 사이즈로 문자열을 축소한다 maxWidth은 4보다 커야한다
String abbreviate String str, int offset, int maxWidth
"…"를 포함한 지정한 사이즈로 문자열을 앞/뒤로 축소한다 offset은 7보다 커야한다
String capitalise String str
deprecated
String capitaliseAllWords String str
deprecated
String capitalize String str
문자열중 첫번째 문자를 대문자로 만든다
String center String str, int size
str의 길이가 size가 되도록 문자열 좌우에 공백문자를 하나씩 추가한다 (우측부터 시작한다)
String center String str, int size, char padChar
str의 길이가 size가 되도록 문자열 좌우에 padChar를 하나씩 추가한다 (우측부터 시작한다)
String center String str, int size, String padStr
str의 길이가 size가 되도록 문자열 좌우에 padStr을 하나씩 추가한다 (우측부터 시작한다)
String chomp String str
문자열 맨 끝에있는 '\n' , '\r', '\r\n'을 제거한다
String chomp String str, String separator
문자열 맨 끝에 separator가 있으면 이를 제거한다
String chompLast String str
deprecated
String chompLast String str, String sep
deprecated
String chop String str
문자열 맨 끝에있는 문자 하나를 제거한다
String chopNewline String str
deprecated
String clean String str
deprecated
String concatenate Object array[]
deprecated
boolean contains String str, char searchChar
str이 searchChar를 포함하고 있으면 true
boolean contains String str, String searchStr
str이 searchStr을 포함하고 있으면 true
boolean containsNone String str, char invalidChars[]
str이 invalidChars의 각 문자를 모두 포함하고 있지 않으면 true
boolean containsNone String str, String invalidChars
str이 invalidChars를 모두 포함하고 있지 않으면 true
boolean containsOnly String str, char valid[]
str이 valid의 각 문자들만 포함하고 있어야 true
boolean containsOnly String str, String validChars
str이 validChars 들만을 포함하고 있어야 true
int countMatches String str, String sub
str중에 sub가 포함되어있는 갯수를 반환한다
String defaultString String str
str이 null이면 ""를 반환하고 아니면 str을 반환한다
String defaultString String str, String defaultStr
str이 null이면 defaultStr을 반환하고 아니면 str을 반환한다
String deleteSpaces String str
deprecated
String deleteWhitespace String str
문자열중 공백문자가 있으면 모두 제거한다
String difference String str1, String str2
str1과 str2를 비교하여 다른부분을 반환한다 (str2의 부분을 반환)
boolean equals String str1, String str2
str1이 null이면 str2가 null인지 유무를 반환하고 str1이 null이 아니면 str1과 str2의 equals를 반환
boolean equalsIgnoreCase String str1, String str2
equals와 동일하며 대소문자를 무시하고 비교한다
String escape String str
deprecated
String getChomp String str, String sep
deprecated
String getNestedString String str, String tag
deprecated
String getNestedString String str, String open, String close
deprecated
String getPrechomp String str, String sep
deprecated
int indexOf String str, char searchChar
str에서 첫번째 searchChar의 인덱스를 반환한다
int indexOf String str, char searchChar, int startPos
str의 startPos 인덱스부터 첫번째 searchChar의 인덱스를 반환한다
int indexOf String str, String searchStr
str에서 첫번째 searchStr의 인덱스를 반환한다
int indexOf String str, String searchStr, int startPos
str의 startPos 인덱스로부터 첫번째 searchStr의 인덱스를 반환한다
int indexOfAny String str, char searchChars[]
str에서 searchChars중 포함하고 있는 문자의 첫번째 인덱스를 반환한다
int indexOfAny String str String searchChars
str에서 searchChars중 포함하고 있는 문자열의 첫번째 인덱스를 반환한다
int indexOfAny String str, String searchStrs[]
str에서 searchStr중 포함하고 잇는 문자열의 첫번째 인덱스를 반환한다
int indexOfAnyBut String str char searchChars[]
str에서 searchChars중 포함되지 않은 문자 첫번째 인덱스를 반환한다
int indexOfAnyBut String str, String searchChars
str에서 searchChars중 포함되지 않은 문자 첫번째 인덱스를 반환한다
int indexOfDifference String str1, String str2
str1과 str2를 비교하여 문자열이 틀려지기 시작하는 인덱스를 반환한다
boolean isAlpha String str
문자열이 모두 Character.isLetter 이면 true (모두 문자이면 true)
boolean isAlphanumeric String str
문자열이 모두 Character.isLetterOrDigit 이면 true (문자거나 숫자이면 true)
boolean isAlphanumericSpace String str
문자열이 모두 Character.isLetterOrDigit 이거나 공백이면 true
boolean isAlphaSpace String str
문자열이 모두 Character.isLetter 이거나 공백문자이면 true
boolean isBlank String str
문자열이 공백문자이거나 길이가 0이거나 null인경우 true
boolean isEmpty String str
문자열이 길이가 0이거나 null인경우 true
boolean isNotBlank String str
문자열이 공백문자도 아니고 길이가 0도 아니고 null도 아니면 true
boolean isNotEmpty String str
문자열이 길이가 0이 아니고 null도 아니면 true
boolean isNumeric String str
문자열이 모두 Character.isDigit 이면 true (모두 숫자이면 true)
boolean isNumericSpace String str
문자열이 모두 Character.isDigit 이거나 공백문자이면 true
boolean isWhitespace String str
문자열이 모두 Character.isWhitespace 이면 true (모두 공백이면 true)
String join Object array[]
array에서 문자열을 읽어와 모두 연결시킨다
String join Object array[], char separator
array에서 문자열을 읽어와 separator를 구분자로 연결시킨다
String join Object array[], String separator
array에서 문자열을 읽어와 separator를 구분자로 연결시킨다
String join Iterator iterator, char separator
iterator에서 문자열을 읽어와 separator를 구분자로 연결시킨다
String join Iterator iterator, String separator
iterator에서 문자열을 읽어와 separator를 구분자로 연결시킨다
int lastIndexOf String str, char searchChar
str에서 마지막 searchChar의 인덱스를 반환한다
int lastIndexOf String str, char searchChar, int startPos
str의 startPos 인덱스부터 마지막 searchChar의 인덱스를 반환한다
int lastIndexOf String str, String searchStr
str에서 마지막 searchStr의 인덱스를 반환한다
int lastIndexOf String str, String searchStr, int startPos
str의 startPos 인덱스부터 마지막 searchStr의 인덱스를 반환한다
int lastIndexOfAny String str, String searchStrs[]
str에서 searchStr의 문자열들중 포함하고 있는 문자열의 마지막 인덱스를 반환한다
String left String str, int len
str의 좌측에서 len 길이만큼 문자열을 구한다
String leftPad String str, int size
str의 길이가 size가 되도록 문자열 왼쪽에 ' '을 추가한다
String leftPad String str, int size, char padChar
str의 길이가 size가 되도록 문자열 왼쪽에 padChar를 추가한다
String leftPad String str, int size, String padStr
str의 길이가 size가 되도록 문자열 왼쪽에 padStr을 추가한다
String lowerCase String str
str을 소문자로 변환한다
String mid String str, int pos, int len
str의 pos 인덱스부터 len 길이만큼의 문자열을 구한다
String overlay String str, String overlay, int start, int end
str의 start부터 end까지overlay로 변환한다
String overlayString String text, String overlay, int start, int end
deprecated
String prechomp String str, String sep
deprecated
String repeat String str, int repeat
str을 repeat만큼 반복하여 반환한다
String replace String text, String repl, String width
text에서 모든 repl을 width로 변환한다
String replace String text, String repl, String width, int max
text에서 모든 repl을 width로 변환하는데 최대 max개만큼 변환한다
String replaceChars String str, char searchChar, char replaceChar
str에서 searchChar를 replaceChar로 모두 변환한다
String replaceChars String str, String searchChars, String replaceChars
str에서 searchChars를 replaceChars로 모두 변환한다
String replaceOne String text, String repl, String width
text에서 repl를 width로 변환하는데 첫번째 하나만 변환한다
String reverse String str
문자열을 앞뒤 순서를 바꾼다
String reverseDelimited String str, char separatorChar
separatorChar를 구분으로 문자열을 나눈 후 나눠진 단어들을 역순으로 바꾼다
String reverseDelimitedString String str, String separatorChars
deprecated
String right String str, int len
str의 len길이만큼 우측에서 문자열을 구한다
String rightPad String str, int size
str의 길이가 size가 되도록 문자열 오른쪽에 ' '을 추가한다
String rightPad String str, int size, char padChar
str의 길이가 size가 되도록 문자열 오른쪽에 padChar를 추가한다
String rightPad String str, int size, String padStr
str의 길이가 size가 되도록 문자열 오른쪽에 padStr을 추가한다
String[] split String str
공백문자를 구분자로 사용하여 분리한다
String[] split String str, char separatorChar
separatorChar를 구분자로 사용하여 분리한다
String[] split String str, String separatorChars
separatorChars를 구분자로 사용하여 분리한다
String[] split String str, String seperatorChars, int max
separatorChars를 구분자로 사용하여 분리한며 최대 max개 만큼한다. 배열의 크기는 max가 된다
String strip String str
문자열 좌우에 있는 공백문자를 제거한다 trim과 동일하다
String strip String str, String stripChars
문자열 좌우에 stripChars에 존재하는 문자를 제거한다
String[] stripAll String strs[]
배열에 있는 모든 문자열 좌우에 있는 공백문자를 제거한다
String[] stripAll String strs[], String stripChars
배열에 있는 모든 문자열 좌우에 stripChars에 존재하는 문자를 제거한다
String stripEnd String str, String stripChars
문자열 우측에만 strip 한다
String stripStart String str, String stripChars
문자열 좌측에만 strip 한다
String stripToEmpty String str
str이 null이면 ""를 반환하고 아니면 strip 한다
String stripToNull String str
str이 null이면 null을 반환하고 아니면 strip 한다
String substring String str, int start
str의 start 인덱스부터 문자열을 구한다
String substring String str, int start, int end
str의 start 부터 end 인덱스 까지 문자열을 구한다
String substringAfter String str, String separator
str의 처음 separator 부분부터 문자열을 구한다
String substringAfterLast String str, String separator
str의 마지막 separator부분부터 문자열을 구한다
String substringBefore String str, String separator
str의 처음 separator 부분까지 문자열을 구한다
String substringBeforeLast String str, String separator
str의 마지막 separator부분까지 문자열을 구한다
String substringBetween String str, String tag
str에서 tag 사이에 있는 문자열을 구한다
String substringBetween String str, String open, String close
str에서 open부터 close 까지 사이에 있는 문자열을 구한다
String swapCase String str
대문자는 소문자로 변환하고 소문자는 대문자로 변환한다
String trimToNull String str
str이 null이거나 length가 0이면 null을 반환하고 그렇지 않으면 좌우 공백문자를 제거한다
String trim String str
문자열 좌우 공백문자를 제거한다
String trimToEmpty String str
str이 null이면 ""를 반환하고 그렇지 않으면 좌우 공백문자를 제거한다
String uncapitalise String str
deprecated
String uncapitalize String str
문자열의 첫문자를 소문자로 변환한다
String upperCase String str
str을 대문자로 변환한다

 

사용법

모두 static 함수이기때문에 다음과 같이 사용하면 됩니다.

String text = StringUtils.replace(str, repl, width);

 

자료만들면서 정리한 엑셀 첨부 합니다 ^^

 

=============================================

본문서는 자유롭게 배포/복사 할수 있지만

이문서의 저자에 대한 언급을 삭제하시면 안됩니다

저자 : GoodBug (unicorn@jakartaproject.com)

최초 : http://www.jakartaproject.com 

=============================================

자바 주석에 본이이 할일 또는 해야할일을 미리 정의한다.!!
 이클립스 에서 
// TODO: 구현하세요 타이핑한뒤 메뉴의 Window - Show View -> Tasks
보면 할일 이 나타난다.


TODO: 뭔가 해야 할 작업을 기록한다. 일반적으로 많이 쓰는 듯 하다. 
FIXME: 이 코드에는 문제가 있거나 개선해야 할 사항이 있다. 수정을 해야 하는걸 마크 
BUG: 이 코드엔 버그가 존재한다. 수정필요
SEE: 명시된 다른 코드를 참조하라는 마크 
XXX: 뭔가 해야 할 작업을 기록하는 것이지만 TODO가 타인과 함께 작업하며 보여주기 위한 성향이 있는 반면 이 마크는 자신이 보기 위한 의미가 더 강하다고(?) 한다.