use of org.fusesource.hawtdb.api.SortedIndex in project camel by apache.
the class HawtDBAggregationRepository method confirm.
public void confirm(final CamelContext camelContext, final String exchangeId) {
LOG.debug("Confirming exchangeId [{}]", exchangeId);
try {
final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
hawtDBFile.execute(new Work<Buffer>() {
public Buffer execute(Transaction tx) {
SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
Buffer buffer = indexCompleted.remove(confirmKeyBuffer);
LOG.trace("Removed confirm index {} -> {}", confirmKeyBuffer, buffer);
return buffer;
}
@Override
public String toString() {
return "Confirming exchangeId [" + exchangeId + "]";
}
});
} catch (IOException e) {
throw new RuntimeException("Error confirming exchangeId " + exchangeId + " from repository " + repositoryName, e);
}
}
use of org.fusesource.hawtdb.api.SortedIndex in project camel by apache.
the class HawtDBAggregationRepository method recover.
public Exchange recover(CamelContext camelContext, final String exchangeId) {
Exchange answer = null;
try {
final Buffer confirmKeyBuffer = codec.marshallKey(exchangeId);
Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
public Buffer execute(Transaction tx) {
SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), false);
if (indexCompleted == null) {
return null;
}
return indexCompleted.get(confirmKeyBuffer);
}
@Override
public String toString() {
return "Recovering exchangeId [" + exchangeId + "]";
}
});
if (rc != null) {
answer = codec.unmarshallExchange(camelContext, rc);
}
} catch (IOException e) {
throw new RuntimeException("Error recovering exchangeId " + exchangeId + " from repository " + repositoryName, e);
}
LOG.debug("Recovering exchangeId [{}] -> {}", exchangeId, answer);
return answer;
}
use of org.fusesource.hawtdb.api.SortedIndex in project camel by apache.
the class HawtDBAggregationRepository method doAdd.
protected Exchange doAdd(final CamelContext camelContext, final String key, final Exchange exchange, final boolean handleOptimisticLockingException) {
LOG.debug("Adding key [{}] -> {}", key, exchange);
try {
// If we could guarantee that the key and exchange are immutable,
// then we could have stuck them directly into the index,
// HawtDB could then eliminate the need to marshal and un-marshal
// in some cases. But since we can't.. we are going to force
// early marshaling.
final Buffer keyBuffer = codec.marshallKey(key);
final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders);
Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
public Buffer execute(Transaction tx) {
SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName, true);
Buffer buffer = index.put(keyBuffer, exchangeBuffer);
LOG.trace("Added key index {}", keyBuffer);
return buffer;
}
@Override
public String toString() {
return "Adding key [" + key + "]";
}
}, handleOptimisticLockingException);
if (rc == null) {
return null;
}
// only return old exchange if enabled
if (isReturnOldExchange()) {
return codec.unmarshallExchange(camelContext, rc);
}
} catch (IOException e) {
throw new RuntimeException("Error adding to repository " + repositoryName + " with key " + key, e);
}
return null;
}
use of org.fusesource.hawtdb.api.SortedIndex in project camel by apache.
the class HawtDBAggregationRepository method remove.
public void remove(final CamelContext camelContext, final String key, final Exchange exchange) {
LOG.debug("Removing key [{}]", key);
try {
final Buffer keyBuffer = codec.marshallKey(key);
final Buffer confirmKeyBuffer = codec.marshallKey(exchange.getExchangeId());
final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders);
hawtDBFile.execute(new Work<Buffer>() {
public Buffer execute(Transaction tx) {
SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName, true);
// remove from the in progress index
Buffer buffer = index.remove(keyBuffer);
LOG.trace("Removed key index {} -> {}", keyBuffer, buffer);
// and add it to the confirmed index
SortedIndex<Buffer, Buffer> indexCompleted = hawtDBFile.getRepositoryIndex(tx, getRepositoryNameCompleted(), true);
indexCompleted.put(confirmKeyBuffer, exchangeBuffer);
LOG.trace("Added confirm index {}", confirmKeyBuffer);
return null;
}
@Override
public String toString() {
return "Removing key [" + key + "]";
}
});
} catch (IOException e) {
throw new RuntimeException("Error removing key " + key + " from repository " + repositoryName, e);
}
}
use of org.fusesource.hawtdb.api.SortedIndex in project camel by apache.
the class HawtDBAggregationRepository method get.
public Exchange get(final CamelContext camelContext, final String key) {
Exchange answer = null;
try {
final Buffer keyBuffer = codec.marshallKey(key);
Buffer rc = hawtDBFile.execute(new Work<Buffer>() {
public Buffer execute(Transaction tx) {
SortedIndex<Buffer, Buffer> index = hawtDBFile.getRepositoryIndex(tx, repositoryName, false);
if (index == null) {
return null;
}
Buffer buffer = index.get(keyBuffer);
LOG.trace("Getting key index {}", keyBuffer);
return buffer;
}
@Override
public String toString() {
return "Getting key [" + key + "]";
}
});
if (rc != null) {
answer = codec.unmarshallExchange(camelContext, rc);
}
} catch (IOException e) {
throw new RuntimeException("Error getting key " + key + " from repository " + repositoryName, e);
}
LOG.debug("Getting key [{}] -> {}", key, answer);
return answer;
}
Aggregations