Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Preamble
PROGNAME=$(basename $0)
function error_exit
{
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit ${2:-1}
#!/bin/bash
# Preamble
PROGNAME=$(basename $0)
function error_exit
{
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
exit ${2:-1}
@andresrc
andresrc / gist:3381978
Created August 17, 2012 19:48
Bocas Cache example
/* On-heap. */
CachingBocas cache = BocasServices.cache().maximumSize(1000).expireAfterAccess(30L, TimeUnit.SECONDS).build(bocas);
/** Off-heap. */
CachingBocas directCache = BocasServices.cache().maximumWeight(536870912L).buildDirect(bocas);
@andresrc
andresrc / BocasBDB.java
Created August 17, 2012 18:28
Instantiate Bocas BDB repository
/** Provide the path to the database environment. */
Bocas bocas = JEBocas.basic("/path/to/env");
@andresrc
andresrc / gist:3381164
Created August 17, 2012 18:03
Instantiate Bocas memory repositories
/* On-heap repository. */
Bocas heap = BocasServices.memory();
/* Off-heap repository. */
Bocas direct = BocasServices.direct();
@andresrc
andresrc / gist:3380724
Created August 17, 2012 17:14
Bocas entries
public class BocasEntry {
/** Returns the entry key. */
public ByteString getKey();
/** Returns the entry value. */
public BocasValue getValue();
/**
* Turns this entry into a loaded entry.
* @throws BocasException if unable to read the value payload.
@andresrc
andresrc / BocasValue.java
Created August 17, 2012 11:33
Bocas Value (conversions)
public class BocasValue implements InputSupplier<InputStream> {
/**
* Turns this value into a loaded one.
* @throws BocasException if unable to load the payload.
*/
public LoadedBocasValue load();
/**
* Turns this value into a direct one.
* @throws BocasException if unable to load the payload.
@andresrc
andresrc / BocasValue.java
Created August 17, 2012 11:12
Bocas Value (basic operations)
public class BocasValue implements InputSupplier<InputStream> {
/** Returns the payload size in bytes (if known). */
public Integer getSize();
/** Copies and returns the internal data. */
public byte[] toByteArray() throws IOException;
}
@andresrc
andresrc / Bocas.java
Created August 16, 2012 18:18
Bocas Interface
public interface Bocas {
/*
* Checking if the repository contains entries.
*/
boolean contains(ByteString key);
Set<ByteString> contained(Iterable<ByteString> keys);
/*
@andresrc
andresrc / Group.java
Created May 21, 2011 18:15
Group Object
public class Group {
public int getHits();
public Set<String> getGroupNames();
public Group getGroup(String name);
}