parent
f524e36a2f
commit
ea0796f5e3
|
@ -4,7 +4,10 @@ import java.text.ParseException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Constructor;
|
||||
import org.bench4q.agent.plugin.Parameter;
|
||||
|
@ -32,12 +35,15 @@ public class HBasePlugin {
|
|||
public static List<String> LABEL_LIST;
|
||||
static {
|
||||
LABEL_LIST = new ArrayList<String>();
|
||||
LABEL_LIST.add("paramName");
|
||||
LABEL_LIST.add("dataType");
|
||||
LABEL_LIST.add("generator");
|
||||
LABEL_LIST.add("min");
|
||||
LABEL_LIST.add("max");
|
||||
}
|
||||
|
||||
private Map<String, RecordGenerator> generatorMap = new LinkedHashMap<String, RecordGenerator>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sampleRate
|
||||
|
@ -52,24 +58,23 @@ public class HBasePlugin {
|
|||
public HBasePlugin(
|
||||
@Parameter(value = "sampleRate", type = SupportTypes.Field) String sampleRate,
|
||||
@Parameter(value = "sendRate", type = SupportTypes.Field) String sendRate,
|
||||
@Parameter(value = "voltage", type = SupportTypes.Table) String voltage,
|
||||
@Parameter(value = "electricCurrent", type = SupportTypes.Table) String electricCurrent,
|
||||
@Parameter(value = "electricity", type = SupportTypes.Table) String electricity) {
|
||||
@Parameter(value = "generatorParams", type = SupportTypes.Table) String generatorParams) {
|
||||
this.sendRate = Integer.parseInt(sendRate);
|
||||
this.sampleRate = Integer.parseInt(sampleRate);
|
||||
int sampleCountForSendOnce = this.sendRate * ONE_DAY_TO_MINUTE
|
||||
/ this.sampleRate;
|
||||
Row voltageRow = Table.buildTable(voltage, LABEL_LIST).getRow(0);
|
||||
this.voltageGenerator = RecordGenerator.buildGeneratorWithRow(
|
||||
voltageRow, sampleCountForSendOnce);
|
||||
Row electricCurrentRow = Table.buildTable(electricCurrent, LABEL_LIST)
|
||||
.getRow(0);
|
||||
this.electricCurrentGenerator = RecordGenerator.buildGeneratorWithRow(
|
||||
electricCurrentRow, sampleCountForSendOnce);
|
||||
Row electricityRow = Table.buildTable(electricity, LABEL_LIST)
|
||||
.getRow(0);
|
||||
this.electricityGenerator = RecordGenerator.buildGeneratorWithRow(
|
||||
electricityRow, sampleCountForSendOnce);
|
||||
|
||||
Table generatorTable = Table.buildTable(generatorParams, LABEL_LIST);
|
||||
for (Row row : generatorTable.getRows()) {
|
||||
RecordGenerator generator = RecordGenerator.buildGeneratorWithRow(
|
||||
row, sampleCountForSendOnce);
|
||||
// this.generators.add(generator);
|
||||
this.generatorMap.put(row.getCell(0), generator);
|
||||
}
|
||||
this.voltageGenerator = this.generatorMap.get("voltage");
|
||||
this.electricCurrentGenerator = this.generatorMap
|
||||
.get("electricCurrent");
|
||||
this.electricityGenerator = this.generatorMap.get("electricity");
|
||||
}
|
||||
|
||||
@Behavior("Send")
|
||||
|
@ -141,9 +146,9 @@ public class HBasePlugin {
|
|||
}
|
||||
|
||||
private void resetGenerators() {
|
||||
this.electricCurrentGenerator.reset();
|
||||
this.electricityGenerator.reset();
|
||||
this.voltageGenerator.reset();
|
||||
for (RecordGenerator generator : this.generatorMap.values()) {
|
||||
generator.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public class TwoTupple {
|
||||
|
|
|
@ -88,8 +88,8 @@ public abstract class RecordGenerator {
|
|||
|
||||
public static RecordGenerator buildGeneratorWithRow(Row row,
|
||||
int sampleCountForSendOnce) {
|
||||
RecordGenerator result = buildGenerator(row.getCell(0), row.getCell(1),
|
||||
row.getCell(2), row.getCell(3), sampleCountForSendOnce);
|
||||
RecordGenerator result = buildGenerator(row.getCell(1), row.getCell(2),
|
||||
row.getCell(3), row.getCell(4), sampleCountForSendOnce);
|
||||
result.reset();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class Table extends Type {
|
|||
this.columnLables = columnLables;
|
||||
}
|
||||
|
||||
private List<Row> getRows() {
|
||||
public List<Row> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,10 +141,12 @@ public class Test_HBasePlugin {
|
|||
|
||||
@Test
|
||||
public void testSend() {
|
||||
HBasePlugin plugin = new HBasePlugin("10", "1",
|
||||
"dataType=Int|generator=Random|min=10|max=50|;",
|
||||
"dataType=Double|generator=Sin|min=216|max=226",
|
||||
"dataType=long|generator=Cos|min=1056|max=1068");
|
||||
HBasePlugin plugin = new HBasePlugin(
|
||||
"10",
|
||||
"1",
|
||||
"paramName=voltage|dataType=Int|generator=Random|min=10|max=50|;"
|
||||
+ "paramName=electricCurrent|dataType=Double|generator=Sin|min=216|max=226|;"
|
||||
+ "paramName=electricity|dataType=long|generator=Cos|min=1056|max=1068|;");
|
||||
plugin.send("201403270000000", "201403280000000", "1", "4");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue