이 주제는 일괄처리 데이터 스트림(BDS) 프레임워크를 사용하는
방법의 예를 보여줍니다.
시작하기 전에
사용할 올바른 패턴을 식별하십시오. 사용자가 필요한 데이터 스트림의
유형을 바탕으로 패턴을 선택하십시오. 예를 들어, 파일에서 텍스트를 읽으려는
경우 FileReaderPattern을 선택하십시오. 패턴 선택에 대해서는
일괄처리 데이터 스트림 프레임워크 및 패턴의 내용을 참조하십시오.
프로시저
- 패턴 인터페이스를 구현하십시오.
<codeblock>package com.ibm.websphere.samples;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Properties;
import com.ibm.websphere.batch.devframework.configuration.BDSFWLogger;
import com.ibm.websphere.batch.devframework.datastreams.patternadapter.FileReaderPattern;
// Implement the FileReaderPattern
public class TransactionListStream implements FileReaderPattern {
private Properties properties;
private BDSFWLogger logger;
/**
Save properties specified in the xJCL
*/
public void initialize(Properties props) {
// create logger
logger = new BDSFWLogger(props);
if (logger.isDebugEnabled())
logger.debug("entering TransactionListInputStream.initialize()");
properties = props;
}
// This method is where you should add the business logic of processing the read //string
public Object fetchRecord(BufferedReader reader) throws IOException {
String str = null;
Posting posting = null;
if (logger.isDebugEnabled())
logger.debug("Entering TransactionListInputStream.fetchRecord");
if(reader.ready()) {
str = reader.readLine();
}
if(str != null) {
posting = _generateRecord(str);
}
if (logger.isDebugEnabled())
logger.debug("Exiting TransactionListInputStream.fetchRecord with " + posting);
return posting;
}
// Helper method that parses the read string and creates an internal object for use
// by other parts of the code
private Posting _generateRecord(String str) {
Posting post = null;
String [] tokens = str.split(",", 3);
if(tokens.length == 3) {
String txTypeStr = tokens[0];
String actNoStr = tokens[1];
String amtStr = tokens[2];
int txType = Integer.parseInt(txTypeStr);
double amt = Double.parseDouble(amtStr);
post = new Posting(txType,actNoStr,amt);
} else {
logger.error("Invalid csv string" + str);
}
if(logger.isDebugEnabled())
logger.debug("Loaded posting record " + post);
return post;
}
public void processHeader(BufferedReader reader) throws IOException {
// NO OP for this sample
}
}
</codeblock>
- xJCL에서의 지원 클래스와 함께 이전 단계에서
작성한 클래스를 참조하십시오.
xJCL 예
<codeblock><batch-data-streams>
<bds>
<logical-name>txlististream</logical-name>
<props>
<prop name="IMPLCLASS" value= "com.ibm.websphere.samples.TransactionListStream"/>
<prop name="FILENAME" value="/opt/inputfile.txt"/>
<prop name="debug" value="true"/>
</props>
<impl-class> com.ibm.websphere.batch.devframework.datastreams.patterns.TextFileReader </impl-class>
</bds>
</batch-data-streams>
</codeblock>
다음에 수행할 작업
애플리케이션을 설치하십시오.