use of org.apache.commons.collections4.queue.CircularFifoQueue in project xwiki-platform by xwiki.
the class XWikiStatsServiceImpl method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
if (Utils.getComponent(RemoteObservationManagerContext.class).isRemoteState()) {
// take care of this
return;
}
ActionExecutedEvent actionEvent = (ActionExecutedEvent) event;
XWikiDocument document = (XWikiDocument) source;
XWikiContext context = (XWikiContext) data;
// anything in the database)
if (context.getWiki().isReadOnly()) {
return;
}
// Initialize cookie used as unique identifier of a user visit and put it in the context
StatsUtil.findCookie(context);
String action = actionEvent.getActionName();
// Let's save in the session the last elements view, saved
synchronized (this) {
if (!action.equals(DownloadAction.ACTION_NAME)) {
Collection actions = StatsUtil.getRecentActionFromSessions(context, action);
if (actions == null) {
actions = new CircularFifoQueue(StatsUtil.getRecentVisitSize(context));
StatsUtil.setRecentActionsFromSession(context, action, actions);
}
String element = document.getPrefixedFullName();
if (actions.contains(element)) {
actions.remove(element);
}
actions.add(element);
}
}
try {
if (StatsUtil.isWikiStatsEnabled(context) && !StatsUtil.getStorageFilteredUsers(context).contains(this.currentDocumentReferenceResolver.resolve(context.getUser()))) {
this.statsRegister.addStats(document, action, context);
}
} catch (Exception e) {
LOGGER.error("Faild to get filter users list", e);
}
}
use of org.apache.commons.collections4.queue.CircularFifoQueue in project scheduling by ow2-proactive.
the class TestJobServerLogs method printDiagnosticMessage.
private void printDiagnosticMessage() {
int LIMIT = 5;
System.out.println("This test is going to fail, but before we print diagnostic message." + simpleDateFormat.format(new Date()));
// iterate over all files in the 'logsLocation'
for (File file : FileUtils.listFiles(new File(logsLocation), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
try {
BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
System.out.println(String.format("Name: %s, Size: %d, Created: %s, Modified: %s", file.getAbsolutePath(), attr.size(), attr.creationTime(), attr.lastModifiedTime()));
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
int i;
// print up to LIMIT first lines
for (i = 0; i < LIMIT && (line = br.readLine()) != null; ++i) {
System.out.println(line);
}
Queue<String> queue = new CircularFifoQueue<>(LIMIT);
// reading last LIMIT lines
for (; (line = br.readLine()) != null; ++i) {
queue.add(line);
}
if (i >= LIMIT * 2) {
// if there is more line than 2*LIMIT
System.out.println(".......");
System.out.println("....... (skipped content)");
System.out.println(".......");
}
for (String l : queue) {
// print rest of the file
System.out.println(l);
}
System.out.println("------------------------------------");
System.out.println();
} catch (IOException e) {
System.out.println("Exception ocurred during accessing file attributes " + e);
}
}
}
Aggregations