@Override public List<RequestData> getRequests() { synchronized (requestWindowLock) { RequestData[] result = new RequestData[hasBufferRolledOver() ? requestWindow.length : indexInWindow]; copyRequestsInOrder(result); return Arrays.asList(result); } }
@Override public void logEventTarget(IRequestHandler requestHandler) { RequestData requestData = getCurrentRequest(); if (requestData != null) { requestData.setEventTarget(requestHandler); } }
/** * Construct. */ public AbstractRequestLogger() { int requestsWindowSize = getRequestsWindowSize(); requestWindow = new RequestData[requestsWindowSize]; liveSessions = new ConcurrentHashMap<>(); }
int newCapacity = getRequestsWindowSize(); int oldNumberOfElements = hasBufferRolledOver() ? oldCapacity : indexInWindow; copyRequestsInOrder(newRequestWindow); copyRequestsInOrder(sortedRequestWindow);
requestdata.setSessionId(sessionId); Object sessionInfo = getSessionInfo(session); requestdata.setSessionInfo(sessionInfo); requestdata.setTimeTaken(timeTaken); addRequest(requestdata); sessionCreated(sessionId); sessiondata = liveSessions.get(sessionId);
@Override public long getAverageRequestTime() { synchronized (requestWindowLock) { int windowSize = getWindowSize(); if (windowSize == 0) return 0; return totalRequestTime / windowSize; } }
@Override public void performLogging() { RequestData requestdata = RequestCycle.get().getMetaData(REQUEST_DATA); if (requestdata != null) { // log the request- and sessiondata (the latter can be null) SessionData sessiondata = RequestCycle.get().getMetaData(SESSION_DATA); log(requestdata, sessiondata); } }
/** * Copies all request data into {@code copy} such that the oldest request is in slot 0 and the * most recent request is in slot {@code copy.length} * * @param copy * the target, has to have a capacity of at least {@code requestWindow.length} */ private void copyRequestsInOrder(RequestData[] copy) { int destPos = 0; if (hasBufferRolledOver()) { destPos = requestWindow.length - indexInWindow; // first copy the oldest requests stored behind the cursor into the copy arraycopy(requestWindow, indexInWindow, copy, 0, destPos); } arraycopy(requestWindow, 0, copy, destPos, indexInWindow); }
protected void addRequest(RequestData rd) { // ensure the buffer has the proper installed length resizeBuffer(); synchronized (requestWindowLock) { // if the requestWindow is a zero-length array, nothing gets stored if (requestWindow.length == 0) return; // use the oldest request data to recalculate the average request time RequestData old = requestWindow[indexInWindow]; // replace the oldest request with the nweset request requestWindow[indexInWindow] = rd; // move the cursor to the next writable position containing the oldest request or if the // buffer hasn't been filled completely the first empty slot indexInWindow = (indexInWindow + 1) % requestWindow.length; if (old != null) { startTimeOfOldestRequest = requestWindow[indexInWindow].getStartDate(); totalRequestTime -= old.getTimeTaken(); } else { if (startTimeOfOldestRequest == null) startTimeOfOldestRequest = rd.getStartDate(); } totalRequestTime += rd.getTimeTaken(); } }
int newCapacity = getRequestsWindowSize(); int oldNumberOfElements = hasBufferRolledOver() ? oldCapacity : indexInWindow; copyRequestsInOrder(newRequestWindow); copyRequestsInOrder(sortedRequestWindow);
requestdata.setSessionId(sessionId); Object sessionInfo = getSessionInfo(session); requestdata.setSessionInfo(sessionInfo); requestdata.setTimeTaken(timeTaken); addRequest(requestdata); sessionCreated(sessionId); sessiondata = liveSessions.get(sessionId);
@Override public long getAverageRequestTime() { synchronized (requestWindowLock) { int windowSize = getWindowSize(); if (windowSize == 0) return 0; return totalRequestTime / windowSize; } }
@Override public void performLogging() { RequestData requestdata = RequestCycle.get().getMetaData(REQUEST_DATA); if (requestdata != null) { // log the request- and sessiondata (the latter can be null) SessionData sessiondata = RequestCycle.get().getMetaData(SESSION_DATA); log(requestdata, sessiondata); } }
/** * Copies all request data into {@code copy} such that the oldest request is in slot 0 and the * most recent request is in slot {@code copy.length} * * @param copy * the target, has to have a capacity of at least {@code requestWindow.length} */ private void copyRequestsInOrder(RequestData[] copy) { int destPos = 0; if (hasBufferRolledOver()) { destPos = requestWindow.length - indexInWindow; // first copy the oldest requests stored behind the cursor into the copy arraycopy(requestWindow, indexInWindow, copy, 0, destPos); } arraycopy(requestWindow, 0, copy, destPos, indexInWindow); }
protected void addRequest(RequestData rd) { // ensure the buffer has the proper installed length resizeBuffer(); synchronized (requestWindowLock) { // if the requestWindow is a zero-length array, nothing gets stored if (requestWindow.length == 0) return; // use the oldest request data to recalculate the average request time RequestData old = requestWindow[indexInWindow]; // replace the oldest request with the nweset request requestWindow[indexInWindow] = rd; // move the cursor to the next writable position containing the oldest request or if the // buffer hasn't been filled completely the first empty slot indexInWindow = (indexInWindow + 1) % requestWindow.length; if (old != null) { startTimeOfOldestRequest = requestWindow[indexInWindow].getStartDate(); totalRequestTime -= old.getTimeTaken(); } else { if (startTimeOfOldestRequest == null) startTimeOfOldestRequest = rd.getStartDate(); } totalRequestTime += rd.getTimeTaken(); } }
@Override public List<RequestData> getRequests() { synchronized (requestWindowLock) { RequestData[] result = new RequestData[hasBufferRolledOver() ? requestWindow.length : indexInWindow]; copyRequestsInOrder(result); return Arrays.asList(result); } }
@Override public void logResponseTarget(IRequestHandler requestHandler) { RequestData requestData = getCurrentRequest(); if (requestData != null) requestData.setResponseTarget(requestHandler); }
@Override public long getRequestsPerMinute() { synchronized (requestWindowLock) { int windowSize = getWindowSize(); if (windowSize == 0) return 0; long start = startTimeOfOldestRequest.getTime(); long end = System.currentTimeMillis(); double diff = end - start; return Math.round(windowSize / (diff / 60000.0)); } }
/** * Construct. */ public AbstractRequestLogger() { int requestsWindowSize = getRequestsWindowSize(); requestWindow = new RequestData[requestsWindowSize]; liveSessions = new ConcurrentHashMap<>(); }
@Override public void logRequestedUrl(String url) { getCurrentRequest().setRequestedUrl(url); }