package journal.action; import java.util.Date; import java.util.Formatter; import java.util.HashMap; import java.util.Map; import journal.reader.DataJournalEntry; public class ClientWorkspaceReporter extends BaseAction { static class ClientInfo { public ClientInfo(String name, Date lastAccessed) { this.name = name; this.lastAccessed = lastAccessed; this.haveEntries = 0; this.openFiles = 0; } String name; Date lastAccessed; int haveEntries; int openFiles; } private Map<String, ClientInfo> clientInfos = new HashMap<String, ClientInfo>(); @Override public void finish() throws Exception { out.println("Workspace Name|Last Accessed|Days Ago|Have Entries|Open Entries"); for (Map.Entry<String, ClientInfo> entry : clientInfos.entrySet()) { ClientInfo info = entry.getValue(); StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); long deltaDays = ((new Date()).getTime() - info.lastAccessed.getTime()) / (24 * 3600 * 1000); formatter.format("%1$-48s|%2$td/%2$tm/%2$ty|%3$d|%4$d|%5$d", info.name, info.lastAccessed, deltaDays, info.haveEntries, info.openFiles); out.println(sb.toString()); formatter.close(); } out.println("\nErrors encountered: ****"); out.println("\tHave Errors : " + haveErrors); out.println("\tWorking Errors : " + workingErrors); super.finish(); } @Override public void putValue(DataJournalEntry dataEntry) { if (dataEntry.getTableName().equals("db.domain")) { String name = (String) dataEntry.getValue("name"); int type = (Integer) dataEntry.getValue("type"); Date access = (Date) dataEntry.getValue("access"); if (options.isCaseInsensitive()) { name = name.toLowerCase(); } if (type == 99) { // found a client workspace ClientInfo info = new ClientInfo(name, access); clientInfos.put(name, info); } } else if (dataEntry.getTableName().equals("db.have")) { String cfile = (String) dataEntry.getValue("cfile"); int slash = cfile.indexOf('/', 2); // find the first slash separating client name and path if (slash < 0) { System.err.println("Very odd dataEntry : " + dataEntry.toJournalString()); haveErrors++; return; // ignore the error and continue } String clientName = cfile.substring(2, slash); if (options.isCaseInsensitive()) { clientName = clientName.toLowerCase(); } if (clientInfos.containsKey(clientName)) { clientInfos.get(clientName).haveEntries++; } else { options.getErrorStream().println(dataEntry.toJournalString()); haveErrors++; // ignore errors for this run System.err.println("Severe problem, have entry points to non-existing workspace " + clientName); return; } } else if (dataEntry.getTableName().equals("db.working")) { String client = (String) dataEntry.getValue("client"); if (options.isCaseInsensitive()) { client = client.toLowerCase(); } if (clientInfos.containsKey(client)) { clientInfos.get(client).openFiles++; } else { options.getErrorStream().println(dataEntry.toJournalString()); workingErrors++; // System.err.println("Severe problem, working points to non-existing workspace " + client); } } } private int haveErrors = 0; private int workingErrors = 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 24773 | Norman Morse |
Moving journalReader from sven's private branch to perforce_software. This is because journalReader is used in the perfsplit test harness, and should be updated over time. Merging //guest/sven_erik_knop/java/JournalReader/... to //guest/perforce_software/journalReader/... |
||
//guest/sven_erik_knop/java/JournalReader/src/journal/action/ClientWorkspaceReporter.java | |||||
#6 | 8345 | Sven Erik Knop | Prevent ClientWorkspaceReporter from exiting in case of broken have records. | ||
#5 | 8296 | Sven Erik Knop |
Clean-up: instead of casting in every action, cast only once in the dispatcher. Should make code saner and safer. No functional change. |
||
#4 | 8275 | Sven Erik Knop | Silenced compiler warning | ||
#3 | 8023 | Sven Erik Knop |
Complete rewrite of the configuration file, now based on an ini-file format. The ini file has a general [reader] section for settings like verbose, outputFile, case-sensitivity and so on. It also allows to set up a range of Actions and Filters. The section name here is the fully classified class name, followed by settings for the particular actions. An example will make this clearer: ================================================================ [reader] verbose=true [journal.action.UserRenamer] fileName=user.txt patch=True outputFile=user.out [journal.action.ClientRenamer] fileName=client.txt outputFile=client.out patch=true ================================================================ I will provide more example set-ups in the near future. Filters are classes implementing journal.action.Filter (soon to be journal.filter.Filter) which can be chained together and are all executed before the actions. Actions are applied in order that they are given in the config file. |
||
#2 | 8020 | Sven Erik Knop | Replace public Option attributes with setters and getters. | ||
#1 | 7527 | Sven Erik Knop |
JournalReader, now in its proper place. Documentation to follow. |