Skip to content

Commit 5ab7872

Browse files
committed
UsageStats: track more information
Specifically, let's track name, label, description and version. From a performance perspective, for each identifiable object (e.g., a ModuleInfo) we only need to interrogate and set this information once (until statistics are flushed), so hopefully it does not add too much overhead. The alternative -- reconstructing the information after the fact -- is tough because the framework lacks a unified way of looking up objects based on their identifiers. It is not required for Identifiable objects to register themselves in any way, so it may not be possible to learn anything else once the usage event is reported to the service.
1 parent 50832cf commit 5ab7872

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/main/java/org/scijava/usage/DefaultUsageService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ public UsageStats getUsage(final Object o) {
8989
return null;
9090
}
9191
final String id = ((Identifiable) o).getIdentifier();
92-
final String url = ((Locatable) o).getLocation();
93-
if (!stats.containsKey(id)) stats.put(id, new UsageStats(id, url));
92+
if (!stats.containsKey(id)) stats.put(id, new UsageStats(o));
9493
return stats.get(id);
9594
}
9695

src/main/java/org/scijava/usage/UsageStats.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,48 @@
3131

3232
package org.scijava.usage;
3333

34+
import org.scijava.AbstractBasicDetails;
35+
import org.scijava.BasicDetails;
3436
import org.scijava.Identifiable;
3537
import org.scijava.Locatable;
38+
import org.scijava.Versioned;
3639

3740
/**
3841
* Data structure storing usage statistics for a particular identifier.
3942
*
4043
* @author Curtis Rueden
4144
*/
42-
public class UsageStats implements Identifiable, Locatable {
45+
public class UsageStats extends AbstractBasicDetails implements Identifiable,
46+
Locatable, Versioned
47+
{
4348

4449
/** The object's unique identifier. */
4550
private String id;
4651

4752
/** This object's location URL. */
4853
private String url;
4954

55+
/** The object's version. */
56+
private String version;
57+
5058
/** Number of times the object was used. */
5159
private long count;
5260

53-
public UsageStats(final String id, final String url) {
54-
this.id = id;
55-
this.url = url;
61+
/**
62+
* Creates usage statistics for the given object. Note that while several
63+
* pieces of information are initially extracted from the object, no reference
64+
* is retained to the object itself.
65+
*/
66+
public UsageStats(final Object o) {
67+
if (o instanceof BasicDetails) {
68+
final BasicDetails basicDetails = (BasicDetails) o;
69+
setName(basicDetails.getName());
70+
setLabel(basicDetails.getLabel());
71+
setDescription(basicDetails.getDescription());
72+
}
73+
id = o instanceof Identifiable ? ((Identifiable) o).getIdentifier() : null;
74+
url = o instanceof Locatable ? ((Locatable) o).getLocation() : null;
75+
version = o instanceof Versioned ? ((Versioned) o).getVersion() : null;
5676
}
5777

5878
/** Gets the number of times the object has been used. */
@@ -79,4 +99,11 @@ public String getLocation() {
7999
return url;
80100
}
81101

102+
// -- Versioned methods --
103+
104+
@Override
105+
public String getVersion() {
106+
return version;
107+
}
108+
82109
}

0 commit comments

Comments
 (0)