use of redis.clients.jedis.exceptions.JedisException in project cachecloud by sohutv.
the class JedisPool method returnResource.
@Override
protected void returnResource(final Jedis resource) {
if (resource != null) {
try {
resource.resetState();
returnResourceObject(resource);
} catch (Exception e) {
returnBrokenResource(resource);
throw new JedisException("Could not return the resource to the pool", e);
}
}
}
use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.
the class RedisTicketService method getTicketImpl.
/**
* Retrieves the ticket from the repository.
*
* @param repository
* @param ticketId
* @return a ticket, if it exists, otherwise null
*/
@Override
protected TicketModel getTicketImpl(RepositoryModel repository, long ticketId) {
Jedis jedis = pool.getResource();
if (jedis == null) {
return null;
}
try {
List<Change> changes = getJournal(jedis, repository, ticketId);
if (ArrayUtils.isEmpty(changes)) {
log.warn("Empty journal for {}:{}", repository, ticketId);
return null;
}
TicketModel ticket = TicketModel.buildTicket(changes);
ticket.project = repository.projectPath;
ticket.repository = repository.name;
ticket.number = ticketId;
log.debug("rebuilt ticket {} from Redis @ {}", ticketId, getUrl());
return ticket;
} catch (JedisException e) {
log.error("failed to retrieve ticket from Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return null;
}
use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.
the class RedisTicketService method renameImpl.
@Override
protected boolean renameImpl(RepositoryModel oldRepository, RepositoryModel newRepository) {
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
boolean success = false;
try {
Set<String> oldKeys = jedis.keys(oldRepository.name + ":*");
Transaction t = jedis.multi();
for (String oldKey : oldKeys) {
String newKey = newRepository.name + oldKey.substring(oldKey.indexOf(':'));
t.rename(oldKey, newKey);
}
t.exec();
success = true;
} catch (JedisException e) {
log.error("failed to rename tickets in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return success;
}
use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.
the class RedisTicketService method assignNewId.
/**
* Assigns a new ticket id.
*
* @param repository
* @return a new long ticket id
*/
@Override
public synchronized long assignNewId(RepositoryModel repository) {
Jedis jedis = pool.getResource();
try {
String key = key(repository, KeyType.counter, null);
String val = jedis.get(key);
if (isNull(val)) {
long lastId = 0;
Set<Long> ids = getIds(repository);
for (long id : ids) {
if (id > lastId) {
lastId = id;
}
}
jedis.set(key, "" + lastId);
}
long ticketNumber = jedis.incr(key);
return ticketNumber;
} catch (JedisException e) {
log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return 0L;
}
use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.
the class RedisTicketService method getIds.
@Override
public Set<Long> getIds(RepositoryModel repository) {
Set<Long> ids = new TreeSet<Long>();
Jedis jedis = pool.getResource();
try {
// account for migrated tickets
Set<String> keys = jedis.keys(key(repository, KeyType.journal, "*"));
for (String tkey : keys) {
// {repo}:journal:{id}
String id = tkey.split(":")[2];
long ticketId = Long.parseLong(id);
ids.add(ticketId);
}
} catch (JedisException e) {
log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return ids;
}
Aggregations