Package org.jboss.cache.util

Examples of org.jboss.cache.util.ExposedByteArrayOutputStream


      int[] sizes = new int[3];
      byte[] retval = null;
      int lastSize;
      MarshalledValueOutputStream out;

      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(1024);
      try {
         initializeStateTransfer(baos);
         lastSize = baos.size();
      }
      catch (Throwable t)
      {
         log.error("failed initialing state transfer byte[]", t);
         if (!suppressErrors)
            throw t;
        
         return null;
      }

      try {
        
         if(generateTransient) {
            out = new MarshalledValueOutputStream(baos);
            marshallTransientState(rootNode, out);
            out.close();
            sizes[0] = baos.size() - lastSize;
            lastSize = baos.size();
            if (debug) {
               log.debug("generated the in-memory state (" + sizes[0] +
                         " bytes)");
            }
            // Return any state associated with the subtree but not stored in it
            if (cache instanceof PojoCache) {
               out = new MarshalledValueOutputStream(baos);
               marshallAssociatedState(fqn, out);
               out.close();
               sizes[1] = baos.size() - lastSize;
               lastSize = baos.size();
               if (debug) {
                  log.debug("returning the associated state (" + sizes[1] +
                            " bytes)");
               }
            }
         }
      }
      catch(Throwable t) {
         log.error("failed getting the in-memory (transient) state", t);
         if (!suppressErrors)
            throw t;
        
         // Reset the byte array and see if we can continue with persistent state
         // TODO reconsider this -- why are errors suppressed at all?
         sizes[0] = sizes[1] = 0;
         baos.reset();
         try {
            initializeStateTransfer(baos);
         }
         catch (Throwable t1) {
            log.error("failed re-initializing state transfer", t1);
            return null;
         }
      }
     
      if (generatePersistent) {
         try {
            if (debug)
               log.debug("getting the persistent state");
            byte[] persState = null;
            if (fqn.size() == 0)
               persState = cache.getCacheLoader().loadEntireState();
            else
               persState = ((ExtendedCacheLoader)cache.getCacheLoader()).loadState(fqn);
           
            if (persState != null) {
               sizes[2] = persState.length;
               baos.write(persState);
            }
           
            if (debug) {
               log.debug("generated the persistent state (" + sizes[2] +
                         " bytes)");
            }
         }
         catch(Throwable t) {
            log.error("failed getting the persistent state", t);
            if (!suppressErrors)
               throw t;
            sizes[2] = 0;
         }
      }
  
      // Overwrite the placeholders used for the sizes of the state transfer
      // components with the correct values
      try {
         byte[] bytes = baos.getRawBuffer();
         overwriteInt(bytes, 8, sizes[0]);
         overwriteInt(bytes, 12, sizes[1]);
         overwriteInt(bytes, 16, sizes[2]);
         retval = bytes;
        
View Full Code Here


      int[] sizes = new int[3];
      byte[] retval = null;
      int lastSize;
      MarshalledValueOutputStream out;

      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(1024);
      try {
         initializeStateTransfer(baos);
         lastSize = baos.size();
      }
      catch (Throwable t)
      {
         log.error("failed initialing state transfer byte[]", t);
         if (!suppressErrors)
            throw t;
        
         return null;
      }

      try {
        
         if(generateTransient) {
            out = new MarshalledValueOutputStream(baos);
            marshallTransientState(rootNode, out);
            out.close();
            sizes[0] = baos.size() - lastSize;
            lastSize = baos.size();
            if (debug) {
               log.debug("generated the in-memory state (" + sizes[0] +
                         " bytes)");
            }
            // Return any state associated with the subtree but not stored in it
            if (cache instanceof PojoCache) {
               out = new MarshalledValueOutputStream(baos);
               marshallAssociatedState(fqn, out);
               out.close();
               sizes[1] = baos.size() - lastSize;
               lastSize = baos.size();
               if (debug) {
                  log.debug("returning the associated state (" + sizes[1] +
                            " bytes)");
               }
            }
         }
      }
      catch(Throwable t) {
         log.error("failed getting the in-memory (transient) state", t);
         if (!suppressErrors)
            throw t;
        
         // Reset the byte array and see if we can continue with persistent state
         // TODO reconsider this -- why are errors suppressed at all?
         sizes[0] = sizes[1] = 0;
         baos.reset();
         try {
            initializeStateTransfer(baos);
         }
         catch (Throwable t1) {
            log.error("failed re-initializing state transfer", t1);
            return null;
         }
      }
     
      if (generatePersistent) {
         try {
            if (debug)
               log.debug("getting the persistent state");
            byte[] persState = null;
            if (fqn.size() == 0)
               persState = cache.getCacheLoader().loadEntireState();
            else
               persState = ((ExtendedCacheLoader)cache.getCacheLoader()).loadState(fqn);
           
            if (persState != null) {
               sizes[2] = persState.length;
               baos.write(persState);
            }
           
            if (debug) {
               log.debug("generated the persistent state (" + sizes[2] +
                         " bytes)");
            }
         }
         catch(Throwable t) {
            log.error("failed getting the persistent state", t);
            if (!suppressErrors)
               throw t;
            sizes[2] = 0;
         }
      }
  
      // Overwrite the placeholders used for the sizes of the state transfer
      // components with the correct values
      try {
         byte[] bytes = baos.getRawBuffer();
         overwriteInt(bytes, 8, sizes[0]);
         overwriteInt(bytes, 12, sizes[1]);
         overwriteInt(bytes, 16, sizes[2]);
         retval = bytes;
        
View Full Code Here

      MarshalledValueOutputStream out = null;
      byte[] result = null;
      try
      {
         ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
         out = new MarshalledValueOutputStream(baos);
         stateTransferManager.getState(out, fqn, timeout, force, suppressErrors);
         result = baos.getRawBuffer();
      }
      finally
      {
         Util.close(out);
      }
View Full Code Here

   public byte[] getState()
   {
      MarshalledValueOutputStream out = null;
      byte[] result = null;
      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
      try
      {
         out = new MarshalledValueOutputStream(baos);

         stateTransferManager.getState(out, Fqn.ROOT, configuration.getStateRetrievalTimeout(), true, true);
      }
      catch (Throwable t)
      {
         stateProducingFailed(t);
      }
      finally
      {
         result = baos.getRawBuffer();
         Util.close(out);
      }
      return result;
   }
View Full Code Here

      if (hasDifferentSourceAndIntegrationRoots)
      {
         sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
      }

      ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
      try
      {
         out = new MarshalledValueOutputStream(baos);

         stateTransferManager.getState(out, Fqn.fromString(sourceRoot),
               configuration.getStateRetrievalTimeout(), true, true);
      }
      catch (Throwable t)
      {
         stateProducingFailed(t);
      }
      finally
      {
         result = baos.getRawBuffer();
         Util.close(out);
      }
      return result;
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.util.ExposedByteArrayOutputStream

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.