달력

3

« 2024/3 »

  • 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
2010. 4. 7. 15:35

Spring Batch sample source [일부] I.lib()/I.lib(S.Batch)2010. 4. 7. 15:35

.. .. ..

Sample Name

분석 여부

필요 기간

기타

skip

O

-

 

retry

O

-

 

restart

O

-

 

automatic-mapping

O

-

 

asynch launch

X

2 day

 

validation

O

-

 

delegation

O

-

 

write behind

X

1/2 day

 

non-sequential

X

1/2 day

loof Flow와 동일.

asynch process

X

2 day

 

filtering

O

-

 

delimited input

O

-

 

fixed-length input

O

-

 

xml input

O

-

 

db paging input

X

1/2 day

 

db cursor input

X

1/2 day

 iBatis는 포함안됨

delimited output

O

-

 

fixed-length output

O

-

 

xml output

O

-

 

db output

O

-

 

multiple files

X

1/2 day

 

multi-line

X

1/2 day

 

multi-record

X

1 day

 



 

Multi-thread Step (asynch process)

<job id="basic_Sample" xmlns="http://www.springframework.org/schema/batch">

          <split id="split1" task-executor="taskExecutor" next="addr">

                      <flow>

                           <step id="wbras_bsid_1-1" next="dong_1-2"/>

                           <step id="dong_1-2"/>

                </flow>

                      <flow>

                           <step id="wbras_bsid_2-1" next="dong_2-2"/>                                                  <step id="dong_2-2"/>

                </flow>

     </split>

     <step  id=”addr”>

     </step>

</job>

 

위의 예제같이 흐름이 그려진다면  wbras_bsid_1-1 wbras_Bsid_2-1이 같이실행되며 스레드 구조로 다음 스텝들을 서로의 플로어(flow) 안에서 실행이 된다.
각각의 플로어가 종료되면 split1에서 설정한 next=”addr” 로 인해 step addr로 이동하며 실행하게 된다.
기타사항으로는 플로어중 exception이 있는 플로어는 실행도중 종료되며 다른 플로어는 계속 실행을 하게된다. 하지만 split안의 플로어중 exception이 일어났을경우는 다음 스텝으로 가지 못하고 fail이 된다. (skip , retry 설정으로 극복

 


 

Multi-record

n  Read된 값들의 종류에 따라 record되는 값이 달라진다.

if (item instanceof Trade) {

        return this.tradeLineAggregator.aggregate((Trade) item);

}

else if (item instanceof CustomerCredit) {

        return this.customerLineAggregator.aggregate((CustomerCredit) item);

}

else {

        throw new RuntimeException();

}                 

라인 어그리에이터의 소스 부분의 모습이다. 받아온 item의 타입에 따라 사용되는 어그리에이터가 달라지는 것이다
 




Multi-line

public Trade read() throws Exception {

Trade t = null;

           for (FieldSet line = null; (line = this.delegate.read()) != null;) {

                      String prefix = line.readString(0);

                     if (prefix.equals("BEGIN")) {

                                t = new Trade(); // Record must start with 'BEGIN'

                     }

                     else if (prefix.equals("INFO")) {

                                Assert.notNull(t, "No 'BEGIN' was found.");

                                t.setIsin(line.readString(1));

                                t.setCustomer(line.readString(2));

                     }

                     else if (prefix.equals("AMNT")) {

                                Assert.notNull(t, "No 'BEGIN' was found.");

                                t.setQuantity(line.readInt(1));

                                t.setPrice(line.readBigDecimal(2));

                     }

                     else if (prefix.equals("END")) {

                                return t; // Record must end with 'END'

                     }

           }

           Assert.isNull(t, "No 'END' was found.");

           return null;

}

ItemReader 부분이다. Read 해서 FieldSet으로 나눠서 나오는 첫번째 값에따라 반환값이 달라진다.

begin일땐 새로 생성하고 info 일땐 값을 입력하고 amnt일땐 다른 값을 입력한다. 이들은 다 리턴을 널값으로 보내준다. 오직 end 값일때만 만들어진 Trade를 리턴해준다. 

요약하면 여러라인 받아놓고 반환 라인 타이밍을 조절하는 것이 Multi-line이다.

 

Multi-file

<bean id="itemReaderForTest" parent="itemReaderParent">

     <property name="resources" value="classpath:data/ /input/delimited*.csv" />

</bean>


이런 식의 빈설정으로 resources는 여러 개의 리소스 값들을 받아온다. 이를 setresources할 때 값은

private Resource[] resources;
이런식으로 배열로 들어가게 된다. 이후 안에 있는값들은 JAVA로 만든 핸들러를 통해 사용된다.


 

Paging query

<bean id="addr_paging_query " class="Infrastructure.read.IbatisPagingItemReader">

<property name="sqlMapClient" ref="sqlMapClient"/>

           <property name="queryId" value="getselect_addr"/>

           <property name="pageSize" value="10000"/>

</bean>


ibatisPagingItemReader
라는 클레스는 원하는 pagesize만큼 read 해서 처리하는 구조이다. Ibatis fetchsize와 비슷한 개념이지만 bean 상태에서 configuration 할수 있다는 장점이 있다. 참고로 batch에서 제공하는 소스상에는 limit 0부터 시작하는데 이것은 Mysql의 구조이기 때문에 limit 1부터 시작하는 altibase와는 맞지 않다. 해서 소스의 변경이 필요하다.

 



 

      synch launch

     <bean id="jobLauncher"
        class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
       <property name="jobRepository" ref="jobRepository" />
       <property name="taskExecutor">
           <bean             
                 class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
       </property>
</bean> 


이와 같이 레퍼런스에 나와있다. http 의 요청으로 launch의 실행시간이 길어지면 다른 작업을 할수 없기때문에 taskExecutor를 사용한다고 나와있다.
ExitStatus 값은 종료되지 않고 thread 상태가 되기때문에 UNKNOWN 상태가 되며 작업은 백그라운드로 실행되게 된다.


 

 

'I.lib() > I.lib(S.Batch)' 카테고리의 다른 글

SqlMapClient 와 SqlMapClientTemplate  (0) 2010.04.19
Spring_Batch_v1.1.2  (2) 2010.03.16
Spring Batch Operator 사용법에 관한 글  (3) 2010.03.04
.
:
Posted by .07274.