Package org.ardverk.dht.storage.message

Examples of org.ardverk.dht.storage.message.Context


   
    Set<KUID> dst = new TreeSet<KUID>();
    Key key = KeyFactory.parseKey("ardverk:///hello/world");
    for (int i = 0; i < count; i++) {
      KUID valueId = KUID.createRandom(key.getId());
      Context context = new Context();
      context.addHeader("X-Index", Integer.toString(i));
     
      index.add(key, context, valueId);
      dst.add(valueId);
    }
   
View Full Code Here


 
  @Override
  protected Response handlePut(Contact src, Key key, Request request,
      InputStream in) throws IOException {
   
    Context context = request.getContext();
   
    MessageDigest md5 = MessageDigestUtils.createMD5();
    MessageDigest sha1 = MessageDigestUtils.createSHA1();
   
    DigestInputStream dis = new DigestInputStream(
        in, MessageDigestUtils.wrap(md5, sha1));
   
    // Create a random ID
    KUID valueId = KUID.createRandom(key.getId());
   
    File contentFile = null;
   
    boolean success = false;
    try {
     
      contentFile = mkContentFile(key, valueId, true);
      writeContent(context, contentFile, dis);
     
      if (!digest(context, Constants.CONTENT_MD5, md5)) {
        return ResponseFactory.INTERNAL_SERVER_ERROR;
      }
     
      if (!digest(context, Constants.CONTENT_SHA1, sha1)) {
        return ResponseFactory.INTERNAL_SERVER_ERROR;
      }
     
      context.addHeader(Constants.VALUE_ID,
          valueId.toHexString());
     
      upsertVclock(key, context);
     
      try {
View Full Code Here

    KUID valueId = getValueId(query);
    return head(src, key, valueId);
  }

  private Response head(Contact src, Key key, KUID valueId) throws IOException {
    Context context = null;
    try {
      context = index.get(key, valueId);
    } catch (Exception err) {
      throw newIoException("Exception", err);
    }
View Full Code Here

  }
 
  private Response value(Contact src, Key key, Map<String, String> query) throws IOException {
    KUID valueId = getValueId(query);
   
    Context context = null;
    try {
      context = index.get(key, valueId);
    } catch (Exception err) {
      throw newIoException("Exception", err);
    }
View Full Code Here

    public Context getOrCreate(byte[] valueId, int maxCount) {
      return getOrCreateContext(KUID.create(valueId), maxCount);
    }
   
    private Context getOrCreateContext(KUID valueId, int maxCount) {
      Context context = get(valueId);
      if (context == null) {
        assert (size() < maxCount);
       
        context = new Context();
        put(valueId, context);
      }
      return context;
    }
View Full Code Here

            int count = getValueCount(keyId);
            values = new Values(marker, count);
           
            do {
              byte[] valueId = rs.getBytes(1);
              Context context = values.getOrCreate(valueId, maxCount);
             
              if (context == null) {
                break;
              }
             
              String name = rs.getString(2);
              String value = rs.getString(3);
             
              context.addHeader(name, value);
             
            } while (rs.next());
          }
         
        } finally {
View Full Code Here

TOP

Related Classes of org.ardverk.dht.storage.message.Context

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.