public class LogEntryTableModelBase
extends javax.swing.table.AbstractTableModel
implements java.lang.Runnable
Each log in the model is identified by a integer key; the association
between keys and logs is done by the allLogs.
rows represents a entry in the table i.e. a log identified by its key.
So to get a log in a row, we must first get its key and then get the log from the cache.
This indirection allows to avoid keeping all the logs in memory
The list of keys (rows) and the map (allLogs) must be consistent
in the sense that the map must always contain the keys of all the logs in the table
but it can have more keys. For example if a log is removed from the table
its key can be removed from the map at a latter time.
The model is modified inside the EDT. The consistency between
(rows) and the map (allLogs) is also obtained by
modifying their contents inside the EDT.
EDTExecutor is used to ensure to access the model from inside the EDT.
To reduce the overload refreshing the content of the table when a lot of logs
have been added or removed, the refresh is triggered only after a certain amount
of time by a dedicated thread (see run()).
When a log is deleted, it key is immediately removed from the List of logs (rows
but the key is still in the cache (allLogs). A dedicated thread, KeysDeleter,
is in charge of removing unused keys. This operation can be safely done in a non-EDT
thread.
LogEntryTableModelBase can be reused by log tables with basic functionalities
like the error browsers.
TODO: manage threads with a ScheduledThreadPoolExecutor
| Modifier and Type | Field and Description |
|---|---|
protected LogCache |
allLogs
The cache of all the logs received.
|
protected LoggingClient |
loggingClient
The LoggingClient that owns this table model
|
protected RowEntries |
rows
Each row of the table shows a log identified by a key returned by the cache.
|
protected java.lang.Thread |
tableUpdater
The thread to refresh the content of the table
|
| Constructor and Description |
|---|
LogEntryTableModelBase(LoggingClient client)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
appendLog(ILogEntry log)
Adds a log to
TableUpdater#rowsToAdd ready to be flushed
in the table at the next iteration. |
void |
clearAll()
Remove all the logs.
|
void |
close(boolean sync)
Closes all the threads and frees the resources
This is the last method to call before closing the application
|
int |
findKeyPos(java.lang.Integer key)
Return the position of the key in the vector.
|
java.lang.Class<?> |
getColumnClass(int column)
Returns default class for column.
|
int |
getColumnCount()
Return number of columns in table
|
java.lang.String |
getColumnName(int columnIndex)
Returns name of the column based LogEntryXML fields.
|
java.lang.Integer |
getLogKey(int index)
Return the key of the log in the given position of the
vector of keys.
|
int |
getRowCount() |
java.util.Calendar |
getTimeFrame() |
java.lang.Object |
getValueAt(int row,
int column)
Returns an item according to the row and the column of its position.
|
ILogEntry |
getVisibleLogEntry(int row)
Return the log shown in the passed row.
|
int |
numberOfUsedFiles() |
void |
replaceLog(int pos,
ILogEntry newEntry)
Replace a log entry with another.
|
void |
run() |
void |
setMaxLog(int max)
Set the max number of logs to keep in cache
This is the max number of logs stored in cache
(the visible logs can be less)
|
void |
start()
Start the thread to update the table model.
|
long |
totalLogNumber()
Return the number of logs in cache
without those waiting to be added in
TableUpdater#rowsToAdd. |
long |
usedDiskSpace() |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAtprotected LogCache allLogs
protected final RowEntries rows
This vector stores the key of each log in the table.
protected java.lang.Thread tableUpdater
protected final LoggingClient loggingClient
public LogEntryTableModelBase(LoggingClient client) throws java.lang.Exception
java.lang.Exceptionpublic void start()
LogEntryTableModelBase#tableUpdater}public final int getColumnCount()
getColumnCount in interface javax.swing.table.TableModelpublic int numberOfUsedFiles()
public long usedDiskSpace()
throws java.io.IOException
java.io.IOException - In case of error getting the size of at least
one of the used cache filespublic int getRowCount()
getRowCount in interface javax.swing.table.TableModelTableModel.getRowCount()public java.lang.Object getValueAt(int row,
int column)
getValueAt in interface javax.swing.table.TableModelrow - intcolumn - intpublic ILogEntry getVisibleLogEntry(int row)
This must be called inside the EDT.
row - The row of the table containing the logpublic void clearAll()
public long totalLogNumber()
TableUpdater#rowsToAdd.public java.util.Calendar getTimeFrame()
LogCachepublic java.lang.Integer getLogKey(int index)
There are several cases that forbids to retrieve the key in the given position,
in such a situations the method return null.
One typical situation is when the entry has been deleted by the LogDeleter.
index - The position in the model of the keynull if it is not possible to return the keyfindKeyPos(Integer key)public int findKeyPos(java.lang.Integer key)
There are cases when the key is not anymore in the vector and in such situations
this method return null.
For example it could happen if the log has been deleted by the LogDeleter.
key - The key whose position in the vector has to be found-1 if the key is not in the vectorpublic final java.lang.String getColumnName(int columnIndex)
getColumnName in interface javax.swing.table.TableModelgetColumnName in class javax.swing.table.AbstractTableModelcolumnIndex - intpublic final java.lang.Class<?> getColumnClass(int column)
getColumnClass in interface javax.swing.table.TableModelgetColumnClass in class javax.swing.table.AbstractTableModelcolumn - intpublic void replaceLog(int pos,
ILogEntry newEntry)
pos - The position in the cache of the log to replacenewEntry - The new LogEntryXMLpublic void close(boolean sync)
sync - If it is true wait the termination of the threads before returningpublic void appendLog(ILogEntry log)
TableUpdater#rowsToAdd ready to be flushed
in the table at the next iteration.
To avoid updating the table very frequently, the logs to add are immediately
inserted in the LogCache but their insertion in the table is delayed
and done by the TableUpdater thread.
For this reason each log is inserted in the temporary vector rowsToAdd
that will be flushed into rows by the thread.
log - The log to addpublic void setMaxLog(int max)
max - The max number of logs
0 means unlimitedpublic void run()
run in interface java.lang.Runnable