Java Code Examples for java.util.concurrent.LinkedBlockingDeque#removeLast()

The following examples show how to use java.util.concurrent.LinkedBlockingDeque#removeLast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkedBlockingDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * removeLast() removes last element, or throws NSEE if empty
 */
public void testRemoveLast() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.removeLast());
    }
    try {
        q.removeLast();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekLast());
}
 
Example 2
Source File: RequestThrottleFilter.java    From publick-sling-blog with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
        final FilterChain chain) throws IOException, ServletException {

    final HttpServletRequest httpServletRequest = (HttpServletRequest)request;
    final HttpSession session = httpServletRequest.getSession(true);
    final String path = httpServletRequest.getPathInfo().toLowerCase();
    final String method = httpServletRequest.getMethod();

    if ("POST".equals(method) && path.startsWith(PublickConstants.SERVLET_PATH_PUBLIC)) {
        synchronized (session.getId().intern()) {
            LinkedBlockingDeque<Long> times = (LinkedBlockingDeque<Long>)session.getAttribute(TIMES);

            if (times == null) {
                times = new LinkedBlockingDeque<Long>();
                session.setAttribute(TIMES, times);
            }

            final long currentTimeMillis = System.currentTimeMillis();

            times.push(Long.valueOf(currentTimeMillis));
            final long cutoff = currentTimeMillis - (SECONDS * 1000);
            Long oldest = times.peekLast();
            while (oldest != null && oldest.longValue() < cutoff) {
                times.removeLast();
                oldest =  times.peekLast();
            }

            if (times.size() > HITS) {
                addResponseHeaderNoCache((HttpServletResponse)response);
                response.getWriter().println("Your request hit rate is too high;"
                        + " please press back, wait a few seconds, and then try again.");
                return;
            }
        }
    }
    chain.doFilter(request, response);
}
 
Example 3
Source File: LinkedBlockingDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * removeLast() removes last element, or throws NSEE if empty
 */
public void testRemoveLast() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.removeLast());
    }
    try {
        q.removeLast();
        shouldThrow();
    } catch (NoSuchElementException success) {}
    assertNull(q.peekLast());
}