Package org.apache.wicket.util.time

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


    {
      @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


  @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

    return timestampParameter;
  }

  public void decorateUrl(ResourceUrl url, final ResourceReference reference)
  {
    Time lastModified = getLastModified(reference);

    if (lastModified != null)
    {
      url.getParameters().set(timestampParameter, lastModified.getMilliseconds());
    }
  }
View Full Code Here

    {
      return cache.get(resourceReference);
    }

    // no cache entry, so retrieve timestamp from resource reference
    Time lastModified = resourceReference.getLastModified();

    // and put it in cache
    cache.put(resourceReference, lastModified);

    return lastModified;
View Full Code Here

    return timestampPrefix;
  }

  public void decorateUrl(ResourceUrl url, ResourceReference reference)
  {
    Time lastModified = getLastModified(reference);

    final String filename = url.getFileName();

    if (lastModified == null)
      return;

    // check if resource name has extension
    int extensionAt = filename.lastIndexOf('.');

    // create timestamped version of filename:
    //
    // filename :=
    // [basename][timestamp-prefix][last-modified-milliseconds](.extension)
    //
    StringBuilder timestampedFilename = new StringBuilder();
    timestampedFilename.append(extensionAt == -1 ? filename
      : filename.substring(0, extensionAt));
    timestampedFilename.append(timestampPrefix);
    timestampedFilename.append(lastModified.getMilliseconds());

    if (extensionAt != -1)
      timestampedFilename.append(filename.substring(extensionAt));

    url.setFileName(timestampedFilename.toString());
View Full Code Here

      // set Content-Type (may be null)
      resourceResponse.setContentType(resourceStream.getContentType());

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

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

      try
      {
        // read resource data
        final byte[] bytes;
View Full Code Here

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

    boolean locked = false;

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

      PageLock previous = locks.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 (semaphore)
          {
            if (logger.isDebugEnabled())
            {
              logger.debug("{} waiting for lock to page {} for {}", new Object[] {
                  thread.getName(), pageId, Duration.milliseconds(remaining) });
            }
            try
            {
              semaphore.wait(remaining);
            }
            catch (InterruptedException e)
            {
              // TODO better exception
              throw new RuntimeException(e);
            }
          }
        }
      }
    }
    if (locked)
    {
      logger.debug("{} acquired lock to page {}", thread.getName(), pageId);
    }
    else
    {
      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

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

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

              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.toString());
              }

              // Sleep until the period is over (or not at all if it's
              // already passed)
              startOfPeriod.add(frequency).fromNow().sleep();
            }
          }
          catch (Throwable t)
          {
            log.error("Task " + name + " terminated", t);
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.