Package nexj.core.util

Examples of nexj.core.util.Binary


    *
    * @param semaphoreDef The (resource . maxCount) pair defining the semaphore.
    */
   protected void release(Pair semaphoreDef)
   {
      final Binary resource = (Binary)semaphoreDef.getHead();

      release(resource); // release the resource immediately

      Function compensator = new Function()
      {
View Full Code Here


    *
    * @param OID oid the oid of the message that has been delivered.
    */
   public void complete(OID oid)
   {
      Binary binOID = oid.toBinary();
      String sTransactionNode = (String)m_nodeByProcessingMessageIdMap.get(binOID);

      if (sTransactionNode != null)
      {
         Set transactionSet = (Set)m_processingMessagesByNodeNameMap.get(sTransactionNode);
View Full Code Here

               s_logger.debug("GetMessage delivering non-persisted message to node " + sNode);
            }
         }
         else
         {
            Binary binOID = (Binary)m_message.getArgArray()[0];

            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("GetMessage delivering oid " + binOID + " to node " + sNode);
            }
View Full Code Here

            istream = helper.getResourceAsStream("files/" + sName);
            dataStream = new ByteArrayOutputStream();

            IOUtil.copy(dataStream, istream);

            return new Binary(dataStream.toByteArray());
         }

         throw new MetadataValidationException("err.meta.invalidFilePath", new Object[] { sName });
      }
      catch (Exception e)
View Full Code Here

      catch (IOException e)
      {
         throw new UncheckedException("err.rpc.valueSerialization", e);
      }

      return new Binary(bos.toByteArray());
   }
View Full Code Here

         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation (\u4e2d\u6587) data.".getBytes("utf-8")));
        
         // Replicate
         context.getUnitOfWork().addReplicationFragment(a, "fragment1");
        
         commit(context);
  
         OID oidA = a.getOID();
         String sOidName = (String)oidA.getValue(0);
        
         // Verify
         File defaultFile = FileManagedConnection.splitNameToSubdirs(dataDir, sOidName, 3, 2, false);
        
         assertTrue(defaultFile.exists());
         assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(defaultFile));
        
         File fragment1File = FileManagedConnection.splitNameToSubdirs(dataDir1, sOidName, 3, 2, false);
        
         assertTrue(fragment1File.exists());
         assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(fragment1File));
        
         // Update it
         assertNull(context.beginTransaction());
        
         a.setValue("data", new Binary("Modified data.\nModified.".getBytes("utf-8")));
        
         // Replication
         context.getUnitOfWork().addReplicationFragment(a, "fragment1");
        
         commit(context);
View Full Code Here

         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data.".getBytes("utf-8")));
        
         commit(context);
       
         OID oidA = a.getOID();
         String sOidName = (String)oidA.getValue(0);
        
         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidName + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data.".getBytes("utf-8")), a.getValue("data"));
  
         // Update
         a.setValue("data", new Binary("Update data.".getBytes("utf-8")));
        
         commit(context);
        
         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidName + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Update data.".getBytes("utf-8")), a.getValue("data"));
        
         // Delete
         a.invoke("delete");
        
         commit(context);
        
         // Read (NOT FOUND)
         assertNull(context.beginTransaction());
           
         Query query = Query.createRead(testFPA, null, parse("(= (@ id) \"" + sOidName + "\")"), null, 10, 0, false, Query.SEC_NONE, context);
         InstanceList resultList = query.read();
           
         assertEquals(0, resultList.getCount());
        
         commit(context);

         // Create it (test that the read operation doesn't add the not-found instance to the invocation context)
         assertNull(context.beginTransaction());

         a = (Instance)testFPA.invoke("new");
         a.setOID(oidA);
         a.setValue("data", new Binary("Creation data #2.".getBytes("utf-8")));

         commit(context);
      }
      finally
      {
View Full Code Here

         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data for 'a'.".getBytes("utf-8")));
        
         Instance b = (Instance)testFPA.invoke("new");
        
         b.setValue("data", new Binary("Creation data for 'b'.".getBytes("utf-8")));
        
         commit(context);
       
         OID oidA = a.getOID();
         String sOidNameA = (String)oidA.getValue(0);
         OID oidB = b.getOID();
         String sOidNameB = (String)oidB.getValue(0);

         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidNameA + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data for 'a'.".getBytes("utf-8")), a.getValue("data"));
  
         b.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidNameB + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data for 'b'.".getBytes("utf-8")), b.getValue("data"));

         commit(context);
      }
      finally
      {
View Full Code Here

        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         result.setValue("data", new Binary("Modified through adapter.".getBytes("utf-8")));
        
         //Edit the data file outside the adapter
         writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);
         writer.write("Modified directly.");
         writer.close();
         dataFile.setLastModified(lOriginalModified + 1);
        
         //Try to commit
         try
         {
            commit(context);
            fail("Expected OptimisticLockException");
         }
         catch (OptimisticLockException ex)
         {
            assertEquals("TestFPA", ex.getClassName());
         }
        
         context.getUnitOfWork().rollback(true);
        
         assertNull(context.beginTransaction());
        
         //Re-read
         result.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"u\")"), null, null, null, null
         });
         assertEquals(new Binary("Modified directly.".getBytes("utf-8")), result.getValue("data"));
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
View Full Code Here

        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         //DELETE it
         result.invoke("delete");
        
         //Edit the data file outside the adapter
         writer = IOUtil.openBufferedWriter(dataFile, XMLUtil.ENCODING);
         writer.write("Modified directly.");
         writer.close();
         dataFile.setLastModified(lOriginalModified + 1);
        
         //Try to commit
         try
         {
            commit(context);
            fail("Expected OptimisticLockException");
         }
         catch (OptimisticLockException ex)
         {
            assertEquals("TestFPA", ex.getClassName());
         }
        
         context.getUnitOfWork().rollback(true);
        
         assertNull(context.beginTransaction());
        
         //Re-read
         result.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"d\")"), null, null, null, null
         });

         assertEquals(new Binary("Modified directly.".getBytes("utf-8")), result.getValue("data"));
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
View Full Code Here

TOP

Related Classes of nexj.core.util.Binary

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.