Package org.jboss.cache

Examples of org.jboss.cache.Fqn


//      CacheSPI<Object, Object> cache1 = createSyncReplicatedCache();
//      CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();

      TransactionManager tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();

      Fqn fqn = Fqn.fromString("/test/node");
      String KEY = "key";
      String VALUE1 = "value1";

      tm1.begin();
      cache1.put(fqn, KEY, VALUE1);


   public NodeSPI addChildDirect(Fqn childName)
   {
      if (childName.size() == 0) return this;
      Object directChildName = childName.get(0);
      NodeSpiMock directChild = children.get(directChildName);
      Fqn subFqn = childName.getSubFqn(1, childName.size());
      if (directChild == null)
      {
         directChild = newChild(directChildName);
      }
      return directChild.addChildDirect(subFqn);

      @NodePassivated
      public void nodePassivated(NodeEvent e)
      {
         if (!e.isPre())
            return; // we are not interested in postPassivate event
         Fqn fqn = e.getFqn();
         if (!fqn.isChildOrEquals(BASE))
            return; // don't care about fqn that doesn't belong to me.

         try
         {
            Object bean = cache.get(fqn, "bean");

   {
      MockNodesFixture nodes = new MockNodesFixture();
      expect(spiMock.getNode(fqn)).andReturn(null);
      expect(containerMock.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)).andReturn(nodes.abNode);

      Fqn firstSearch = Fqn.fromString(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN + "/c/dummy");
      expect(spiMock.getNode(firstSearch)).andReturn(nodes.abcNode);

      ArrayList listReference = new ArrayList();
      expect(containerMock.buildNodeData(Collections.EMPTY_LIST, nodes.abcNode, false)).andReturn(listReference);

      MockNodesFixture nodes = new MockNodesFixture();
      expect(spiMock.getNode(fqn)).andReturn(null);
      expect(containerMock.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)).andReturn(nodes.adfNode);

      control.checkOrder(false);
      Fqn firstSearch = Fqn.fromString(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN + "/g/dummy");
      expect(spiMock.getNode(firstSearch)).andReturn(null);
      Fqn secondSearch = Fqn.fromString(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN + "/h/dummy");
      expect(spiMock.getNode(secondSearch)).andReturn(null);
      control.checkOrder(true);

      control.replay();
      assert GravitateResult.noDataFound().equals(command.perform(ctx));

      }
   }

   public void testLockReentrancy() throws InterruptedException
   {
      Fqn fqn = Fqn.fromString("/a/b/c");
      NodeSPI node = new NodeInvocationDelegate(new UnversionedNode(fqn));

      assert lm.lock(fqn, WRITE, null);
      assert lm.isLocked(node);

      final CountDownLatch secondCanRead = new CountDownLatch(1);
      final CountDownLatch secondDone = new CountDownLatch(1);
      final CountDownLatch firstCanRollback = new CountDownLatch(1);
      final CountDownLatch firstDone = new CountDownLatch(1);

      final Fqn PARENT = Fqn.fromString("/a");

      // start a first thread and a transaction

      Thread firstThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               TransactionManager tm = startTransaction();

               // Create an empty parent node and a node with data
               Fqn a1 = Fqn.fromRelativeElements(PARENT, "1");
               cache.put(a1, KEY, VALUE);

               // notify the second thread it can write
               secondCanWrite.countDown();

               // wait until the second thread writes and allows me to rollback or until I timeout
               firstCanRollback.await(3000, TimeUnit.MILLISECONDS);

               tm.rollback();

               assertNull("a1 empty", cache.get(a1, KEY));

               // notify the reading thread
               secondCanRead.countDown();
            }
            catch (AssertionError e)
            {
               writerError = e;
            }
            catch (Throwable t)
            {
               t.printStackTrace();
               writerFailed = true;
            }
            finally
            {
               secondCanWrite.countDown();
               secondCanRead.countDown();
               firstDone.countDown();
            }
         }
      }, "FIRST");
      firstThread.start();

      // start a second thread; no transaction is necessary here

      Thread secondThread = new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               // wait until the first thread has created PARENT and a child
               secondCanWrite.await();

               // create a second child under parent
               Fqn a2 = Fqn.fromRelativeElements(PARENT, "2");
               try
               {
                  cache.put(a2, KEY, VALUE);
               }
               catch (TimeoutException good)

      byte magic = ois.readByte();
      short ref = ois.readShort();
      assert magic == CacheMarshaller200.MAGICNUMBER_FQN;

      // now the chunks of an Fqn
      Fqn f = cm200.unmarshallFqn(ois, new UnmarshalledReferences());

      assert f.equals(Fqn.fromString("/hello"));
   }

      cr.start();

      RegionManager rm = cr.getComponent(RegionManager.class);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      final Fqn region = Fqn.fromString("/hello");
      Region r = rm.getRegion(region, true);
      r.registerContextClassLoader(this.getClass().getClassLoader());
      cm200.objectToObjectStream(new ClusteredGetCommand(false, null), oos, region);
      oos.close();

      final byte[] stream = baos.toByteArray();
      // so now the stream starts with the Fqn "/hello".

      // repeat 100 times
      for (int i = 0; i < 100; i++)
      {
         if (i % 3 == 0)
         {
            // task 1 above
            e.execute(new Runnable()
            {
               public void run()
               {
                  try
                  {
                     RegionalizedMethodCall rmc = cm200.regionalizedMethodCallFromObjectStream(new ObjectInputStream(new ByteArrayInputStream(stream)));
                     ByteArrayOutputStream out = new ByteArrayOutputStream();
                     ObjectOutputStream outStream = new ObjectOutputStream(out);
                     RegionalizedReturnValue rrv = new RegionalizedReturnValue("A result", rmc);
                     cm200.objectToObjectStream(rrv, outStream);
                     outStream.close();
                     out.close();
                     // test that the output stream has got "/hello" as it's region Fqn.
                     ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
                     assert in.readByte() == CacheMarshaller200.MAGICNUMBER_FQN : "The stream should start with an Fqn";
                     // discard the nest refId short
                     in.readShort();
                     Fqn f = cm200.unmarshallFqn(in, new UnmarshalledReferences());
                     assert region.equals(f) : "Should use the same region for the response as was used for the request!";

                  }
                  catch (Throwable t)
                  {

   }

   @SuppressWarnings("unchecked")
   public void testRemoveBeforePut() throws Exception
   {
      Fqn f = Fqn.fromString("/test");
      assertNull(c[0].getNode(f));
      assertNull(c[1].getNode(f));

      replListeners[1].expectWithTx(PutKeyValueCommand.class);
      t.begin();

TOP

Related Classes of org.jboss.cache.Fqn

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.