<c:choose>
                <c:when test="${fn:length(list) > 0}">
                    <c:forEach items="${list}" var="row">
                        <tr>
                            <td>${row.ID}</td>
                        </tr>
                    </c:forEach>
                </c:when>
                <c:otherwise>
                    <tr>
                        <td colspan="4">no data</td>
                    </tr>
                </c:otherwise>
            </c:choose>


데이터 조회해오고 화면에 뿌려줄때 쓰는 jstl문법입니다.



'Programming > Spring' 카테고리의 다른 글

spring 사용이유?  (0) 2018.05.14
event.preventDefault() / event.stopPropagation()  (0) 2018.05.13
jQuery 간단 사용법  (0) 2018.05.13
IOC / DL / DI  (0) 2018.05.13
Spring Framework  (0) 2018.05.12

ajax

$.ajax({
                url: "/sample/board_list/next_page",
                type: "GET",
                data: param,
                success: function(data){
                   
                ...
                   
                },
                error: function(request, status, error){
                    console.log(error)
                }
            });


id="list" 자식 태그 제거하기

$("#list").empty();


id="list" 에 a추가하기

$("#list").append(a);



클릭 이벤트 정의

$("#write").on("click", function(e) {
         fn();
});


만약 자바스크립트로 동적으로 html을 만들었다면 위의 이벤트 정의가 먹히지 않는다. 이유는 해당 html이 그려지고 난다음 jQuery가 정의되는데 이벤트를 정의한 id가 삭제되면 jQuery는 연결되어있는 연결고리가 없어지게 된다. 이는 이후에 같은 아이디를 만들어도 연결되지 않는 다는 것을 뜻한다. 그렇기 때문에 아래와 같은 방법을 사용해야한다.

 

$(document).on("click","#write", function(e) { //제목
         fn();
});



a태그중 name이 page인

"a[name='page']" 친구들을 정의한다.


this는 js의 this로 현재 태그를 받아온다.

$(this) jQuery의 this로 this의 객체형이다. parent()를 사용해서 부모태그를 얻을 수 있다.



val() / text() / html()

val()은 textarea의 값을 받아올때 쓰인다.

text() / html()는 자바스크립트의 innerHTML()처럼 쓰인다.



jstl로 받아온값을 자바스크립트 변수로 담는법

total_page_cnt = <c:out value="${page}"/>;


'Programming > Spring' 카테고리의 다른 글

event.preventDefault() / event.stopPropagation()  (0) 2018.05.13
jstl 간단 사용법  (0) 2018.05.13
IOC / DL / DI  (0) 2018.05.13
Spring Framework  (0) 2018.05.12
CRUD구현하기 - Back end  (0) 2018.02.16

IOC(Inversion of control)

자바가 등장하고 자바 기반으로 애플리케이션을 개발하기 시작하던 최초의 시기에는 자바 객체를 생성하고 객체간의 의존관계를 연결시키는 등의 제어권을 개발자가 직접 가지고 있었다.

그러나 서블릿, EJB가 등장하면서 개발자들이 가지고 있던 제어권과 객체의 생명주기를 관리 하는 권한이 서블릿과 EJB를 관리하는 컨테이너에게 넘어갔다.

이처럼 객체의 생성에서부터 생명주기의 관리까지 모든 객체에 대한 제어권이 바뀐것을 의미하는 것이 제어권의 역전, 즉 IoC라는 개념이다.


DL(Dependency Lookup)

IoC 컨테이너는 각 컨테이너에서 관리해야 하는 객체들을 관리하기 위한 별도의 저장소를 가지게 되는데,

이 IoC컨테이너가 관리중인 객체 저장소(Pool)에서 객체를 검색하여 참조하는 방법이다.

(컨테이너에서 제공하는 api를 이용하여 찾고자 하는 bean을 lookup하는 방법)


DI(Dependency Injection)

Spring에서 새롭게 지원하는 IoC의 한 형태로써 각 계층 사이, 각 Class 사이에 필요로 하는 의존관계가 있다면 이를 컨테이너가 자동적으로 연결시켜 주는 것(@Autowired, @Qualifier)으로 각 Class 사이의 의존관계를 Bean 설정 정보를 바탕으로 컨테이너가 자동적으로 연결해 주는 것이다.


외부에서 객체를 생성후 주입시켜주게 되면 두 객체사이에 약한 결합으로 형성되게 된다.

그러나 내부에서 new를 사용하여 객체를 생성하게되면 두 객체사이에 강한 결합으로 형성이 된다.

강한 결합으로 생성시 객체에대한 의존성이 강해지므로 객체의 교체가 어렵게 된다..

반면 약한 결합으로 객체를 생성한다면 의존성이 약해지므로 객체를 쉽게 교체할 수 있게된다.


DI의 종류로는 Setter Injection, Constructor Injection, Method Injection이 있다.


Setter Injection - Class 사이의 의존관계를 연결시키기 위해 Setter() 메소드를 이용하는 방법.
Constructor Injection - Class 사이의 의존관계를 연결시키기 위해 생성자를 이용하는 방법.
Method Injection - Method Injection은 Setter Injection과 Constructor Injection이 가지고 있는 한계점을 극복하기 위하여 지원하고 있는 DI의 한 종류다. Singleton 인스턴스와 Non Singleton 인스턴스의 의존관계를 연결할 필요가 있을 때 사용한다.




'Programming > Spring' 카테고리의 다른 글

jstl 간단 사용법  (0) 2018.05.13
jQuery 간단 사용법  (0) 2018.05.13
Spring Framework  (0) 2018.05.12
CRUD구현하기 - Back end  (0) 2018.02.16
CRUD 구현하기 - front end  (0) 2018.02.16

1.  Spring Framework란?
부품을 조립해주는 라이브러리(lib)로 라이브러리가 모이면 framework(재사용하는 틀)이 된다.
요구명세서(목록)만 주면 객체도 생성하고 조립까지 해준다.




 2. Spring Framework의 장점
- 경량 컨테이너
전체 스프링의 크기는 1MB 남짓 한 하나의 JAR파일 및 스프링에 의해 발생하는 부하는 무시해도 되는 수준
객체의 라이프 사이클 관리, JAVA EE 구현을 위한 다양한 API 제공
- DI(Dependency Injection), AOP(AspectOriented Programming),
POJO(Plain Old Java Object) 지원
- 다양한 API와의 연동 지원을 통한 JAVA EE 구현 가능
3. Spring Framework의 주요 특징
- DI(의존성 주입) / AOP(관점지향) / MVC(JDBC 코딩)
- 통합(struts, spring, mybatis, hibernate)
- Transation / IOC(제어의 역행, 역제어)



'Programming > Spring' 카테고리의 다른 글

jQuery 간단 사용법  (0) 2018.05.13
IOC / DL / DI  (0) 2018.05.13
CRUD구현하기 - Back end  (0) 2018.02.16
CRUD 구현하기 - front end  (0) 2018.02.16
Ajax  (0) 2018.02.15

MapReduce연산이 진행되는 DataFlow에 대해 살펴 보겠습니다.




1. Input Files

MapReduce Task를 위한 데이터는 inputFile에 저장되어 있습니다. 그리고 이 input file은 HDFS에 저장 되어있습니다. 이 파일의 포맷은 임시적이며, line-based log files 과 binary format 을 사용할 수 있습니다.


2. InputFormat

InputFormat은 input file이 어떻게 분할되고 어떻게 읽어지는 가를 정의합니다.

Hadoop의 Job은 Map task와 Reduce task로 나누어집니다.


그리고 이 task들은 Yarn에 의해 스케쥴링되고 클러스터안의 노드위에서 실행됩니다. 만약 task가 fail되면 자동으로 다른 노드로 rescheduling합니다.


InputFormat은 입력을 위해서 파일이나 다른 객체를 선택하여 getSplits()를 통하여 List<inputSplit>을 생성합니다. inputSplit를 Application Master에 전달하면 Map Task가 createRecordReader()를 실행시켜 RecordReader를 만듭니다.

Hadoop은 각각의 Split마다 하나의 MapTask를 생성하게 되는데, MapTask는 Split을 각각의 record로 나누어 사용자 정의 map Function을 적용합니다.

2.1. InputSplits

inputSplit은 inputFormat에 의해 생성되며, 데이터를 각각의 Mapper에 맞는 논리 형식으로 분할합니다. 예를들어서 HDFS의 File size는 128MB인데, 파일크기가 150MB라면 Block을 2개 읽어와서 논리적으로 시작과 끝을 지정합니다.


2.2. RecordReader

InputSplit에서 분할된 레코드들을 Mapper에 적합한 Key-Value쌍으로 변환합니다. 기본적으로 TextInputFormat를 사용하여 Key-Value쌍으로 변환합니다. InputFormat은 기본적으로 TextInputFormat를 지원하는데, TextInputFormat은 text file을 읽을때 \n까지를 한줄로 인식하고 한줄 단위로 Split을 만드는 기능을 합니다.

그리고 Record Reader은 InputSplit에서 유니크한 수인 byte offset을 키로하고, 각 라인을 value로 해서 하나의 새로운 Key-Value쌍을 만듭니다. 그리고 이 Key-Value쌍을 Data Processing을 위한 Mapper로 전송하게 됩니다.


3. Mapper

RecordReader를 통해서 입력된 record를 완전히 새로운 Key-Value쌍으로 만드는 프로세스 입니다. Mapper의해 발생된 출력은 HDFS에 바로 저장되지 않고 임시 데이터로 저장이고, 이 출력은 곧 Combiner에 입력으로 들어가게됩니다.

4. Combiner

‘Mini-reducer’라고 알려져 있는 Combiner는 Mapper의 출력을 local에서 Reduce를 처리합니다. local에서 각각에 대하여 reduce연산을 수행하게 되면 이후 진행되는 shuffling이나 Sorting Reducer작업을 위해 데이터를 전송할때 생기는 부하를 줄여주는 효과가 있습니다.

5. Shuffling and Sorting

Reduce에 입력으로 주기위해 Map연산이 끝난 데이터를 Reduce연산에서 생기는 네트워크 트래픽을 최소화 하기 위해서 Sorting하고 같은것으로 모으는 작업입니다.


6. Reducer

Mapper에 의해 생성된 key-Value쌍을 가지고 각각의 reduce연산을 통하여 최종 결과물을 출력합니다. 이 최종결과물은 HDFS에 저장됩니다.

7. RecordWriter

Reduce 연산이 끝난 Key-Value쌍을 출력 파일에 씁니다.

8. OutputFormat

OutputFormat에 의해 결정된 RecordWrite가 출력된 Key-Value쌍을 file에 씁니다. OutputFormat instances은 HDFS또는 그 local disk가 사용하는 하둡에의해 제공됩니다. reducer의 최종 출력은 OutputFormat instances에 의해 HDFS에 저장됩니다.


'Hadoop ecosystem > MapReduce' 카테고리의 다른 글

WordCount  (0) 2018.04.14
Indexing  (0) 2018.04.14
InputType  (0) 2018.04.14
MapReduce 3  (1) 2018.04.09
MapReduce프로그래밍을 위한 HL  (0) 2017.05.04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 
public class WordCount {
    
    public static class TokenizerMapper
        extends Mapper<Object, Text, Text, IntWritable>//KeyIn, ValueIn, KeyOut, ValueOut 
 
        //IntWritable : Integer형이면서 Writable, Comparable한 자료형
        private final static IntWritable one = new IntWritable(1);
 
        private Text word = new Text();
                        //KeyIn, ValueIn
        
        /*
        On the top of the Crumpetty Tree
        The Quangle Wangle sat,
        But his face you could not see,
        On account of his Beaver Hat.
        (0, On the top of the Crumpetty Tree)
        (33, The Quangle Wangle sat,)
        (57, But his face you could not see,)
        (89, On account of his Beaver Hat.)
        */
        
        public void map(Object key, Text value, Context context)  
                        //{ byte단위 offset, String, Context }
                            throws IOException, InterruptedException {
 
        //value를 " " 단위로 Tokenizing한다.
        StringTokenizer itr = new StringTokenizer(value.toString());
 
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                
                //KeyOut, ValueOut
                context.write(word, one);
            }
 
        }
    }
    public static class IntSumReducer
                extends Reducer<Text, IntWritable, Text, IntWritable> { //KeyIn, ValueIn, KeyOut, ValueOut 
 
    private IntWritable result = new IntWritable();
 
                        //KeyIn, ValueIn
    public void reduce(Text key, Iterable<IntWritable> values, Context context
                        ) throws IOException, InterruptedException {
            int sum = 0;
            
            for (IntWritable val : values) {
                sum += val.get();
            }
            
            result.set(sum);
            
            //KeyOut, ValueOut 
            context.write(key, result);
        }
    }
 
    public static void main(String[] args) throws Exception {
        
        //initialize configuration
        Configuration conf = new Configuration();
 
        //create Job Instance
        Job job = Job.getInstance(conf, "word count");
        job.setJarByClass(WordCount.class);
        
        //Setting Classes using Job Instance
        job.setMapperClass(TokenizerMapper.class);
 
        //같은 노드내에서 reduce작업을 수행함으로써 전송되는 데이터의 갯수를 줄인다.
        job.setCombinerClass(IntSumReducer.class);
 
        //input은 shuffle을 통해 각 노드에서 key별로 (key,[1,2,3,1,1,2])가 된 상태
        job.setReducerClass(IntSumReducer.class);
 
        //job을통해 최종 Output될 클래스 세팅
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        
        //해당 경로를 job의 configuration.mapred.input.dir에 넣어준다.
        FileInputFormat.addInputPath(job, new Path(args[0]));
        
        //Output dir을 설정한다.
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
 
        //excute the Application
        //Blocking Function(실행이 완료될때 까지 return되지않음)
        //Submit the job, then poll for progress until the job is complete
        System.exit(job.waitForCompletion(true) ? 0 : 1);
        
        //Job이 실행되면 내부적으로 InputSplit과 RecoreReader를 실행해서 
        //Map에 적합한 {Key,Value}쌍을 만든다.
    }
}
 
cs





Sample text-files as input:


$ bin/hadoop fs -ls /user/joe/wordcount/input/

/user/joe/wordcount/input/file01

/user/joe/wordcount/input/file02


$ bin/hadoop fs -cat /user/joe/wordcount/input/file01

Hello World Bye World


$ bin/hadoop fs -cat /user/joe/wordcount/input/file02

Hello Hadoop Goodbye Hadoop


Run the application:

$ bin/hadoop jar wc.jar WordCount /user/joe/wordcount/input /user/joe/wordcount/output


Output:


$ bin/hadoop fs -cat /user/joe/wordcount/output/part-r-00000

Bye 1

Goodbye 1

Hadoop 2

Hello 2

World 2


'Hadoop ecosystem > MapReduce' 카테고리의 다른 글

DataFlow  (0) 2018.04.14
Indexing  (0) 2018.04.14
InputType  (0) 2018.04.14
MapReduce 3  (1) 2018.04.09
MapReduce프로그래밍을 위한 HL  (0) 2017.05.04

Indexing은 조회쿼리에 대한 연관문서를 빠르게 찾기위해 사용한다.


Inverted index

각 단어가 존재하는 문서번호를  저장하고 있는 인덱스
Inverted Index
WordDocuments
theDocument 1, Document 3, Document 4, Document 5, Document 7
cowDocument 2, Document 3, Document 4
saysDocument 5
mooDocument 7

검색하고자 하는 단어가 입력되었을때, 해당문서에 단어가 존재하는지 안하는지 만을 알수있다.


The forward index

문서에 존재하는 각 단어들을 저장하고 있는 인덱스
Forward Index
DocumentWords
Document 1the,cow,says,moo
Document 2the,cat,and,the,hat
Document 3the,dish,ran,away,with,the,spoon


'Hadoop ecosystem > MapReduce' 카테고리의 다른 글

DataFlow  (0) 2018.04.14
WordCount  (0) 2018.04.14
InputType  (0) 2018.04.14
MapReduce 3  (1) 2018.04.09
MapReduce프로그래밍을 위한 HL  (0) 2017.05.04

Mapper를 호출하기전에 일반 텍스트파일을 Key Value 값으로 맞춰줘야한다. 그러기 위해서 InputFormat을 맞춰주는 전처리 작업이 필요하다. 이를위해서 MapReduce는 2가지 방법을 제공해주고있다.


TextInputFormat


입력값이 일반텍스트일때, 라인단위로 쪼갠다. Key는 파일의 라인수가되고, Values는 해당라인의 텍스트가 된다


참조 : https://hadoop.apache.org/docs/r2.7.5/api/org/apache/hadoop/mapred/TextInputFormat.html

KeyValueTextInputFormat

입력값이 일반텍스트일때,  파일을 라인단위로 쪼개는데, 특정 구분자를 기준으로 쪼갠다. 만약 해당구분자가 존재하지않는경우 value는 빈값으로 리턴한다. 


참조 : https://hadoop.apache.org/docs/r2.7.5/api/org/apache/hadoop/mapred/KeyValueTextInputFormat.html

'Hadoop ecosystem > MapReduce' 카테고리의 다른 글

WordCount  (0) 2018.04.14
Indexing  (0) 2018.04.14
MapReduce 3  (1) 2018.04.09
MapReduce프로그래밍을 위한 HL  (0) 2017.05.04
MapReduce 2  (0) 2017.05.03

+ Recent posts