"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/java/com/rapidminer/tools/usagestats/CtaEventAggregator.java" between
rapidminer-studio-9.4.1-src.tar.gz and rapidminer-studio-9.5.0-src.tar.gz

About: RapidMiner Studio is a code-free environment for designing advanced analytic processes with machine learning, data mining, text mining, predictive analytics and business analytics. Java source.

CtaEventAggregator.java  (rapidminer-studio-9.4.1-src):CtaEventAggregator.java  (rapidminer-studio-9.5.0-src)
skipping to change at line 22 skipping to change at line 22
* This program is distributed in the hope that it will be useful, but WITHOUT A NY WARRANTY; without * This program is distributed in the hope that it will be useful, but WITHOUT A NY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP OSE. See the GNU * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURP OSE. See the GNU
* Affero General Public License for more details. * Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License alon g with this program. * You should have received a copy of the GNU Affero General Public License alon g with this program.
* If not, see http://www.gnu.org/licenses/. * If not, see http://www.gnu.org/licenses/.
*/ */
package com.rapidminer.tools.usagestats; package com.rapidminer.tools.usagestats;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import java.util.logging.Level;
import com.rapidminer.Process;
import com.rapidminer.RapidMiner; import com.rapidminer.RapidMiner;
import com.rapidminer.RapidMiner.ExecutionMode; import com.rapidminer.RapidMiner.ExecutionMode;
import com.rapidminer.io.process.ProcessOriginProcessXMLFilter; import com.rapidminer.io.process.ProcessOriginProcessXMLFilter;
import com.rapidminer.tools.LogService;
import com.rapidminer.tools.Tools;
import com.rapidminer.settings.Telemetry;
import com.rapidminer.tools.usagestats.ActionStatisticsCollector.Key; import com.rapidminer.tools.usagestats.ActionStatisticsCollector.Key;
/** /**
* Aggregates UsageStats events for the cta system * Aggregates UsageStats events for the cta system
* *
* The event counts are aggregated, to reduce the load on the database. * The event counts are aggregated, to reduce the load on the database.
* *
* Every time {@link pullEvents()} is called, the aggregation starts again. * Every time {@link #pullEvents()} is called, the aggregation starts again.
* *
* @author Jonas Wilms-Pfau * @author Jonas Wilms-Pfau
* @since 7.5.0 * @since 7.5.0
* *
*/ */
enum CtaEventAggregator { public enum CtaEventAggregator {
INSTANCE; INSTANCE;
/** The current event map */ /**
* The current event map
*/
private volatile Map<Key, Long> eventMap = new ConcurrentHashMap<>(); private volatile Map<Key, Long> eventMap = new ConcurrentHashMap<>();
/** this is set to true during init of the CTA extension */
private AtomicBoolean ctaSystemLive = new AtomicBoolean(false);
/** this is set to true if the aggregator is killed due to the CTA system
not being live after extensions have been loaded */
private AtomicBoolean killed = new AtomicBoolean(false);
/** Locks for synchronization */ /** Locks for synchronization */
private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private ReadLock readLock = lock.readLock(); private ReadLock readLock = lock.readLock();
private WriteLock writeLock = lock.writeLock(); private WriteLock writeLock = lock.writeLock();
private static final boolean NOT_IN_UI_MODE = !RapidMiner.getExecutionMod e().equals(ExecutionMode.UI); private static final boolean UI_MODE = RapidMiner.getExecutionMode().equa ls(ExecutionMode.UI);
/** /**
* Represents the keys that are not to be written to the CTA database. * Checks if logging is allowed
* The log items should be filtered by checking for all blacklist items, *
* that determine which log parts are to be matched. * @return {@code true} if logging is not allowed
*/
private static boolean loggingAllowed() {
return UI_MODE && !Telemetry.USAGESTATS.isDenied();
}
/**
* Represents the keys that are not to be written to the CTA database. Th
e log items should be filtered by checking
* for all blacklist items, that determine which log parts are to be matc
hed.
*/ */
private static class BlackListItem { private static class BlackListItem {
/** /**
* The key to be matched. * The key to be matched.
*/ */
private final Key key; private final Key key;
/** /**
* Match for the type of the key is obligatory. * Match for the type of the key is obligatory.
*/ */
skipping to change at line 90 skipping to change at line 109
this.key = key; this.key = key;
this.useType = useType; this.useType = useType;
this.useValue = useValue; this.useValue = useValue;
this.useArg = useArg; this.useArg = useArg;
} }
boolean matchesKey(Key key) { boolean matchesKey(Key key) {
if (key == null) { if (key == null) {
return false; return false;
} }
if (useType && ( if (useType && !Objects.equals(this.key.getType(), key.ge
this.key.getType() == null && key.getType tType())) {
() != null
|| this.key.getType() !=
null && !this.key.getType().equals(key.getType())
)) {
return false; return false;
} }
if (useValue && ( if (useValue && !Objects.equals(this.key.getValue(), key.
this.key.getValue() == null && key.getVal getValue())) {
ue() != null
|| this.key.getValue() !=
null && !this.key.getValue().equals(key.getValue())
)) {
return false; return false;
} }
if (useArg && ( if (useArg && !Objects.equals(this.key.getArgWithIndicato
this.key.getArgWithIndicators() == null & rs(), key.getArgWithIndicators())) {
& key.getArgWithIndicators() != null
|| this.key.getArgWithInd
icators() != null && !this.key.getArgWithIndicators().equals(key.getArgWithIndic
ators())
)) {
return false; return false;
} }
return true; return true;
} }
} }
private static final BlackListItem[] BLACKLIST = new BlackListItem[4 + Pr ocessOriginProcessXMLFilter.ProcessOriginState.values().length]; private static final BlackListItem[] BLACKLIST = new BlackListItem[4 + Pr ocessOriginProcessXMLFilter.ProcessOriginState.values().length];
static { static {
// the argument of logged exceptions are too long and irrelevant // the argument of logged exceptions are too long and irrelevant
int i = 0; int i = 0;
BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec tor.TYPE_PROCESS, ActionStatisticsCollector.VALUE_EXCEPTION, BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec tor.TYPE_PROCESS, ActionStatisticsCollector.VALUE_EXCEPTION,
null), true, true, false); null), true, true, false);
for (ProcessOriginProcessXMLFilter.ProcessOriginState state : Pro cessOriginProcessXMLFilter.ProcessOriginState.values()) { for (ProcessOriginProcessXMLFilter.ProcessOriginState state : Pro cessOriginProcessXMLFilter.ProcessOriginState.values()) {
BLACKLIST[i++] = new BlackListItem(new Key(state.getPrefi x() + ActionStatisticsCollector.TYPE_PROCESS, ActionStatisticsCollector.VALUE_EX CEPTION, BLACKLIST[i++] = new BlackListItem(new Key(state.getPrefi x() + ActionStatisticsCollector.TYPE_PROCESS, ActionStatisticsCollector.VALUE_EX CEPTION,
null), true, true, false); null), true, true, false);
} }
// progress-thread typed logs are irrelevant // progress-thread typed logs are irrelevant
BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec tor.TYPE_PROGRESS_THREAD, null, BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec tor.TYPE_PROGRESS_THREAD, null,
null), true, false, false); null), true, false, false);
// resource-action typed logs are irrelevant, use "action" type i n CTA rules instead // resource-action typed logs are irrelevant, use "action" type i n CTA rules instead
BLACKLIST[i++] = new BlackListItem(new Key(Action BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec
StatisticsCollector.TYPE_RESOURCE_ACTION, null, tor.TYPE_RESOURCE_ACTION, null,
null), true, false, false); null), true, false, false);
// simple-action typed logs are irrelevant, use "action" type in CTA rules instead // simple-action typed logs are irrelevant, use "action" type in CTA rules instead
BLACKLIST[i++] = new BlackListItem(new Key(Action BLACKLIST[i++] = new BlackListItem(new Key(ActionStatisticsCollec
StatisticsCollector.TYPE_SIMPLE_ACTION, null, tor.TYPE_SIMPLE_ACTION, null,
null), true, false, false); null), true, false, false);
} }
/** /**
* Log the event * Log the event
* *
* @param type * @param type the type of the event
* @param value * @param value the value of the event
* @param arg * @param arg the argument of the event
* @param count * @param count the number of time the event happened
*/ */
public void log(String type, String value, String arg, long count) { public void log(String type, String value, String arg, long count) {
log(new Key(type, value, arg), count); log(new Key(type, value, arg), count);
} }
/** /**
* Log the event * Log the event
* *
* @param event * @param event
* the event
* @param count * @param count
* the number of times the event occured
*/ */
public void log(Key event, long count) { public void log(Key event, long count) {
// Disable logging on server if (loggingAllowed() && !isBlacklisted(event) && !killed.get()) {
if (NOT_IN_UI_MODE || !validateKey(event)) { logNow(event, count);
return;
} }
}
/**
* Allows to log a short version of a blacklisted event
*
* @param event
* the event
* @param count
* the number of times the event occurred
* @since 9.5.0
*/
void logBlacklistedKey(Key event, long count) {
if (loggingAllowed() && isBlacklisted(event)) {
logNow(event, count);
}
}
/**
* Log the event
* <p>Warning: this method does not check anything, call {@link #loggingA
llowed()} before calling this method.</p>
*
* @param event
* the event
* @param count
* the number of times the event occurred
*/
private void logNow(Key event, long count) {
readLock.lock(); readLock.lock();
try { try {
eventMap.merge(event, count, Long::sum); eventMap.merge(event, count, Long::sum);
} finally { } finally {
readLock.unlock(); readLock.unlock();
} }
} }
/** /**
* Remove and return all events * Remove and return all events
* *
* @return * @return events with count since the last invocation of this method
*/ */
public Map<Key, Long> pullEvents() { public Map<Key, Long> pullEvents() {
Map<Key, Long> result = eventMap; Map<Key, Long> result = eventMap;
writeLock.lock(); writeLock.lock();
try { try {
eventMap = new ConcurrentHashMap<>(); eventMap = new ConcurrentHashMap<>();
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
} }
return result; return result;
} }
/** /**
* Returns true if no item of the blacklist matched the key. * Sets the CTA system to be available (the CTA extension calls this duri
ng loading).
*
* @since 9.5.0
*/
public void setCtaSystemLive() {
Tools.requireInternalPermission();
ctaSystemLive.set(true);
}
/**
* Whether the CTA system is available or not.
*
* @return {@code true} if the CTA system is available (i.e. the extensio
n is loaded); {@code false} otherwise
* @since 9.5.0
*/
public boolean isCtaSystemLive() {
return ctaSystemLive.get();
}
/**
* Internal API, do not call. Disable event aggregation to avoid building
a giant map when the CTA extension is not
* loaded. After this is called, no further calls are expected by this cl
ass during the lifetime of that Studio
* instance.
*
* @since 9.5.0
*/
public void killAggregator() {
Tools.requireInternalPermission();
LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.usa
gestats.CtaEventAggregator.killed");
killed.set(true);
// kill old map by ignoring pull results
pullEvents();
}
/**
* Returns {@code false} if no item of the blacklist matched the key.
* *
* @param key * @param key the event
* @return * @return {@code true} if the event is blacklisted
*/ */
private boolean validateKey(Key key) { private static boolean isBlacklisted(Key key) {
for (BlackListItem item : BLACKLIST) { for (BlackListItem item : BLACKLIST) {
if (item.matchesKey(key)) { if (item.matchesKey(key)) {
return false; return true;
} }
} }
return true; return false;
} }
} }
 End of changes. 29 change blocks. 
49 lines changed or deleted 128 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)