Package org.apache.wicket.util.time

Examples of org.apache.wicket.util.time.Time


  public Time lastModifiedTime()
  {
    try
    {
      // get url modification timestamp
      final Time time = Connections.getLastModified(url);

      // if timestamp changed: update content length and last modified date
      if (Objects.equal(time, lastModified) == false)
      {
        lastModified = time;
View Full Code Here


   *
   * @return date header with specified name
   */
  public Time getDateHeader(String name)
  {
    final Time time = headers.getDateHeader(name);

    if (time == null)
    {
      throw new WicketRuntimeException("Date header '" + name + "' is not set.");
    }
View Full Code Here

    Boolean booleanValue = true;
    Integer integerValue = 42;
    Long longValue = integerValue * 1L;
    Double doubleValue = integerValue * 1.0D;
    Time timeValue = Time.now();
    Duration durationValue = Duration.hours(1);

    boolean defBoolean = !booleanValue;
    int defInteger = 10101;
    long defLong = defInteger * 1L;
    double defDouble = defInteger * 1.0D;
    Time defTime = Time.now();
    Duration defDuration = Duration.hours(42);

    vm.put("num", integerValue.toString());
    vm.put("num.bad", "xxx");
    vm.put("time", timeValue.toString());
View Full Code Here

   */
  public void lockPage(int pageId) throws CouldNotLockPageException
  {
    final Thread thread = Thread.currentThread();
    final PageLock lock = new PageLock(pageId, thread);
    final Time start = Time.now();

    boolean locked = false;

    final boolean isDebugEnabled = logger.isDebugEnabled();

    while (!locked && start.elapsedSince().lessThan(timeout))
    {
      if (isDebugEnabled)
      {
        logger.debug("'{}' attempting to acquire lock to page with id '{}'",
          thread.getName(), pageId);
      }

      PageLock previous = locks.get().putIfAbsent(pageId, lock);
      if (previous == null || previous.getThread() == thread)
      {
        // first thread to acquire lock or lock is already owned by this thread
        locked = true;
      }
      else
      {
        // wait for a lock to become available
        long remaining = remaining(start, timeout);
        if (remaining > 0)
        {
          synchronized (previous)
          {
            if (isDebugEnabled)
            {
              logger.debug("{} waiting for lock to page {} for {}", new Object[] {
                  thread.getName(), pageId, Duration.milliseconds(remaining) });
            }
            try
            {
              previous.wait(remaining);
            }
            catch (InterruptedException e)
            {
              // TODO better exception
              throw new RuntimeException(e);
            }
          }
        }
      }
    }
    if (locked)
    {
      if (isDebugEnabled)
      {
        logger.debug("{} acquired lock to page {}", thread.getName(), pageId);
      }
    }
    else
    {
      if (logger.isWarnEnabled())
      {
        logger.warn(
          "{} failed to acquire lock to page {}, attempted for {} out of allowed {}",
          new Object[] { thread.getName(), pageId, start.elapsedSince(), timeout });
      }
      throw new CouldNotLockPageException(pageId, thread.getName(), timeout);
    }
  }
View Full Code Here

    {
      duration = MAX_CACHE_DURATION;
    }

    // Get current time
    Time now = Time.now();

    // Time of message generation
    setDateHeader("Date", now);

    // Time for cache expiry = now + duration
    setDateHeader("Expires", now.add(duration));

    // Enable caching and set max age
    setHeader("Cache-Control", scope.cacheControl);
    addHeader("Cache-Control", "max-age=" + duration.getMilliseconds());
  }
View Full Code Here

  @Test
  public void testBlocking() throws Exception
  {
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(5));
    final Duration hold = Duration.seconds(1);
    final Time t1locks[] = new Time[1];
    final Time t2locks[] = new Time[1];

    class T1 extends Thread
    {
      @Override
      public void run()
View Full Code Here

    {
      @Override
      public void run()
      {
        Random random = new Random();
        Time start = Time.now();

        while (start.elapsedSince().lessThan(duration) && error[0] == null)
        {
          logger.info("{} elapsed: {}, duration: {}", new Object[] {
              Thread.currentThread().getName(), start.elapsedSince(), duration });
          int page1 = random.nextInt(counts.length);
          int page2 = random.nextInt(counts.length);
          int count = 0;
          while (page2 == page1 && count < 100)
          {
View Full Code Here

    {
      @Override
      public void run()
      {
        Random random = new Random();
        Time start = Time.now();

        while (start.elapsedSince().lessThan(duration) && error[0] == null)
        {
          logger.info("{} elapsed: {}, duration: {}", new Object[] {
              Thread.currentThread().getName(), start.elapsedSince(), duration });
          int page1 = random.nextInt(counts.length);
          int page2 = random.nextInt(counts.length);
          int count = 0;
          while (page2 == page1 && count < 100)
          {
View Full Code Here

            "Unable to find resource");

        resourceResponse.setContentType(findContentType(resources));

        // add Last-Modified header (to support HEAD requests and If-Modified-Since)
        final Time lastModified = findLastModified(resources);

        if (lastModified != null)
          resourceResponse.setLastModified(lastModified);

        // read resource data
View Full Code Here

    return null;
  }

  protected Time findLastModified(List<IResourceStream> resources)
  {
    Time ret = null;
    for (IResourceStream curStream : resources)
    {
      Time curLastModified = curStream.lastModifiedTime();
      if (ret == null || curLastModified.after(ret))
        ret = curLastModified;
    }
    return ret;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.time.Time

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.