mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Code cleanup in DSF examples.
- Added @Override where necessary. - Added src_ant to source directories in build.properties - Fixed resource leaks - Added type parameters where missing (e.g. Vector in PreProcessor.java) - Removed unused imports Change-Id: I28c7e295891833f9b561975da0adc92d55f2e048 Signed-off-by: Jesper Eskilson <jesper.eskilson@iar.com>
This commit is contained in:
parent
a08b9582d3
commit
92cd626895
14 changed files with 167 additions and 101 deletions
|
@ -420,32 +420,33 @@ public class PDAVirtualMachine {
|
||||||
pdaVM.run();
|
pdaVM.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
PDAVirtualMachine(String inputFile, boolean debug, int commandPort, int eventPort) throws IOException {
|
PDAVirtualMachine(String inputFile, boolean debug, int commandPort, int eventPort) throws IOException {
|
||||||
fFilename = inputFile;
|
fFilename = inputFile;
|
||||||
|
|
||||||
// Load all the code into memory
|
// Load all the code into memory
|
||||||
FileReader fileReader = new FileReader(inputFile);
|
try (FileReader fileReader = new FileReader(inputFile)) {
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new StringWriter();
|
||||||
List<String> code = new LinkedList<String>();
|
List<String> code = new LinkedList<String>();
|
||||||
int c = fileReader.read();
|
int c = fileReader.read();
|
||||||
while (c != -1) {
|
while (c != -1) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
code.add(stringWriter.toString().trim());
|
code.add(stringWriter.toString().trim());
|
||||||
stringWriter = new StringWriter();
|
stringWriter = new StringWriter();
|
||||||
} else {
|
} else {
|
||||||
stringWriter.write(c);
|
stringWriter.write(c);
|
||||||
}
|
}
|
||||||
c = fileReader.read();
|
c = fileReader.read();
|
||||||
}
|
}
|
||||||
code.add(stringWriter.toString().trim());
|
code.add(stringWriter.toString().trim());
|
||||||
fCode = code.toArray(new String[code.size()]);
|
fCode = code.toArray(new String[code.size()]);
|
||||||
|
|
||||||
fLabels = mapLabels(fCode);
|
fLabels = mapLabels(fCode);
|
||||||
|
|
||||||
fDebug = debug;
|
fDebug = debug;
|
||||||
fCommandPort = commandPort;
|
fCommandPort = commandPort;
|
||||||
fEventPort = eventPort;
|
fEventPort = eventPort;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the labels map
|
* Initializes the labels map
|
||||||
|
|
|
@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Vendor: %providerName
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.examples.dsf;singleton:=true
|
Bundle-SymbolicName: org.eclipse.cdt.examples.dsf;singleton:=true
|
||||||
Bundle-Version: 2.1.0.qualifier
|
Bundle-Version: 2.2.0.qualifier
|
||||||
Bundle-Activator: org.eclipse.cdt.examples.dsf.DsfExamplesPlugin
|
Bundle-Activator: org.eclipse.cdt.examples.dsf.DsfExamplesPlugin
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Require-Bundle: org.eclipse.ui,
|
Require-Bundle: org.eclipse.ui,
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
# Contributors:
|
# Contributors:
|
||||||
# Wind River Systems - initial API and implementation
|
# Wind River Systems - initial API and implementation
|
||||||
###############################################################################
|
###############################################################################
|
||||||
source.. = src/
|
source.. = src/,\
|
||||||
|
src_ant/
|
||||||
output.. = bin/
|
output.. = bin/
|
||||||
bin.includes = META-INF/,\
|
bin.includes = META-INF/,\
|
||||||
.,\
|
.,\
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
<artifactId>org.eclipse.cdt.examples.dsf</artifactId>
|
<artifactId>org.eclipse.cdt.examples.dsf</artifactId>
|
||||||
<packaging>eclipse-plugin</packaging>
|
<packaging>eclipse-plugin</packaging>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -47,9 +47,9 @@ import org.apache.tools.ant.util.FileUtils;
|
||||||
*/
|
*/
|
||||||
public class PreProcessor extends Task {
|
public class PreProcessor extends Task {
|
||||||
|
|
||||||
private Vector fFileSets = new Vector();
|
private Vector<FileSet> fFileSets = new Vector<>();
|
||||||
private File fDestDir = null;
|
private File fDestDir = null;
|
||||||
private Set fSymbols = new HashSet();
|
private Set<String> fSymbols = new HashSet<>();
|
||||||
private FileUtils fUtils = FileUtils.getFileUtils();
|
private FileUtils fUtils = FileUtils.getFileUtils();
|
||||||
|
|
||||||
// possible states
|
// possible states
|
||||||
|
@ -116,7 +116,7 @@ public class PreProcessor extends Task {
|
||||||
throw new BuildException("destdir does not exist: " + fDestDir.getAbsolutePath());
|
throw new BuildException("destdir does not exist: " + fDestDir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
StringBuffer buf = new StringBuffer("Symbols: ");
|
StringBuffer buf = new StringBuffer("Symbols: ");
|
||||||
String[] symbols = (String[]) fSymbols.toArray(new String[fSymbols.size()]);
|
String[] symbols = fSymbols.toArray(new String[fSymbols.size()]);
|
||||||
for (int i = 0; i < symbols.length; i++) {
|
for (int i = 0; i < symbols.length; i++) {
|
||||||
String symbol = symbols[i];
|
String symbol = symbols[i];
|
||||||
buf.append(symbol);
|
buf.append(symbol);
|
||||||
|
@ -126,9 +126,9 @@ public class PreProcessor extends Task {
|
||||||
}
|
}
|
||||||
log(buf.toString());
|
log(buf.toString());
|
||||||
|
|
||||||
Iterator fileSets = fFileSets.iterator();
|
Iterator<FileSet> fileSets = fFileSets.iterator();
|
||||||
while (fileSets.hasNext()) {
|
while (fileSets.hasNext()) {
|
||||||
FileSet fileSet = (FileSet) fileSets.next();
|
FileSet fileSet = fileSets.next();
|
||||||
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
|
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
|
||||||
String[] includedFiles = scanner.getIncludedFiles();
|
String[] includedFiles = scanner.getIncludedFiles();
|
||||||
File baseDir = fileSet.getDir(getProject());
|
File baseDir = fileSet.getDir(getProject());
|
||||||
|
@ -188,9 +188,7 @@ public class PreProcessor extends Task {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String preProcessFile(File srcFile, String strip) {
|
public String preProcessFile(File srcFile, String strip) {
|
||||||
try {
|
try (BufferedReader reader = new BufferedReader(new FileReader(srcFile))) {
|
||||||
FileReader fileReader = new FileReader(srcFile);
|
|
||||||
BufferedReader reader = new BufferedReader(fileReader);
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
String activeSymbol = null;
|
String activeSymbol = null;
|
||||||
|
|
|
@ -80,11 +80,13 @@ public class ACPMSumDataGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCount(final DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getCount(final DataRequestMonitor<Integer> rm) {
|
||||||
// Artificially delay the retrieval of the sum data to simulate
|
// Artificially delay the retrieval of the sum data to simulate
|
||||||
// real processing time.
|
// real processing time.
|
||||||
fExecutor.schedule( new Runnable() {
|
fExecutor.schedule( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
// Create the transaction here to put all the ugly
|
// Create the transaction here to put all the ugly
|
||||||
// code in one place.
|
// code in one place.
|
||||||
new Transaction<Integer>() {
|
new Transaction<Integer>() {
|
||||||
|
@ -129,11 +131,13 @@ public class ACPMSumDataGenerator
|
||||||
return maxCount;
|
return maxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getValue(final int index, final DataRequestMonitor<Integer> rm)
|
@Override
|
||||||
|
public void getValue(final int index, final DataRequestMonitor<Integer> rm)
|
||||||
{
|
{
|
||||||
// Add a processing delay.
|
// Add a processing delay.
|
||||||
fExecutor.schedule( new Runnable() {
|
fExecutor.schedule( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
new Transaction<Integer>() {
|
new Transaction<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
protected Integer process()
|
protected Integer process()
|
||||||
|
@ -175,7 +179,8 @@ public class ACPMSumDataGenerator
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown(final RequestMonitor rm) {
|
@Override
|
||||||
|
public void shutdown(final RequestMonitor rm) {
|
||||||
for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) {
|
for (DataGeneratorCacheManager dataGeneratorCM : fDataGeneratorCMs) {
|
||||||
dataGeneratorCM.getDataGenerator().removeListener(this);
|
dataGeneratorCM.getDataGenerator().removeListener(this);
|
||||||
dataGeneratorCM.dispose();
|
dataGeneratorCM.dispose();
|
||||||
|
@ -184,33 +189,39 @@ public class ACPMSumDataGenerator
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(final Listener listener) {
|
@Override
|
||||||
|
public void addListener(final Listener listener) {
|
||||||
// Must access fListeners on executor thread.
|
// Must access fListeners on executor thread.
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fListeners.add(listener);
|
fListeners.add(listener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (RejectedExecutionException e) {}
|
} catch (RejectedExecutionException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeListener(final Listener listener) {
|
@Override
|
||||||
|
public void removeListener(final Listener listener) {
|
||||||
// Must access fListeners on executor thread.
|
// Must access fListeners on executor thread.
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fListeners.remove(listener);
|
fListeners.remove(listener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (RejectedExecutionException e) {}
|
} catch (RejectedExecutionException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void countChanged() {
|
@Override
|
||||||
|
public void countChanged() {
|
||||||
// Must access fListeners on executor thread.
|
// Must access fListeners on executor thread.
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
for (Listener listener : fListeners) {
|
for (Listener listener : fListeners) {
|
||||||
listener.countChanged();
|
listener.countChanged();
|
||||||
}
|
}
|
||||||
|
@ -219,11 +230,13 @@ public class ACPMSumDataGenerator
|
||||||
} catch (RejectedExecutionException e) {}
|
} catch (RejectedExecutionException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void valuesChanged(final Set<Integer> changed) {
|
@Override
|
||||||
|
public void valuesChanged(final Set<Integer> changed) {
|
||||||
// Must access fListeners on executor thread.
|
// Must access fListeners on executor thread.
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
for (Object listener : fListeners) {
|
for (Object listener : fListeners) {
|
||||||
((Listener)listener).valuesChanged(changed);
|
((Listener)listener).valuesChanged(changed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,14 +107,16 @@ public class ACPMSumDataViewer implements ILazyContentProvider
|
||||||
// Schedule a task to refresh the viewer periodically.
|
// Schedule a task to refresh the viewer periodically.
|
||||||
fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(
|
fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
|
UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
@Override
|
||||||
|
public void dispose() {
|
||||||
// Cancel the periodic task of refreshing the view.
|
// Cancel the periodic task of refreshing the view.
|
||||||
fRefreshFuture.cancel(false);
|
fRefreshFuture.cancel(false);
|
||||||
|
|
||||||
|
@ -147,12 +149,14 @@ public class ACPMSumDataViewer implements ILazyContentProvider
|
||||||
fItemDataRequestMonitors.clear();
|
fItemDataRequestMonitors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
@Override
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
// Set the initial count to the viewer after the input is set.
|
// Set the initial count to the viewer after the input is set.
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateElement(final int index) {
|
@Override
|
||||||
|
public void updateElement(final int index) {
|
||||||
// Calculate the visible index range.
|
// Calculate the visible index range.
|
||||||
final int topIdx = fViewer.getTable().getTopIndex();
|
final int topIdx = fViewer.getTable().getTopIndex();
|
||||||
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
||||||
|
@ -164,7 +168,8 @@ public class ACPMSumDataViewer implements ILazyContentProvider
|
||||||
// calls to be combined together improving performance of the viewer.
|
// calls to be combined together improving performance of the viewer.
|
||||||
fCancelCallsPending++;
|
fCancelCallsPending++;
|
||||||
fDisplayExecutor.execute(
|
fDisplayExecutor.execute(
|
||||||
new Runnable() { public void run() {
|
new Runnable() { @Override
|
||||||
|
public void run() {
|
||||||
cancelStaleRequests(topIdx, botIdx);
|
cancelStaleRequests(topIdx, botIdx);
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
@ -205,7 +210,8 @@ public class ACPMSumDataViewer implements ILazyContentProvider
|
||||||
// if the cache is reset during processing by an event. The request
|
// if the cache is reset during processing by an event. The request
|
||||||
// for data will be re-issued.
|
// for data will be re-issued.
|
||||||
fDataExecutor.execute(new Runnable() {
|
fDataExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
new Transaction<Integer>() {
|
new Transaction<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
protected Integer process()
|
protected Integer process()
|
||||||
|
@ -274,7 +280,8 @@ public class ACPMSumDataViewer implements ILazyContentProvider
|
||||||
// if the cache is reset during processing by an event. The request
|
// if the cache is reset during processing by an event. The request
|
||||||
// for data will be re-issued.
|
// for data will be re-issued.
|
||||||
fDataExecutor.execute(new Runnable() {
|
fDataExecutor.execute(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
new Transaction<String>() {
|
new Transaction<String>() {
|
||||||
@Override
|
@Override
|
||||||
protected String process()
|
protected String process()
|
||||||
|
|
|
@ -79,16 +79,19 @@ public class AsyncDataViewer
|
||||||
fDataGenerator.addListener(this);
|
fDataGenerator.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
@Override
|
||||||
|
public void dispose() {
|
||||||
fDataGenerator.removeListener(this);
|
fDataGenerator.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
@Override
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
// Set the initial count to the viewer after the input is set.
|
// Set the initial count to the viewer after the input is set.
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateElement(final int index) {
|
@Override
|
||||||
|
public void updateElement(final int index) {
|
||||||
// Calculate the visible index range.
|
// Calculate the visible index range.
|
||||||
final int topIdx = fViewer.getTable().getTopIndex();
|
final int topIdx = fViewer.getTable().getTopIndex();
|
||||||
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
||||||
|
@ -100,7 +103,8 @@ public class AsyncDataViewer
|
||||||
// calls to be combined together improving performance of the viewer.
|
// calls to be combined together improving performance of the viewer.
|
||||||
fCancelCallsPending++;
|
fCancelCallsPending++;
|
||||||
fDisplayExecutor.schedule(
|
fDisplayExecutor.schedule(
|
||||||
new Runnable() { public void run() {
|
new Runnable() { @Override
|
||||||
|
public void run() {
|
||||||
cancelStaleRequests(topIdx, botIdx);
|
cancelStaleRequests(topIdx, botIdx);
|
||||||
}},
|
}},
|
||||||
1, TimeUnit.MILLISECONDS);
|
1, TimeUnit.MILLISECONDS);
|
||||||
|
@ -120,19 +124,22 @@ public class AsyncDataViewer
|
||||||
itemCount - top);
|
itemCount - top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThreadSafe
|
@Override
|
||||||
|
@ThreadSafe
|
||||||
public void countChanged() {
|
public void countChanged() {
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ThreadSafe
|
@Override
|
||||||
|
@ThreadSafe
|
||||||
public void valuesChanged(final Set<Integer> indexes) {
|
public void valuesChanged(final Set<Integer> indexes) {
|
||||||
// Mark the changed items in table viewer as dirty, this will
|
// Mark the changed items in table viewer as dirty, this will
|
||||||
// trigger update requests for these indexes if they are
|
// trigger update requests for these indexes if they are
|
||||||
// visible in the viewer.
|
// visible in the viewer.
|
||||||
final TableViewer tableViewer = fViewer;
|
final TableViewer tableViewer = fViewer;
|
||||||
fDisplayExecutor.execute( new Runnable() {
|
fDisplayExecutor.execute( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!fViewer.getTable().isDisposed()) {
|
if (!fViewer.getTable().isDisposed()) {
|
||||||
for (Integer index : indexes) {
|
for (Integer index : indexes) {
|
||||||
tableViewer.clear(index);
|
tableViewer.clear(index);
|
||||||
|
|
|
@ -52,11 +52,13 @@ public class AsyncSumDataGenerator implements IDataGenerator {
|
||||||
fDataGenerators = generators;
|
fDataGenerators = generators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCount(final DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getCount(final DataRequestMonitor<Integer> rm) {
|
||||||
// Artificially delay the retrieval of the sum data to simulate
|
// Artificially delay the retrieval of the sum data to simulate
|
||||||
// real processing time.
|
// real processing time.
|
||||||
fExecutor.schedule( new Runnable() {
|
fExecutor.schedule( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
doGetCount(rm);
|
doGetCount(rm);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -102,12 +104,14 @@ public class AsyncSumDataGenerator implements IDataGenerator {
|
||||||
crm.setDoneCount(fDataGenerators.length);
|
crm.setDoneCount(fDataGenerators.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getValue(final int index, final DataRequestMonitor<Integer> rm)
|
@Override
|
||||||
|
public void getValue(final int index, final DataRequestMonitor<Integer> rm)
|
||||||
{
|
{
|
||||||
// Artificially delay the retrieval of the sum data to simulate
|
// Artificially delay the retrieval of the sum data to simulate
|
||||||
// real processing time.
|
// real processing time.
|
||||||
fExecutor.schedule( new Runnable() {
|
fExecutor.schedule( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
doGetValue(index, rm);
|
doGetValue(index, rm);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -156,15 +160,18 @@ public class AsyncSumDataGenerator implements IDataGenerator {
|
||||||
crm.setDoneCount(fDataGenerators.length);
|
crm.setDoneCount(fDataGenerators.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown(RequestMonitor rm) {
|
@Override
|
||||||
|
public void shutdown(RequestMonitor rm) {
|
||||||
rm.done();
|
rm.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(final Listener listener) {
|
@Override
|
||||||
|
public void addListener(final Listener listener) {
|
||||||
// no events generated
|
// no events generated
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeListener(Listener listener) {
|
@Override
|
||||||
|
public void removeListener(Listener listener) {
|
||||||
// no events generated
|
// no events generated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,14 +95,16 @@ public class AsyncSumDataViewer implements ILazyContentProvider
|
||||||
// Schedule a task to refresh the viewer periodically.
|
// Schedule a task to refresh the viewer periodically.
|
||||||
fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(
|
fRefreshFuture = fDisplayExecutor.scheduleAtFixedRate(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
|
UPDATE_INTERVAL, UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
@Override
|
||||||
|
public void dispose() {
|
||||||
// Cancel the periodic task of refreshing the view.
|
// Cancel the periodic task of refreshing the view.
|
||||||
fRefreshFuture.cancel(false);
|
fRefreshFuture.cancel(false);
|
||||||
|
|
||||||
|
@ -113,12 +115,14 @@ public class AsyncSumDataViewer implements ILazyContentProvider
|
||||||
fItemDataRequestMonitors.clear();
|
fItemDataRequestMonitors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
@Override
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
// Set the initial count to the viewer after the input is set.
|
// Set the initial count to the viewer after the input is set.
|
||||||
queryItemCount();
|
queryItemCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateElement(final int index) {
|
@Override
|
||||||
|
public void updateElement(final int index) {
|
||||||
// Calculate the visible index range.
|
// Calculate the visible index range.
|
||||||
final int topIdx = fViewer.getTable().getTopIndex();
|
final int topIdx = fViewer.getTable().getTopIndex();
|
||||||
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
final int botIdx = topIdx + getVisibleItemCount(topIdx);
|
||||||
|
@ -130,7 +134,8 @@ public class AsyncSumDataViewer implements ILazyContentProvider
|
||||||
// calls to be combined together improving performance of the viewer.
|
// calls to be combined together improving performance of the viewer.
|
||||||
fCancelCallsPending++;
|
fCancelCallsPending++;
|
||||||
fDisplayExecutor.execute(
|
fDisplayExecutor.execute(
|
||||||
new Runnable() { public void run() {
|
new Runnable() { @Override
|
||||||
|
public void run() {
|
||||||
cancelStaleRequests(topIdx, botIdx);
|
cancelStaleRequests(topIdx, botIdx);
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,8 @@ public class DataGeneratorCacheManager implements IDataGenerator.Listener {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void countChanged() {
|
@Override
|
||||||
|
public void countChanged() {
|
||||||
// Reset the count cache and all the value caches.
|
// Reset the count cache and all the value caches.
|
||||||
if (fCountCache != null) {
|
if (fCountCache != null) {
|
||||||
fCountCache.countChanged();
|
fCountCache.countChanged();
|
||||||
|
@ -153,7 +154,8 @@ public class DataGeneratorCacheManager implements IDataGenerator.Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void valuesChanged(Set<Integer> indexes) {
|
@Override
|
||||||
|
public void valuesChanged(Set<Integer> indexes) {
|
||||||
// Reset selected value caches.
|
// Reset selected value caches.
|
||||||
for (Integer index : indexes) {
|
for (Integer index : indexes) {
|
||||||
ValueCache value = fValueCaches.get(index);
|
ValueCache value = fValueCaches.get(index);
|
||||||
|
|
|
@ -72,9 +72,11 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
fRequestMonitor = rm;
|
fRequestMonitor = rm;
|
||||||
|
|
||||||
rm.addCancelListener(new RequestMonitor.ICanceledListener() {
|
rm.addCancelListener(new RequestMonitor.ICanceledListener() {
|
||||||
public void requestCanceled(RequestMonitor rm) {
|
@Override
|
||||||
|
public void requestCanceled(RequestMonitor rm) {
|
||||||
fExecutor.execute(new DsfRunnable() {
|
fExecutor.execute(new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fQueue.remove(Request.this);
|
fQueue.remove(Request.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -184,7 +186,8 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// Schedule a runnable to make the random changes.
|
// Schedule a runnable to make the random changes.
|
||||||
fExecutor.scheduleAtFixedRate(
|
fExecutor.scheduleAtFixedRate(
|
||||||
new DsfRunnable() {
|
new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
randomChanges();
|
randomChanges();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -197,10 +200,12 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
||||||
// indicating allowed thread access to this class/method/member
|
// indicating allowed thread access to this class/method/member
|
||||||
//#endif
|
//#endif
|
||||||
public void shutdown(final RequestMonitor rm) {
|
@Override
|
||||||
|
public void shutdown(final RequestMonitor rm) {
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
// Empty the queue of requests and fail them.
|
// Empty the queue of requests and fail them.
|
||||||
for (Request request : fQueue) {
|
for (Request request : fQueue) {
|
||||||
request.fRequestMonitor.setStatus(new Status(
|
request.fRequestMonitor.setStatus(new Status(
|
||||||
|
@ -226,10 +231,12 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
||||||
// indicating allowed thread access to this class/method/member
|
// indicating allowed thread access to this class/method/member
|
||||||
//#endif
|
//#endif
|
||||||
public void getCount(final DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getCount(final DataRequestMonitor<Integer> rm) {
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fQueue.add(new CountRequest(rm));
|
fQueue.add(new CountRequest(rm));
|
||||||
serviceQueue();
|
serviceQueue();
|
||||||
}
|
}
|
||||||
|
@ -246,10 +253,12 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
||||||
// indicating allowed thread access to this class/method/member
|
// indicating allowed thread access to this class/method/member
|
||||||
//#endif
|
//#endif
|
||||||
public void getValue(final int index, final DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getValue(final int index, final DataRequestMonitor<Integer> rm) {
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fQueue.add(new ItemRequest(index, rm));
|
fQueue.add(new ItemRequest(index, rm));
|
||||||
serviceQueue();
|
serviceQueue();
|
||||||
}
|
}
|
||||||
|
@ -265,10 +274,12 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
||||||
// indicating allowed thread access to this class/method/member
|
// indicating allowed thread access to this class/method/member
|
||||||
//#endif
|
//#endif
|
||||||
public void addListener(final Listener listener) {
|
@Override
|
||||||
|
public void addListener(final Listener listener) {
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fListeners.add(listener);
|
fListeners.add(listener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -279,10 +290,12 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
// TODO Exercise 4 - Add an annotation (ThreadSafe/ConfinedToDsfExecutor)
|
||||||
// indicating allowed thread access to this class/method/member
|
// indicating allowed thread access to this class/method/member
|
||||||
//#endif
|
//#endif
|
||||||
public void removeListener(final Listener listener) {
|
@Override
|
||||||
|
public void removeListener(final Listener listener) {
|
||||||
try {
|
try {
|
||||||
fExecutor.execute( new DsfRunnable() {
|
fExecutor.execute( new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
fListeners.remove(listener);
|
fListeners.remove(listener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -299,7 +312,8 @@ public class DataGeneratorWithExecutor implements IDataGenerator {
|
||||||
private void serviceQueue() {
|
private void serviceQueue() {
|
||||||
fExecutor.schedule(
|
fExecutor.schedule(
|
||||||
new DsfRunnable() {
|
new DsfRunnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
doServiceQueue();
|
doServiceQueue();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class DataGeneratorWithThread extends Thread
|
||||||
new LinkedBlockingQueue<Request>();
|
new LinkedBlockingQueue<Request>();
|
||||||
|
|
||||||
// ListenerList class provides thread safety.
|
// ListenerList class provides thread safety.
|
||||||
private ListenerList fListeners = new ListenerList();
|
private ListenerList<Listener> fListeners = new ListenerList<>();
|
||||||
|
|
||||||
// Current number of elements in this generator.
|
// Current number of elements in this generator.
|
||||||
private int fCount = MIN_COUNT;
|
private int fCount = MIN_COUNT;
|
||||||
|
@ -105,7 +105,8 @@ public class DataGeneratorWithThread extends Thread
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown(RequestMonitor rm) {
|
@Override
|
||||||
|
public void shutdown(RequestMonitor rm) {
|
||||||
// Mark the generator as shut down. After the fShutdown flag is set,
|
// Mark the generator as shut down. After the fShutdown flag is set,
|
||||||
// all new requests should be shut down.
|
// all new requests should be shut down.
|
||||||
if (!fShutdown.getAndSet(true)) {
|
if (!fShutdown.getAndSet(true)) {
|
||||||
|
@ -118,7 +119,8 @@ public class DataGeneratorWithThread extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCount(DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getCount(DataRequestMonitor<Integer> rm) {
|
||||||
if (!fShutdown.get()) {
|
if (!fShutdown.get()) {
|
||||||
fQueue.add(new CountRequest(rm));
|
fQueue.add(new CountRequest(rm));
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,7 +130,8 @@ public class DataGeneratorWithThread extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getValue(int index, DataRequestMonitor<Integer> rm) {
|
@Override
|
||||||
|
public void getValue(int index, DataRequestMonitor<Integer> rm) {
|
||||||
if (!fShutdown.get()) {
|
if (!fShutdown.get()) {
|
||||||
fQueue.add(new ItemRequest(index, rm));
|
fQueue.add(new ItemRequest(index, rm));
|
||||||
} else {
|
} else {
|
||||||
|
@ -138,11 +141,13 @@ public class DataGeneratorWithThread extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(Listener listener) {
|
@Override
|
||||||
|
public void addListener(Listener listener) {
|
||||||
fListeners.add(listener);
|
fListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeListener(Listener listener) {
|
@Override
|
||||||
|
public void removeListener(Listener listener) {
|
||||||
fListeners.remove(listener);
|
fListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,12 +56,14 @@ public class SyncDataViewer
|
||||||
fDataGenerator.addListener(this);
|
fDataGenerator.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
@Override
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
// Not used
|
// Not used
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object[] getElements(Object inputElement) {
|
@Override
|
||||||
|
public Object[] getElements(Object inputElement) {
|
||||||
|
|
||||||
// Create the query object for reading data count.
|
// Create the query object for reading data count.
|
||||||
Query<Integer> countQuery = new Query<Integer>() {
|
Query<Integer> countQuery = new Query<Integer>() {
|
||||||
|
@ -126,16 +128,19 @@ public class SyncDataViewer
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
@Override
|
||||||
|
public void dispose() {
|
||||||
fDataGenerator.removeListener(this);
|
fDataGenerator.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void countChanged() {
|
@Override
|
||||||
|
public void countChanged() {
|
||||||
// For any event from the generator, refresh the whole viewer.
|
// For any event from the generator, refresh the whole viewer.
|
||||||
refreshViewer();
|
refreshViewer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void valuesChanged(Set<Integer> indexes) {
|
@Override
|
||||||
|
public void valuesChanged(Set<Integer> indexes) {
|
||||||
// For any event from the generator, refresh the whole viewer.
|
// For any event from the generator, refresh the whole viewer.
|
||||||
refreshViewer();
|
refreshViewer();
|
||||||
}
|
}
|
||||||
|
@ -151,7 +156,8 @@ public class SyncDataViewer
|
||||||
// thread before calling the viewer.
|
// thread before calling the viewer.
|
||||||
Display display = fViewer.getControl().getDisplay();
|
Display display = fViewer.getControl().getDisplay();
|
||||||
display.asyncExec( new Runnable() {
|
display.asyncExec( new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
if (!fViewer.getControl().isDisposed()) {
|
if (!fViewer.getControl().isDisposed()) {
|
||||||
fViewer.refresh();
|
fViewer.refresh();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue