importjava.lang.management.ManagementFactory;importjava.lang.management.MemoryMXBean;importjava.lang.management.MemoryUsage;publicbooleanprocessRow(StepMetaInterface smi,StepDataInterface sdi)throwsKettleException{if(first){
first =false;/* TODO: Your code here. (Using info fields)
FieldHelper infoField = get(Fields.Info, "info_field_name");
RowSet infoStream = findInfoRowSet("info_stream_tag");
Object[] infoRow = null;
int infoRowCount = 0;
// Read all rows from info step before calling getRow() method, which returns first row from any
// input rowset. As rowMeta for info and input steps varies getRow() can lead to errors.
while((infoRow = getRowFrom(infoStream)) != null){
// do something with info data
infoRowCount++;
}
*/}MemoryMXBean memoryMXBean =ManagementFactory.getMemoryMXBean();MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();// 获取已使用内存大小(bytes)long usedMemory = heapMemoryUsage.getUsed();// 获取已分配内存大小(bytes)long committedMemory = heapMemoryUsage.getCommitted();// 获取最大内存大小(bytes)long maxMemory = heapMemoryUsage.getMax();Object[] r =getRow();if(r ==null){setOutputDone();returnfalse;}Long limitMemory =Long.parseLong(get(Fields.In,"limitMemory").getString(r));logBasic("kettle已使用内存:"+usedMemory/(1024*1024)+"M");logBasic("kettle已分配内存:"+committedMemory/(1024*1024)+"M");logBasic("kettle最大内存:"+maxMemory/(1024*1024)+"M");if(usedMemory >(limitMemory *1024*1024*1024)){logBasic("垃圾回收,走GC了");System.gc();}// It is always safest to call createOutputRow() to ensure that your output row's Object[] is large// enough to handle any new fields you are creating in this step.
r =createOutputRow(r, data.outputRowMeta.size());/* TODO: Your code here. (See Sample)
// Get the value from an input field
String foobar = get(Fields.In, "a_fieldname").getString(r);
foobar += "bar";
// Set a value in a new output field
get(Fields.Out, "output_fieldname").setValue(r, foobar);
*/// Send the row on to the next step.putRow(data.outputRowMeta, r);returntrue;}