Package org.apache.wicket.util.time

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


  @Override
  protected ResourceResponse newResourceResponse(Attributes attributes)
  {
    final IResourceStream resourceStream = internalGetResourceStream();
    ResourceResponse data = new ResourceResponse();
    Time lastModifiedTime = resourceStream.lastModifiedTime();
    if (lastModifiedTime != null)
    {
      data.setLastModified(lastModifiedTime);
    }
View Full Code Here


    if (response instanceof WebResponse)
    {
      WebResponse webResponse = (WebResponse)response;

      // 1. Last Modified
      Time lastModified = data.getLastModified();
      if (lastModified != null)
      {
        webResponse.setLastModifiedTime(lastModified);
      }
View Full Code Here

     *         <code>false</code> otherwise.
     */
    public boolean dataNeedsToBeWritten(Attributes attributes)
    {
      WebRequest request = (WebRequest)attributes.getRequest();
      Time ifModifiedSince = request.getIfModifiedSinceHeader();

      if (cacheDuration != Duration.NONE && ifModifiedSince != null && lastModified != null)
      {
        // [Last-Modified] headers have a maximum precision of one second
        // so we have to truncate the milliseconds part for a proper compare.
        // that's stupid, since changes within one second will not be reliably
        // detected by the client ... any hint or clarification to improve this
        // situation will be appreciated...
        Time roundedLastModified = Time.millis(lastModified.getMilliseconds() / 1000 * 1000);

        return ifModifiedSince.before(roundedLastModified);
      }
      else
      {
View Full Code Here

      return sendResourceError(resourceResponse, HttpServletResponse.SC_NOT_FOUND,
          "Unable to find resource");
    }

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

    resourceResponse.setLastModified(lastModified);

    if (resourceResponse.dataNeedsToBeWritten(attributes))
    {
View Full Code Here

    final Entry entry = modifiableToEntry.get(modifiable);

    // Found it?
    if (entry == null)
    {
      Time lastModifiedTime = modifiable.lastModifiedTime();
      if (lastModifiedTime != null)
      {
        // Construct new entry
        final Entry newEntry = new Entry();
View Full Code Here

  {
    for (Entry entry : modifiableToEntry.values())
    {
      // If the modifiable has been modified after the last known
      // modification time
      final Time modifiableLastModified = entry.modifiable.lastModifiedTime();
      if ((modifiableLastModified != null) &&
          modifiableLastModified.after(entry.lastModifiedTime))
      {
        // Notify all listeners that the modifiable was modified
        entry.listeners.notifyListeners();

        // Update timestamp
View Full Code Here

      return sendResourceError(resourceResponse, HttpServletResponse.SC_NOT_FOUND,
          "Unable to find resource");
    }

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

    resourceResponse.setLastModified(lastModified);

    if (resourceResponse.dataNeedsToBeWritten(attributes))
    {
View Full Code Here

    if (stream == null)
    {
      return null;
    }

    final Time lastModified = stream.lastModifiedTime();

    // if no timestamp is available we can not provide a version
    if (lastModified == null)
    {
      return null;
    }
    // version string = last modified timestamp converted to milliseconds
    return String.valueOf(lastModified.getMilliseconds()).intern();
  }
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();

    PageLock previous = null;

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

      previous = locks.get().putIfAbsent(pageId, lock);

      if (previous == null || previous.thread == 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)
        {
          previous.waitForRelease(remaining, isDebugEnabled);
        }
      }
    }
    if (locked)
    {
      if (isDebugEnabled)
      {
        logger.debug("{} acquired lock to page {}", thread.getName(), pageId);
      }
    }
    else
    {
      if (logger.isWarnEnabled())
      {
        logger.warn(
          "Thread '{}' failed to acquire lock to page with id '{}', attempted for {} out of allowed {}. The thread that holds the lock has name '{}'.",
          new Object[] { thread.getName(), pageId, start.elapsedSince(), timeout,
              previous.thread.getName() });
        if (Application.exists())
        {
          ThreadDumpStrategy strategy = Application.get()
            .getExceptionSettings()
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

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.