use of org.fusesource.hawtbuf.Buffer in project camel by apache.
the class LevelDBAggregationRepository method get.
public Exchange get(final CamelContext camelContext, final String key) {
Exchange answer = null;
try {
byte[] lDbKey = keyBuilder(repositoryName, key);
LOG.trace("Getting key index {}", key);
byte[] rc = levelDBFile.getDb().get(lDbKey);
if (rc != null) {
answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
}
} catch (IOException e) {
throw new RuntimeException("Error getting key " + key + " from repository " + repositoryName, e);
}
LOG.debug("Getting key [{}] -> {}", key, answer);
return answer;
}
use of org.fusesource.hawtbuf.Buffer in project camel by apache.
the class LevelDBAggregationRepository method add.
public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) {
LOG.debug("Adding key [{}] -> {}", key, exchange);
try {
byte[] lDbKey = keyBuilder(repositoryName, key);
final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange, allowSerializedHeaders);
byte[] rc = null;
if (isReturnOldExchange()) {
rc = levelDBFile.getDb().get(lDbKey);
}
LOG.trace("Adding key index {} for repository {}", key, repositoryName);
levelDBFile.getDb().put(lDbKey, exchangeBuffer.toByteArray(), levelDBFile.getWriteOptions());
LOG.trace("Added key index {}", key);
if (rc == null) {
return null;
}
// only return old exchange if enabled
if (isReturnOldExchange()) {
return codec.unmarshallExchange(camelContext, new Buffer(rc));
}
} catch (IOException e) {
throw new RuntimeException("Error adding to repository " + repositoryName + " with key " + key, e);
}
return null;
}
use of org.fusesource.hawtbuf.Buffer in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository method recover.
/**
* {@inheritDoc}
* This specific implementation locks the recovered exchange for a period of time specified by the DAO.
* If the exchange is locked by the DAO, then null is returned.
*/
@Override
public Exchange recover(CamelContext camelContext, String exchangeId) {
Exchange retVal = null;
try {
// recover the exchnage from the repository
final AggregationCompleted agg = dao.getAggregationCompleted(exchangeId, true);
// not found or is locked... return null
if (agg == null)
return null;
// deserialize exchange
retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
// set the version number of the exchange
retVal.setProperty(AGGREGATION_COMPLETE_ENTITY_VERSON, agg.getVersion());
} catch (Exception e) {
// wrap exception in a runtime exception
throw new RuntimeException("Error recovering exchange from repository with exchangeId " + exchangeId, e);
}
return retVal;
}
use of org.fusesource.hawtbuf.Buffer in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository method get.
/**
* {@inheritDoc}
*/
@Override
public Exchange get(CamelContext camelContext, String key) {
Exchange retVal = null;
try {
// get the aggregation
final Aggregation agg = dao.getAggregation(key);
if (agg == null)
return null;
// deserialized to an exchange object
retVal = codec.unmarshallExchange(camelContext, new Buffer(agg.getExchangeBlob()));
// set the version of the exchange for later consistency checking
retVal.setProperty(AGGREGATION_ENTITY_VERSON, agg.getVersion());
} catch (Exception e) {
// wrap exception in a runtime exception
throw new RuntimeException("Error retrieving from repository aggregation with key " + key, e);
}
return retVal;
}
use of org.fusesource.hawtbuf.Buffer in project camel by apache.
the class MQTTEndpoint method createConnection.
protected void createConnection() {
connection = configuration.callbackConnection();
connection.listener(new Listener() {
public void onConnected() {
connected = true;
LOG.info("MQTT Connection connected to {}", configuration.getHost());
}
public void onDisconnected() {
// no connected = false required here because the MQTT client should trigger its own reconnect;
// setting connected = false would make the publish() method to launch a new connection while the original
// one is still reconnecting, likely leading to duplicate messages as observed in CAMEL-9092;
// if retries are exhausted and it desists, we should get a callback on onFailure, and then we can set
// connected = false safely
LOG.debug("MQTT Connection disconnected from {}", configuration.getHost());
}
public void onPublish(UTF8Buffer topic, Buffer body, Runnable ack) {
if (!consumers.isEmpty()) {
Exchange exchange = createExchange();
exchange.getIn().setBody(body.toByteArray());
exchange.getIn().setHeader(MQTTConfiguration.MQTT_SUBSCRIBE_TOPIC, topic.toString());
for (MQTTConsumer consumer : consumers) {
consumer.processExchange(exchange);
}
}
if (ack != null) {
ack.run();
}
}
public void onFailure(Throwable value) {
// mark this connection as disconnected so we force re-connect
connected = false;
LOG.warn("Connection to " + configuration.getHost() + " failure due " + value.getMessage() + ". Forcing a disconnect to re-connect on next attempt.");
connection.disconnect(new Callback<Void>() {
public void onSuccess(Void value) {
}
public void onFailure(Throwable e) {
LOG.debug("Failed to disconnect from " + configuration.getHost() + ". This exception is ignored.", e);
}
});
}
});
}
Aggregations