import bruma.master.Master; //导入方法依赖的package包/类
/**
* @param args [--from=][--to=][--encoding=][--showLeader]
* @throws BrumaException
*/
public static void main(final String[] args) throws BrumaException {
if (args.length < 1) {
usage();
}
int from = 1;
int to = -1;
String encoding = Master.GUESS_ISO_IBM_ENCODING;
final Master mst;
Record rec;
Leader leader;
boolean showLeader = false;
Record.Status status;
for (int idx = 1; idx < args.length; idx++) {
if (args[idx].startsWith("--from=")) {
from = Integer.parseInt(args[idx].substring(7));
} else if (args[idx].startsWith("--to=")) {
to = Integer.parseInt(args[idx].substring(5));
} else if (args[idx].startsWith("--encoding=")) {
encoding = args[idx].substring(11);
} else if (args[idx].equals("--showLeader")) {
showLeader = true;
} else {
usage();
}
}
mst = MasterFactory.getInstance(args[0])
.setEncoding(encoding)
.open();
if (to == -1) {
to = mst.getControlRecord().getNxtmfn() - 1;
}
if (to < from) {
throw new IllegalArgumentException("to[" + to + "] < from["
+ from + "]");
}
for (int mfn = from; mfn <= to; mfn++) {
rec = mst.getRecord(mfn);
status = rec.getStatus();
System.out.println("--------------------------- " + mfn
+ ((status != Record.Status.ACTIVE) ? " " : " ---------")
+ "-------------------------\n");
if ((status == Record.Status.ACTIVE)
|| (status == Record.Status.LOGDEL)) {
if (showLeader) {
leader = rec.getLeader(mst.getEncoding(), mst.isFFI());
System.out.println("mfn=" + mfn + " status="
+ leader.getStatus() + " len=" + leader.getMfrl());
}
System.out.println(rec);
}
}
mst.close();
}