Package org.apache.wicket.page

Examples of org.apache.wicket.page.PageAccessSynchronizer


   * @throws Exception
   */
  @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


   * @throws Exception
   */
  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

      }
    }

    // set up a synchronizer and lock page 5 with locker1
    final Duration timeout = Duration.seconds(30);
    final PageAccessSynchronizer sync = new PageAccessSynchronizer(timeout);
    Locker locker1 = new Locker(sync);

    final long start = System.currentTimeMillis();
    locker1.run();

    // make sure we can serialize the synchronizer

    final PageAccessSynchronizer sync2 = (PageAccessSynchronizer)WicketObjects.cloneObject(sync);
    assertTrue(sync != sync2);

    // make sure the clone does not retain locks by attempting to lock page locked by locker1 in
    // locker2
    Locker locker2 = new Locker(sync2);
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

   * @throws Exception
   */
  @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

   * @throws Exception
   */
  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

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

    pageFactory = newPageFactory();

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

    requestCycleProvider = new DefaultRequestCycleProvider();
  }
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

  }

  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

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.