private List<String> getDuplicateList(List<String> duplicateList) {

        TreeSet<String> treeSetList = new TreeSet<String>();

        List<String> retList = new ArrayList<String>();

        for (String dupl : duplicateList) {

            treeSetList.add(dupl);

        }

        Iterator<String> it = treeSetList.iterator();

        while(it.hasNext()) {

            retList.add(it.next());

        }

        return retList;

    }




코드란게 한달짜고 버릴때도 있고 일주일 짜고 폐기 될때도 있지만


그래도 짜놓은게 아까워서 폐기코드를 저장해놓음..


서버에 존재하지 않는 블럭(404)의 연속된 순서에 많은 부분의 절반부터 Sequence를 부여하는 부분


(멀티 업로드 시 협업을 위함)



    /**

     * Set Block Sequence

     * <p>

     * 

     * @author YM,Jung

     * @date 2013. 12. 10.

     * @param blockHashRefList

     * @param notFoundBlockSeqList

     * @return

     */

    private void setBlockRefSequence(List<BlockHashRef> blockHashRefList, List<Integer> notFoundBlockSeqList) {

        Iterator<Integer> blockSeqIter = getUploadBlockSequence(notFoundBlockSeqList, blockHashRefList.size());


        for (Integer notFoundBlockSeq : notFoundBlockSeqList) {

            if (blockSeqIter.hasNext()) {

                //sequence. or sort.

                blockHashRefList.get(notFoundBlockSeq).setSequence(blockSeqIter.next());

            }

        }

    }


    /**

     * 업로드 지점 정해줌. 처음 업로드의 경우 블럭의 처음 반환

     * <p>

     * (0) N번째의 경우 남은 블럭의 반 지점 반환

     * <p>

     * 일반 업로드의 경우 블럭이 업로드 안된 지점부터 끝까지.

     * <p>

     * 

     * @author YM,Jung

     * @date 2013. 12. 10.

     * @param notFoundBlockSeqList

     * @param blockTotalSize

     * @return

     */

    private Iterator<Integer> getUploadBlockSequence(List<Integer> notFoundBlockSeqList, int blockTotalSize) {

        boolean multiUpload = false;

        int returnValue = 0;

        int compare = 0;

        int chainCount = 0;

        int topCount = 0;

        if (notFoundBlockSeqList.size() == blockTotalSize) { // 전체 처음 업로드

            return getSequence(notFoundBlockSeqList, returnValue);

        }

        for (int i = 0; i < notFoundBlockSeqList.size(); i++) {

            // 연속된 수를 구함

            if (compare + 1 == notFoundBlockSeqList.get(i)) {

                chainCount++;

            } else {

                // 연속된 수가 크면 대체.

                if (chainCount > topCount) {

                    topCount = chainCount;

                    returnValue = calculateUploadBlockPointer(chainCount, i);

                    chainCount = 0;

                    multiUpload = true;

                }

            }

            compare = notFoundBlockSeqList.get(i);

        }

        if (multiUpload) {

            if (chainCount > topCount) { // 마지막까지 not found 를 위한 추가.

                returnValue = calculateUploadBlockPointer(chainCount, blockTotalSize);

            }

            return getSequence(notFoundBlockSeqList, returnValue);

        } else {

            // 없는 블럭 차례대로 업로드

            return getSequence(notFoundBlockSeqList, 0);

        }


    }



    private Iterator<Integer> getSequence(List<Integer> notFoundBlockSeqList, int firstSequenceBlock) {

        List<Integer> blockSequenceList = new ArrayList<Integer>();

        int firstSeq = 0;

        // Set first sequence point.

        for (Integer notFoundBlockSeq : notFoundBlockSeqList) {

            if (notFoundBlockSeq == firstSequenceBlock) {

                break;

            } else {

                firstSeq++;

            }

        }


        //Set sequence.

        for (int i = 0; i < firstSeq; i++) {

            blockSequenceList.add(notFoundBlockSeqList.size() - firstSeq + i);

        }

        for (int i = firstSeq; i < notFoundBlockSeqList.size(); i++) {

            blockSequenceList.add(i - firstSeq);

        }

        return blockSequenceList.iterator();

    }



    private int calculateUploadBlockPointer(int chainCount, int blockPointer) {

        int half = chainCount / 2; // 버림.

        return blockPointer - half; //남은 블럭의 반지점.

    }

'java' 카테고리의 다른 글

자바 정규표현식 필터링 Pattern 사용법 예시  (0) 2014.02.04
TreeSet 을 사용한 List<> 중복 제거  (0) 2014.01.06
InputStream을 파일로 저장  (0) 2013.11.01
동일성 동등성 == equals  (0) 2013.05.22
어노테이션 사용  (0) 2013.05.16

간단한 소스이나 메모. 

finally에서 try catch를 한번 더 해줘야 하나.. 소스도 지저분해지고 

개발서버의 경우 risk가 크지 않으므로 생략.

(실서버 또는 민감한 사항을 다루는곳에서는 추가.)


private void writeInputStreamToFile(String fileName, InputStream in) throws IOException {

        OutputStream out = null;

        try {

            out = new FileOutputStream(fileName);


            int read = 0;

            byte[] bytes = new byte[1024];


            while ((read = in.read(bytes)) != -1) {

                out.write(bytes, 0, read);

            }

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            if (out != null) {

                out.close();

            }

            if (in != null) {

                in.close();

            }

        }

        

    }

'java' 카테고리의 다른 글

TreeSet 을 사용한 List<> 중복 제거  (0) 2014.01.06
죽은 코드 저장  (0) 2013.12.12
동일성 동등성 == equals  (0) 2013.05.22
어노테이션 사용  (0) 2013.05.16
리플렉션 메소드 사용, reflection  (0) 2013.05.06

동일성  == 

JVM에 정의된 개념. 두객체는 같은 메모리 위치를 가르키고 있다면 동일하다고 봄.


동등성 .equals(Object object)

등가성이라고 부르기도하며 서로 다른 두 객체가 같은 값을 갖는것을 말함.

'java' 카테고리의 다른 글

죽은 코드 저장  (0) 2013.12.12
InputStream을 파일로 저장  (0) 2013.11.01
어노테이션 사용  (0) 2013.05.16
리플렉션 메소드 사용, reflection  (0) 2013.05.06
java 연산자 기호표  (0) 2012.09.26

메타 어노테이션

@Target

 - 어노테이션을 적용할 대상을 지정

 - ElementType 

CONSTRUCTOR         // 생성자 선언부

FIELD                      // enum포함 필드선언부

LOCAL_VARIABLE     // 지역변수 선언부

METHOD                 // 메소드 선언부

PACKAGE                 // 패키지 선언부

PARAMETER             // 파라메터 선언부

TYPE                     // 클래스, 인터페이스, enum 선언부

@Retention

 - 어노테이션 정보가 보관되는 기간을 지정

 - RetentionPolicy

SOURCE    // 어노테이션이 컴파일러에서 버려짐

CLASS    // 클래스안의 어노테이션은 사용되지만 VM에서는 버려짐

RUNTIME    // VM에서 유지가 되므로 리플렉션으로 활용 가능

@Documented

 - Javadoc에 포함

@Inherited

 - 서브클래스 부모 어노테이션을 상속


활용 Exam


@Target(ElementType.METHOD)

@Retention(RetentionPolicy.RUNTIME)

public @interface Handler {

    String value();

    String name();

}


///


private void base(Handler annotation) {

        Preconditions.checkNotNull(annotation);


        name = annotation.name();

        path = annotation.value();

    }



///


public HttpRequestHandler build(Object obj, Method method) {
        Preconditions.checkNotNull(obj);
        Preconditions.checkNotNull(method);

        base(method.getAnnotation(Handler.class));

        Preconditions.checkNotNull(name);
        Preconditions.checkNotNull(path);
        
        String httpMethod = null;
        
        String upperCaseName = name.toUpperCase();
        if(upperCaseName.startsWith("GET")) {
            httpMethod = "GET";
        } else if(upperCaseName.startsWith("POST")) {
            httpMethod = "POST";
        } else if(upperCaseName.startsWith("PUT")) {
            httpMethod = "PUT";
        } else if(upperCaseName.startsWith("DELETE")) {
            httpMethod = "DELETE";
        }
  HttpRequestHandler handler = new HttpRequestHandler(name, path, httpMethod);
        handler.addArgs(args);
        handler.setRaw(obj, method);
        
        return handler;
    }

Front Controller Pattern.

몇 개의 서블릿이 중앙집중식으로 모든 요청을 다 받아서 처리하는 방식

대표적 - Spring.


초기에는 URL당 하나의 서블릿을 등록, 독립적 기능을 담당하게 함.

처리방식 - 서블릿 선행작업 수행, 요청의 기능을 담당하는 핸들러 클래스 호출


Spring에서는 최소한의 서블릿으로 처리 (프론트 컨트롤러 패턴 적용)

'java > design_pattern' 카테고리의 다른 글

Design Pattern 기본 원칙  (0) 2014.06.18
Builder Pattern  (0) 2014.06.17
Java Beans Pattern  (0) 2014.06.17
Telescoping Pattern  (0) 2014.06.17
디자인패턴 개인 메모.  (0) 2012.03.29

리플렉션 (Reflection)

자바의 코드 자체를 추상화 하여 접근하도록 만들어진 기능, Method.


 
String checkTarget = "Hello";
Method lengthMethod = String.class.getMethod("length");
int checker = (Integer)lengthMethod.invoke(checkTarget);
int compare = checkTarget.length();

---

checker와 compare는 같다.


'java' 카테고리의 다른 글

동일성 동등성 == equals  (0) 2013.05.22
어노테이션 사용  (0) 2013.05.16
java 연산자 기호표  (0) 2012.09.26
can not find the tag library descriptor for http //java.sun.com/jsp/jstl/core  (4) 2012.07.03
Map (String) -> JsonString 변환  (0) 2012.05.09

패키지 생성 -> AbstractJavaSamplerClient 확장(extends) -> 테스트 생성


[생성]

 1) default값을 잘 설정

 2) runTest에 context값 (jmeter에서 입력될 값)으로 테스트 로직을 추가한다.




[배포]

 1) Export -> Runnable JAR -> /ext/lib [copy]

 2) /bin/jmeter.properties 수정 -> remote_hosts=[자기자신IP], [RemoteIP] ','로 구분

(Properties에 설정할 수도 있으나 왠만하면 테스트 PC도 동일한 directory 구조를 추천)

 3) Remote 수행할 PC도 동일한 Path에 jmeter 복사, 설치 (host PC를 그대로 복사를 추천)


[실행]

 1) Thread Group Listener 등록

 2) jmeter-server.bat 실행 (remote대상도 실행)

 3) Run -> Remote Start All 





'java > test' 카테고리의 다른 글

JMeter 테스트 생성  (0) 2014.08.19
GCM 테스트 쉘 스크립트  (0) 2014.05.12
jmeter 테스트 - 생성  (0) 2013.04.15

jmeter : Apache재단의 서버 클라이언트 테스트 프로그램. 일반적으로 스트레스 테스트에 사용.


단순히 jmeter를 다운받아  bin폴더의 jmeterw를 실행 UI 환경으로 테스트를 생성, 사용할수도 있으나 배운게 소스사용 테스트 이므로 소스 사용 테스트를 메모

memo1. 기본설정

New 생성

TestPlan -> Add -> Threads 생성

Thread Properties 설정.

 1) Number of Threads : 테스트에 사용될 Thread 갯수. 

 2) Ramp-Up Period : 동시 생성 시간 (너무 짧으면 무시 또는 누락이 될수 있음)

 3) Loop Count : 테스트 수. ex) 위의 경우 5개의 쓰레드에서 120번 테스트 이므로 120 x 5 = 600. 총 600번의 테스트가 수행.


Threads -> Add -> 해당되는 테스트 선택 (직접 선택해도 되나 샘플러 하나 선택 후 수정을 추천)



'java > test' 카테고리의 다른 글

JMeter 테스트 생성  (0) 2014.08.19
GCM 테스트 쉘 스크립트  (0) 2014.05.12
jmeter 테스트 - JavaRequest, Remote Start  (0) 2013.04.15


연산자 기호를 검색할때는 곤란하다. 검색자에 ! ~ 등을 쳐놓아도 나오지가 않으니.. 나중에 참고할 목적으로 기호표를 퍼놓는다.

찾는 다른사람분 있으면 참고하시길.

혹시나 퍼가실꺼면 아래 출처에 의사를 밝히고 퍼가면 됩니다.

출처 : http://blog.naver.com/PostView.nhn?blogId=chunjae0307&logNo=120124323659

+ Recent posts