Package org.apache.wicket.util.time

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


          try
          {
            while (!stop)
            {
              // Get the start of the current period
              final Time startOfPeriod = Time.now();

              if (log.isTraceEnabled())
              {
                log.trace("Run the job: '{}'", code);
              }

              try
              {
                // Run the user's code
                code.run(getLog());
              }
              catch (Exception e)
              {
                log.error(
                  "Unhandled exception thrown by user code in task " + name, e);
              }

              if (log.isTraceEnabled())
              {
                log.trace("Finished with job: '{}'", code);
              }

              // Sleep until the period is over (or not at all if it's
              // already passed)
              startOfPeriod.add(frequency).fromNow().sleep();
            }
          }
          catch (Exception x)
          {
            log.error("Task '{}' terminated", name, x);
View Full Code Here


          // Get resource stream
          IResourceStream stream = resource.getResourceStream();

          // Get last modified time from stream
          Time time = stream.lastModifiedTime();

          try
          {
            stream.close();
          }
          catch (IOException e)
          {
            // ignore
          }

          return time != null ? time.getMilliseconds() : -1;
        }
      }
      catch (AbortException e)
      {
        return -1;
View Full Code Here

    String name = resourceReference.getName();
    if (getApplication().getResourceSettings().getAddLastModifiedTimeToResourceReferenceUrl() &&
      !Strings.isEmpty(name) && !name.endsWith("/")) // test for / because it could be a
    // resource reference to a path..
    {
      Time time = resourceReference.lastModifiedTime();
      if (time != null)
      {
        if (parameters == null)
        {
          parameters = new ValueMap();
          parameters.put("w:lm", new Long(time.getMilliseconds() / 1000));
        }
      }
    }

    requestParameters.setParameters(parameters);
View Full Code Here

    private final byte[] _content;
    private final String _contentType;
    private final Time _lastModifiedTime;

    private LocalizedMergedResourceStream() {
      Time max = null;
      // final StringWriter w = new StringWriter(4096);
      ByteArrayOutputStream out = new ByteArrayOutputStream(4096);

      final ArrayList<IResourceStream> resourceStreams = new ArrayList<IResourceStream>(_specs.length);

      String contentType = null;
      for (int i = 0; i < _specs.length; i++) {
        final Class<?> scope = _specs[i].getScope();
        final String fileName = _specs[i].getFile();

        final IResourceStream resourceStream = findResourceStream(scope, fileName);
        if (contentType != null) {
          if (resourceStream.getContentType() != null
              && !contentType.equalsIgnoreCase(resourceStream.getContentType())) {
            log.warn("content types of merged resources don't match: '" + resourceStream.getContentType()
                + "' and '" + contentType + "'");
          }
        } else {
          contentType = resourceStream.getContentType();
        }

        try {

          final Time lastModified = resourceStream.lastModifiedTime();
          if (max == null || lastModified != null && lastModified.after(max)) {
            max = lastModified;
          }
          if (i > 0) {
            writeFileSeparator(out);
          }
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));

    // Set cache scope
    setHeader("Cache-Control", scope.cacheControl);
   
    // Set maximum age for caching in seconds (rounded)
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

    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

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.