Skip to content

Commit 9c460f0

Browse files
committed
Lots of final adjustments to the documentation.
1 parent 6606ff1 commit 9c460f0

9 files changed

Lines changed: 98 additions & 8 deletions

File tree

src/main/java/nl/rug/jbi/jsm/bcel/CompositeBCELClassLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* The primary purpose of this class is to act as a source for {@link org.apache.bcel.classfile.JavaClass} within the
1616
* BCEL library.
1717
* It also records the source of the class files so this information can be used for collection-based metrics.
18-
* <p></p>
18+
* <br>
1919
* Be aware that this class is not a functional class loader, it only implements what is required to provide
2020
* functionality to BCEL.
2121
*
@@ -29,7 +29,7 @@ public class CompositeBCELClassLoader extends ClassLoader {
2929

3030
/**
3131
* Construct a composite class loader which draws its classes from the sources provided.
32-
* <p></p>
32+
* <br>
3333
* Internally the provided URLs are converted into class-loaders with reverse-mappings to identifiable names.
3434
*
3535
* @param externalSources URL objects referencing outside resources, defined for URLs representing directories
@@ -69,7 +69,7 @@ private void storeMapping(final String classFileName, final String source) {
6969
/**
7070
* Looks for class files by linear search though the provided resources, if the class cannot be found in the
7171
* provided locations, the {@link ClassLoader#getSystemClassLoader()} will be queried.
72-
* <p></p>
72+
* <br>
7373
* {@inheritDoc}
7474
*/
7575
@Override

src/main/java/nl/rug/jbi/jsm/bcel/JavaClassDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String getSuperClass() {
4949

5050
/**
5151
* @return Transitive list of all results from {@link #getSuperClass()}.
52-
* @throws nl.rug.jbi.jsm.bcel.MissingDataException
52+
* @throws nl.rug.jbi.jsm.bcel.MissingDataException If one of the superclasses is missing.
5353
*/
5454
public List<String> getSuperClasses() {
5555
try {

src/main/java/nl/rug/jbi/jsm/core/execution/CalculationStageTask.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
import java.util.Map;
1515
import java.util.concurrent.CountDownLatch;
1616

17+
/**
18+
* Runnable that performs the first stage of the frame execution pipeline.
19+
* This consists of the following steps:
20+
* <ul>
21+
* <li>Execute the provided modifier, this is a Class Visitor or a {@link nl.rug.jbi.jsm.core.execution.DataListDispatcher}</li>
22+
* <li>Calculate the {@link nl.rug.jbi.jsm.core.calculator.IsolatedMetric} for the associated class.</li>
23+
* <li>Send the results, if they exist, to the frontend.</li>
24+
* </ul>
25+
*
26+
* @author David van Leusen
27+
* @since 2014-06-02
28+
*/
1729
class CalculationStageTask implements Runnable {
1830
private final static Logger logger = LogManager.getLogger(CalculationStageTask.class);
1931
private final CountDownLatch latch;

src/main/java/nl/rug/jbi/jsm/core/execution/CollectionStageTask.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
import java.util.concurrent.Callable;
1414
import java.util.concurrent.CountDownLatch;
1515

16+
/**
17+
* Runnable that performs the third stage of the frame execution pipeline.
18+
* This consists of the following steps:
19+
* <ul>
20+
* <li>Calculate a set of results/produce using the provided data and function.</li>
21+
* <li>Return the results/produce to the Controller Thread.</li>
22+
* </ul>
23+
*
24+
* @author David van Leusen
25+
* @since 2014-06-02
26+
*/
1627
class CollectionStageTask<M, R> implements Callable<List<R>> {
1728
private final static Predicate<MetricState> VALIDITY_FILTER = new Predicate<MetricState>() {
1829
@Override

src/main/java/nl/rug/jbi/jsm/core/execution/ControllerThread.java

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@
2222

2323
import static com.google.common.base.Preconditions.checkState;
2424

25+
/**
26+
* Implementation of the execution of the {@link nl.rug.jbi.jsm.core.pipeline.Pipeline}.
27+
* The execution is performed by performing the following loop.
28+
* <ul>
29+
* <li>{@link #performCalculationStage(java.util.Queue, java.util.List)}</li>
30+
* <li>{@link #performMetricCollection(nl.rug.jbi.jsm.core.pipeline.PipelineFrame, java.util.Map)}</li>
31+
* <li>{@link #performCollectionStage(java.util.Map, nl.rug.jbi.jsm.core.pipeline.PipelineFrame, java.util.List)}</li>
32+
* <li>{@link #prepareProduceForNextFrame(java.util.Map, java.util.List, nl.rug.jbi.jsm.core.calculator.MetricScope)}</li>
33+
* <li>If end of frame, merge data for the next scope into the deliverables for the next frame.</li>
34+
* <li>{@link #prepareCalculatorsForNextFrame(java.util.Queue, java.util.Map, nl.rug.jbi.jsm.core.pipeline.HandlerMap)}</li>
35+
* <li>If there is no next frame, exit loop.</li>
36+
* </ul>
37+
*
38+
* @author David van Leusen
39+
* @since 2014-06-02
40+
*/
2541
class ControllerThread extends Thread {
2642
private final static Logger logger = LogManager.getLogger(ControllerThread.class);
2743
private final static AtomicInteger UNIQUE_EXECUTION_ID = new AtomicInteger(0);
@@ -107,6 +123,7 @@ public void run() {
107123
final Repository repo = this.executionPlan.getRepository();
108124
final ClassVisitorFactory cvFactory = this.executionPlan.getClassVisitorFactory();
109125

126+
//Create the base set of modifiers for the first frame, based on the classes that need to be inspected.
110127
for (final Map.Entry<String, EventBus> entry : this.stateContainers.entrySet()) {
111128
try {
112129
final JavaClass jc = repo.loadClass(entry.getKey());
@@ -187,6 +204,7 @@ public void run() {
187204
logger.debug("State containers and tasks added for next scope.");
188205
}
189206

207+
//Prepare tasks containing data for the next frame.
190208
prepareCalculatorsForNextFrame(
191209
taskQueue,
192210
nextFrameExecutionData,
@@ -201,6 +219,12 @@ public void run() {
201219
executionPlan.onFinish();
202220
}
203221

222+
/**
223+
* Step that gets executed at the end of the frame, it will turn the produce produced by the producers into a set of
224+
* {@link nl.rug.jbi.jsm.core.execution.DataListDispatcher} for execution in the next frame.
225+
*
226+
* @see nl.rug.jbi.jsm.core.execution.DataListDispatcher
227+
*/
204228
private void prepareCalculatorsForNextFrame(
205229
final Queue<Pair<EventBus, Runnable>> taskQueue,
206230
final Map<String, List<Object>> executionData,
@@ -213,7 +237,7 @@ private void prepareCalculatorsForNextFrame(
213237
} else {
214238
logger.warn(
215239
"Request for undefined identifier, might indicate that " +
216-
"a producer is returning wrong data: '{}'",
240+
"a producer is returning wrong identifiers: '{}'",
217241
entry.getKey()
218242
);
219243

@@ -224,6 +248,13 @@ private void prepareCalculatorsForNextFrame(
224248
}
225249
}
226250

251+
/**
252+
* Processes the produce of {@link #performCollectionStage(java.util.Map, nl.rug.jbi.jsm.core.pipeline.PipelineFrame, java.util.List)}
253+
* by splitting the produce based on whether it needs to be delivered in the current frame or a future frame.
254+
* The produce meant for the current frame gets prepared to be sent to
255+
* {@link #prepareCalculatorsForNextFrame(java.util.Queue, java.util.Map, nl.rug.jbi.jsm.core.pipeline.HandlerMap)}
256+
* while the other produce gets stored based on the scope its meant to be delivered in.
257+
*/
227258
private void prepareProduceForNextFrame(
228259
final Map<String, List<Object>> executionMap,
229260
final List<ProducerMetric.Produce> produceList,
@@ -249,6 +280,16 @@ private void prepareProduceForNextFrame(
249280
}
250281
}
251282

283+
/**
284+
* Based on the data collected by {@link #performMetricCollection(nl.rug.jbi.jsm.core.pipeline.PipelineFrame, java.util.Map)}
285+
* calculate both results and produce of declared {@link nl.rug.jbi.jsm.core.calculator.SharedMetric} and
286+
* {@link nl.rug.jbi.jsm.core.calculator.ProducerMetric}.
287+
* The results from the shared metrics will be sent off to the frontend while the produce gets returned to the loop
288+
* for further processing.
289+
*
290+
* @see nl.rug.jbi.jsm.core.execution.CollectionStageTask#forSharedMetric(nl.rug.jbi.jsm.core.calculator.SharedMetric, java.util.Map, java.util.concurrent.CountDownLatch)
291+
* @see nl.rug.jbi.jsm.core.execution.CollectionStageTask#forProducer(nl.rug.jbi.jsm.core.calculator.ProducerMetric, java.util.Map, java.util.concurrent.CountDownLatch)
292+
*/
252293
private void performCollectionStage(
253294
final Map<Class, Map<String, MetricState>> dataMap,
254295
final PipelineFrame currentFrame,
@@ -262,6 +303,7 @@ private void performCollectionStage(
262303
final List<Pair<SharedMetric, Future<List<MetricResult>>>> futureResults = Lists.newLinkedList();
263304
final List<Pair<ProducerMetric, Future<List<ProducerMetric.Produce>>>> futureProduce = Lists.newLinkedList();
264305

306+
//Begin execution of Shared Metric collection
265307
for (final SharedMetric metric : sharedMetrics) {
266308
final Map<String, MetricState> data = dataMap.get(metric.getClass());
267309
futureResults.add(new Pair<SharedMetric, Future<List<MetricResult>>>(
@@ -270,6 +312,7 @@ private void performCollectionStage(
270312
));
271313
}
272314

315+
//Begin execution of Producer collection
273316
for (final ProducerMetric metric : producerMetrics) {
274317
final Map<String, MetricState> data = dataMap.get(metric.getClass());
275318
futureProduce.add(new Pair<ProducerMetric, Future<List<ProducerMetric.Produce>>>(
@@ -323,9 +366,13 @@ private void performCollectionStage(
323366
}
324367
}
325368

369+
/**
370+
* Collects the states from the individual targets, then transposes the results so they are mapped by metric
371+
* instead of by target.
372+
*/
326373
private void performMetricCollection(
327374
final PipelineFrame currentFrame,
328-
final Map<Class, Map<String, MetricState>> dataMap
375+
final Map<Class, Map<String, MetricState>> outputMap
329376
) {
330377
final Table<String, Class, MetricState> dataTmp = HashBasedTable.create();
331378

@@ -341,9 +388,16 @@ private void performMetricCollection(
341388
}
342389

343390
//Output the data
344-
dataMap.putAll(Tables.transpose(dataTmp).rowMap());
391+
outputMap.putAll(Tables.transpose(dataTmp).rowMap());
345392
}
346393

394+
/**
395+
* Applies the set of modifiers left by the last frame and calculate the isolated metrics.
396+
* This stage happens in parallel within a {@link java.util.concurrent.ExecutorService}, this thread will block
397+
* until all individual processing is done.
398+
*
399+
* @see nl.rug.jbi.jsm.core.execution.CalculationStageTask
400+
*/
347401
private void performCalculationStage(
348402
final Queue<Pair<EventBus, Runnable>> taskQueue,
349403
final List<IsolatedMetric> isolatedMetrics
@@ -361,6 +415,7 @@ private void performCalculationStage(
361415
));
362416
}
363417

418+
//Block until individual processes are complete.
364419
calculationStageLatch.await();
365420
}
366421
}

src/main/java/nl/rug/jbi/jsm/core/execution/DataListDispatcher.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
import java.util.List;
66

7+
/**
8+
* Runnable that delivers a set of data to a shared target.
9+
* The data is produced by {@link nl.rug.jbi.jsm.core.calculator.ProducerMetric}
10+
* Used in tandem with {@link nl.rug.jbi.jsm.core.execution.CalculationStageTask}.
11+
*
12+
* @author David van Leusen
13+
* @since 2014-06-02
14+
*/
715
class DataListDispatcher implements Runnable {
816
private final EventBus eBus;
917
private final List objectList;

src/main/java/nl/rug/jbi/jsm/core/pipeline/Pipeline.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ private void registerMetricInternal(final BaseMetric metric) throws MetricPrepar
146146
}
147147
}
148148

149+
//Extract a set of data from the list of listeners.
149150
final Set<Class> usedData = FluentIterable.from(executors)
150151
.transform(new Function<Pair<Class, HandlerExecutor>, Class>() {
151152
@Override

src/main/java/nl/rug/jbi/jsm/util/BiFunction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public interface BiFunction<A, B, C> {
2222
* {@code Objects.equal(c, d)} implies that {@code Objects.equal(function.apply(a, c), function.apply(b, d))}.</li>
2323
* </ul>
2424
*
25+
* @param input1 First input
26+
* @param input2 Second input
27+
* @return A value based on input1 and input2
2528
* @throws java.lang.NullPointerException if {@code input1} or {@code input2} is null and this function does not
2629
* accept null arguments
2730
*/

src/main/java/nl/rug/jbi/jsm/util/ResultsExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Multi-file exporter for the metric results. Using the CSV-writer from the OpenCSV project, it will create a CSV file
20-
* for each Metric->ResultList association. Mappings between the various Metrics, Scopes and their result files will be
20+
* for each Metric-&gt;ResultList association. Mappings between the various Metrics, Scopes and their result files will be
2121
* put in the unique file with identifier "Mapping".
2222
*
2323
* @author David van Leusen

0 commit comments

Comments
 (0)