Package org.apache.wicket.page

Examples of org.apache.wicket.page.PageAccessSynchronizer


        timeout = Duration.minutes(1);
        log.warn(
          "PageAccessSynchronizer created outside of application thread, using default timeout: {}",
          timeout);
      }
      return new PageAccessSynchronizer(timeout);
    }
View Full Code Here


        timeout = Duration.minutes(1);
        log.warn(
          "PageAccessSynchronizer created outside of application thread, using default timeout: {}",
          timeout);
      }
      return new PageAccessSynchronizer(timeout);
    }
View Full Code Here

        timeout = Duration.minutes(1);
        log.warn(
          "PageAccessSynchronizer created outside of application thread, using default timeout: {}",
          timeout);
      }
      return new PageAccessSynchronizer(timeout);
    }
View Full Code Here

        timeout = Duration.minutes(1);
        log.warn(
          "PageAccessSynchronizer created outside of application thread, using default timeout: {}",
          timeout);
      }
      return new PageAccessSynchronizer(timeout);
    }
View Full Code Here

    // set up default request mapper
    setRootRequestMapper(new SystemMapper(this));

    pageFactory = newPageFactory();

    pageAccessSynchronizer = new PageAccessSynchronizer(getRequestCycleSettings().getTimeout());

    requestCycleProvider = new DefaultRequestCycleProvider();
    exceptionMapperProvider = new DefaultExceptionMapperProvider();
  }
View Full Code Here

  }

  public void runContentionTest(final int pages, final int workers, final Duration duration)
    throws Exception
  {
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(1));

    final AtomicInteger[] counts = new AtomicInteger[pages];
    for (int i = 0; i < counts.length; i++)
    {
      counts[i] = new AtomicInteger();
    }

    final AtomicInteger hits = new AtomicInteger();

    final String[] error = new String[1];

    class Worker extends Thread
    {
      @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)
          {
            page2 = random.nextInt(counts.length);
            count++;
          }
          if (page2 == page1)
          {
            throw new RuntimeException("orly?");
          }
          try
          {
            sync.lockPage(page1);
            sync.lockPage(page2);
            // have locks, increment the count

            counts[page1].incrementAndGet();
            counts[page2].incrementAndGet();
            hits.incrementAndGet();

            // hold the lock for some time
            try
            {
              Thread.sleep(50);
            }
            catch (InterruptedException e)
            {
              error[0] = "Worker :" + Thread.currentThread().getName() +
                " interrupted";
            }

            // decrement the counts
            counts[page1].decrementAndGet();
            counts[page2].decrementAndGet();

            // release lock
          }
          catch (CouldNotLockPageException e)
          {
            // ignore
          }
          finally
          {
            sync.unlockAllPages();
          }
        }
      }
    }
View Full Code Here

  public MethodRule globalTimeout = new Timeout((int)Duration.seconds(30).getMilliseconds());

  @Test
  public void testReentrant() throws Exception
  {
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(5));
    final Duration hold = Duration.seconds(1);
    sync.lockPage(0);
    sync.lockPage(0);
  }
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()
      {
        sync.lockPage(1);
        t1locks[0] = Time.now();
        hold.sleep();
        sync.unlockAllPages();
      }
    }

    class T2 extends Thread
    {
      @Override
      public void run()
      {
        sync.lockPage(1);
        t2locks[0] = Time.now();
        sync.unlockAllPages();
      }
    }

    T1 t1 = new T1();
    t1.setName("t1");
View Full Code Here

        timeout = Duration.minutes(1);
        log.warn(
          "PageAccessSynchronizer created outside of application thread, using default timeout: {}",
          timeout);
      }
      return new PageAccessSynchronizer(timeout);
    }
View Full Code Here

   * @throws Exception
   */
  @Test
  public void testReentrant() throws Exception
  {
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(Duration.seconds(5));
    final Duration hold = Duration.seconds(1);
    sync.lockPage(0);
    sync.lockPage(0);
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.page.PageAccessSynchronizer

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.