Search in sources :

Example 1 with CircularFifoQueue

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);
    }
}
Also used : CircularFifoQueue(org.apache.commons.collections4.queue.CircularFifoQueue) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ActionExecutedEvent(org.xwiki.bridge.event.ActionExecutedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) Collection(java.util.Collection) XWikiException(com.xpn.xwiki.XWikiException) RemoteObservationManagerContext(org.xwiki.observation.remote.RemoteObservationManagerContext)

Example 2 with CircularFifoQueue

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);
        }
    }
}
Also used : CircularFifoQueue(org.apache.commons.collections4.queue.CircularFifoQueue) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) WaitAndPrint(org.ow2.proactive.scheduler.examples.WaitAndPrint) Date(java.util.Date) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

CircularFifoQueue (org.apache.commons.collections4.queue.CircularFifoQueue)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Collection (java.util.Collection)1 Date (java.util.Date)1 WaitAndPrint (org.ow2.proactive.scheduler.examples.WaitAndPrint)1 ActionExecutedEvent (org.xwiki.bridge.event.ActionExecutedEvent)1 RemoteObservationManagerContext (org.xwiki.observation.remote.RemoteObservationManagerContext)1