@ManagedOperation public void put(K key, V val) { put(key, val, default_replication_count, caching_time); }
/** * Places a key/value pair into one or several nodes in the cluster. * @param key The key, needs to be serializable * @param val The value, needs to be serializable * @param repl_count Number of replicas. The total number of times a data item should be present in a cluster. * Needs to be > 0 * <ul> * <li>-1: create key/val in all the nodes in the cluster * <li>1: create key/val only in one node in the cluster, picked by computing the consistent hash of KEY * <li>K > 1: create key/val in those nodes in the cluster which match the consistent hashes created for KEY * </ul> * @param timeout Expiration time for key/value. * <ul> * <li>-1: don't cache at all in the L1 cache * <li>0: cache forever, until removed or evicted because we need space for newer elements * <li>> 0: number of milliseconds to keep an idle element in the cache. An element is idle when not accessed. * </ul> */ @ManagedOperation public void put(K key, V val, short repl_count, long timeout) { put(key, val, repl_count, timeout, false); // don't block (asynchronous put) by default }
private void startPerfTest() { int num_puts=1000; short repl_count=1; long timeout=0; String key_prefix="key"; String tmp=perf_key_prefix.getText(); if(tmp != null) key_prefix=tmp; tmp=perf_num_keys.getText(); if(tmp != null) num_puts=Integer.valueOf(tmp); tmp=perf_size.getText(); Integer size; if(tmp != null) size=Integer.valueOf(tmp); tmp=perf_repl_count_field.getText(); if(tmp != null) repl_count=Short.valueOf(tmp); tmp=perf_timeout_field.getText(); if(tmp != null) timeout=Long.valueOf(tmp); long start=System.currentTimeMillis(); for(int i=0; i < num_puts; i++) { String key=key_prefix + "-" + i; String value="val-" + i; cache.put(key, value, repl_count, timeout); } long diff=System.currentTimeMillis() - start; status.setText("It took " + diff + " ms to insert " + num_puts + " elements"); }
public boolean mkdir() { try { boolean parents_exist=checkParentDirs(getPath(), false); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { e.printStackTrace(); return false; } }
void setLength(int new_length) { Metadata metadata=cache.get(getPath()); if(metadata != null) { metadata.length=new_length; metadata.setModificationTime(System.currentTimeMillis()); cache.put(getPath(), metadata, (short)-1, 0, false); } else System.err.println("metadata for " + getPath() + " not found !"); }
public boolean mkdirs() { try { boolean parents_exist=checkParentDirs(getPath(), true); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { return false; } }
public void flush() throws IOException { int chunk_number=getChunkNumber(); String key=name + ".#" + chunk_number; byte[] val=new byte[local_index]; System.arraycopy(current_buffer, 0, val, 0, local_index); cache.put(key, val, repl_count, 0); if(log.isTraceEnabled()) log.trace("put(): index=" + index + ", key=" + key + ": " + val.length + " bytes"); file.setLength(index); }
cache.put(comp, new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0); else return false;
timeout="0"; cache.put(key, value, Short.valueOf(repl_count), Long.valueOf(timeout)); break; case "Remove":
public boolean createNewFile() throws IOException { if(exists()) return true; if(!checkParentDirs(getPath(), false)) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.FILE), (short)-1, 0, true); return true; }
@ManagedOperation public void put(K key, V val) { put(key, val, default_replication_count, caching_time); }
/** * Places a key/value pair into one or several nodes in the cluster. * @param key The key, needs to be serializable * @param val The value, needs to be serializable * @param repl_count Number of replicas. The total number of times a data item should be present in a cluster. * Needs to be > 0 * <ul> * <li>-1: create key/val in all the nodes in the cluster * <li>1: create key/val only in one node in the cluster, picked by computing the consistent hash of KEY * <li>K > 1: create key/val in those nodes in the cluster which match the consistent hashes created for KEY * </ul> * @param timeout Expiration time for key/value. * <ul> * <li>-1: don't cache at all in the L1 cache * <li>0: cache forever, until removed or evicted because we need space for newer elements * <li>> 0: number of milliseconds to keep an idle element in the cache. An element is idle when not accessed. * </ul> */ @ManagedOperation public void put(K key, V val, short repl_count, long timeout) { put(key, val, repl_count, timeout, false); // don't block (asynchronous put) by default }
private void startPerfTest() { int num_puts=1000; short repl_count=1; long timeout=0; String key_prefix="key"; String tmp=perf_key_prefix.getText(); if(tmp != null) key_prefix=tmp; tmp=perf_num_keys.getText(); if(tmp != null) num_puts=Integer.valueOf(tmp); tmp=perf_size.getText(); Integer size; if(tmp != null) size=Integer.valueOf(tmp); tmp=perf_repl_count_field.getText(); if(tmp != null) repl_count=Short.valueOf(tmp); tmp=perf_timeout_field.getText(); if(tmp != null) timeout=Long.valueOf(tmp); long start=System.currentTimeMillis(); for(int i=0; i < num_puts; i++) { String key=key_prefix + "-" + i; String value="val-" + i; cache.put(key, value, repl_count, timeout); } long diff=System.currentTimeMillis() - start; status.setText("It took " + diff + " ms to insert " + num_puts + " elements"); }
public boolean mkdir() { try { boolean parents_exist=checkParentDirs(getPath(), false); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { e.printStackTrace(); return false; } }
void setLength(int new_length) { Metadata metadata=cache.get(getPath()); if(metadata != null) { metadata.length=new_length; metadata.setModificationTime(System.currentTimeMillis()); cache.put(getPath(), metadata, (short)-1, 0, false); } else System.err.println("metadata for " + getPath() + " not found !"); }
cache.put(comp, new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0); else return false;
public boolean mkdirs() { try { boolean parents_exist=checkParentDirs(getPath(), true); if(!parents_exist) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.DIR), (short)-1, 0, true); return true; } catch(IOException e) { return false; } }
public void flush() throws IOException { int chunk_number=getChunkNumber(); String key=name + ".#" + chunk_number; byte[] val=new byte[local_index]; System.arraycopy(current_buffer, 0, val, 0, local_index); cache.put(key, val, repl_count, 0); if(log.isTraceEnabled()) log.trace("put(): index=" + index + ", key=" + key + ": " + val.length + " bytes"); file.setLength(index); }
timeout="0"; cache.put(key, value, Short.valueOf(repl_count), Long.valueOf(timeout)); break; case "Remove":
public boolean createNewFile() throws IOException { if(exists()) return true; if(!checkParentDirs(getPath(), false)) return false; cache.put(getPath(), new Metadata(0, System.currentTimeMillis(), chunk_size, Metadata.FILE), (short)-1, 0, true); return true; }