Package com.shop.util.chunked

Examples of com.shop.util.chunked.ChunkedByteArray


  {
    key = filterKey(key);

    try
    {
      ChunkedByteArray  bytes = null;
     
      String         commandName = SCSetOfCommands.getCommandName(ignoreTTL ? SCCommandGetObjectIgnoreTTL.class : SCCommandGetObject.class);
      fClient.send(commandName);
      fClient.send(key);
      fClient.flush();

      int      size = safeParseInt(fClient.readLine());
      if ( size > 0 )
      {
        bytes = fClient.readBytes(size);
      }

      if ( (bytes == null) || (bytes.size() == 0) )
      {
        return null;
      }

      return bytes;
View Full Code Here


      if ( (activePendingPut != null) && activePendingPut.key.equals(key) )
      {
        return activePendingPut.spec;
      }

      ChunkedByteArray    data = null;

      CCDB2IndexEntry     entry = fIndex.get(key);
      if ( entry != null )
      {
        synchronized(entry)
        {
          if ( entry.address == CCDB2IndexEntry.NOT_EXISTS_ADDRESS )
          {
            if ( wasDeleted != null )
            {
              wasDeleted.set(true);
            }
          }
          else
          {
            data = (entry.bytesRef != null) ? entry.bytesRef.get() : null;
            if ( data == null )
            {
              if ( entry.address >= CCDB2IndexEntry.MINIMUM_ACTIVE_ADDRESS )
              {
                data = readObject(entry.address);
                if ( data == null )
                {
                  if ( wasDeleted != null )
                  {
                    wasDeleted.set(true);
                  }
                  entry.address = CCDB2IndexEntry.NOT_EXISTS_ADDRESS;
                }
                else
                {
                  data.lock();
                  entry.bytesRef = new SoftReference<ChunkedByteArray>(data);

                  fFromDiskGetQty.incrementAndGet();
                }
              }
View Full Code Here

    fIndexSize.addAndGet(size);
  }

  private void processPut(CCDB2IndexEntry entry, String key, CCDB2DataSpec spec, long[] groupSpecs, boolean addToIndexFile) throws IOException
  {
    ChunkedByteArray     previous = (entry.bytesRef != null) ? entry.bytesRef.get() : null;
    PendingPutRecord    pendingPut = new PendingPutRecord(key, previous, entry, spec, groupSpecs, addToIndexFile);

    // though this is a SoftReference, a hard reference is held by spec.data in the pending record until it's actually written
    entry.bytesRef = new SoftReference<ChunkedByteArray>(spec.data);
    if ( fPendingPutQueue != null )
View Full Code Here

  {
    final RandomAccessFile   file = io.getUnderlyingFile();

    if ( driver.doChunking() && (fObjectSize >= ChunkedByteArray.DEFAULT_CHUNK_SIZE) )
    {
      fObject = new ChunkedByteArray();
      fObject.append
      (
        new InputStream()
        {
          @Override
View Full Code Here

   */
  private void  processPut(PutWrapper wrapper)
  {
    try
    {
      ChunkedByteArray     data = fSerializer.serialize(wrapper.block);
      SCDataSpec spec = new SCDataSpec(data, wrapper.block.getTTL());
      if ( wrapper.withBackup )
      {
        fManager.putWithBackup(wrapper.block.getKey(), spec, wrapper.block.getGroups());
      }
View Full Code Here

  private Object requestObject(SCDataBlock block, long rightNow)
  {
    Object     resultObject = null;
    try
    {
      ChunkedByteArray   data = fManager.get(block.getKey(), block.getIgnoreTTL());
      SCDataBlock     fromManagerBlock = (data != null) ? fSerializer.deserialize(data) : null;
      if ( fromManagerBlock != null )
      {
        boolean     isUseable = checkIsUsable(block, fromManagerBlock, rightNow);
        if ( isUseable )
View Full Code Here

  }

  @Override
  public ChunkedByteArray serialize(SCDataBlock block) throws Exception
  {
    ChunkedByteArray        chunked = new ChunkedByteArray();
    ObjectOutputStream         out = new ObjectOutputStream(new GZIPOutputStream(new ChunkedByteArrayOutputStream(chunked)));

    out.writeInt(FILE_VERSION);
    out.writeInt(block.getVersionNumber());
    out.writeLong(block.getTTL());
    out.writeUTF(block.getKey());

    out.writeObject(block.getObject());

    out.close();

    chunked.lock();
    return chunked;
  }
View Full Code Here

          case OBJECT:
          {
            int    size = sizeFromLine(fClient.readLine());
            if ( size > 0 )
            {
              ChunkedByteArray    bytes = fClient.readBytes(size);
              builder.addNextObject(bytes);
            }
            break;
          }
View Full Code Here

      }

      @Override
      public void executeCommand(SCServer server, SCConnection connection) throws Exception
      {
        ChunkedByteArray     data = server.get(fKey, fIgnoreTTL);
        connection.sendObject((data != null) ? data : null);
      }

      private String      fKey = "";
    };
View Full Code Here

  @Override
  public ChunkedByteArray readBytes(int size) throws IOException
  {
    boolean          eof = false;
    ChunkedByteArray    bytes = (size < ChunkedByteArray.DEFAULT_CHUNK_SIZE) ? new ChunkedByteArray(size) : new ChunkedByteArray();
    while ( size-- > 0 )
    {
      int    i = fIn.read();
      if ( i < 0 )
      {
        eof = true;
        break;
      }
      bytes.append((byte)(i & 0xff));
      updateLastReadTicks();
    }

    if ( eof )
    {
      if ( bytes.size() == 0 )
      {
        return null;
      }
      throw new EOFException();
    }
View Full Code Here

TOP

Related Classes of com.shop.util.chunked.ChunkedByteArray

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.