use of redis.clients.jedis.exceptions.JedisException in project cachecloud by sohutv.
the class BinaryJedisPubSub method process.
private void process(Client client) {
do {
List<Object> reply = client.getRawObjectMultiBulkReply();
final Object firstObj = reply.get(0);
if (!(firstObj instanceof byte[])) {
throw new JedisException("Unknown message type: " + firstObj);
}
final byte[] resp = (byte[]) firstObj;
if (Arrays.equals(SUBSCRIBE.raw, resp)) {
subscribedChannels = ((Long) reply.get(2)).intValue();
final byte[] bchannel = (byte[]) reply.get(1);
onSubscribe(bchannel, subscribedChannels);
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
subscribedChannels = ((Long) reply.get(2)).intValue();
final byte[] bchannel = (byte[]) reply.get(1);
onUnsubscribe(bchannel, subscribedChannels);
} else if (Arrays.equals(MESSAGE.raw, resp)) {
final byte[] bchannel = (byte[]) reply.get(1);
final byte[] bmesg = (byte[]) reply.get(2);
onMessage(bchannel, bmesg);
} else if (Arrays.equals(PMESSAGE.raw, resp)) {
final byte[] bpattern = (byte[]) reply.get(1);
final byte[] bchannel = (byte[]) reply.get(2);
final byte[] bmesg = (byte[]) reply.get(3);
onPMessage(bpattern, bchannel, bmesg);
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
subscribedChannels = ((Long) reply.get(2)).intValue();
final byte[] bpattern = (byte[]) reply.get(1);
onPSubscribe(bpattern, subscribedChannels);
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
subscribedChannels = ((Long) reply.get(2)).intValue();
final byte[] bpattern = (byte[]) reply.get(1);
onPUnsubscribe(bpattern, subscribedChannels);
} else {
throw new JedisException("Unknown message type: " + firstObj);
}
} while (isSubscribed());
}
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 deleteTicketImpl.
/**
* Deletes a ticket.
*
* @param ticket
* @return true if successful
*/
@Override
protected boolean deleteTicketImpl(RepositoryModel repository, TicketModel ticket, String deletedBy) {
boolean success = false;
if (ticket == null) {
throw new RuntimeException("must specify a ticket!");
}
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
try {
// atomically remove ticket
Transaction t = jedis.multi();
t.del(key(repository, KeyType.ticket, ticket.number));
t.del(key(repository, KeyType.journal, ticket.number));
t.exec();
success = true;
log.debug("deleted ticket {} from Redis @ {}", "" + ticket.number, getUrl());
} catch (JedisException e) {
log.error("failed to delete ticket from 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 commitChangeImpl.
/**
* Commit a ticket change to the repository.
*
* @param repository
* @param ticketId
* @param change
* @return true, if the change was committed
*/
@Override
protected boolean commitChangeImpl(RepositoryModel repository, long ticketId, Change change) {
Jedis jedis = pool.getResource();
if (jedis == null) {
return false;
}
try {
List<Change> changes = getJournal(jedis, repository, ticketId);
changes.add(change);
// build a new effective ticket from the changes
TicketModel ticket = TicketModel.buildTicket(changes);
String object = TicketSerializer.serialize(ticket);
String journal = TicketSerializer.serialize(change);
// atomically store ticket
Transaction t = jedis.multi();
t.set(key(repository, KeyType.ticket, ticketId), object);
t.rpush(key(repository, KeyType.journal, ticketId), journal);
t.exec();
log.debug("updated ticket {} in Redis @ {}", "" + ticketId, getUrl());
return true;
} catch (JedisException e) {
log.error("failed to update ticket cache in Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return false;
}
use of redis.clients.jedis.exceptions.JedisException in project gitblit by gitblit.
the class RedisTicketService method getTickets.
/**
* Returns all the tickets in the repository. Querying tickets from the
* repository requires deserializing all tickets. This is an expensive
* process and not recommended. Tickets should be indexed by Lucene and
* queries should be executed against that index.
*
* @param repository
* @param filter
* optional filter to only return matching results
* @return a list of tickets
*/
@Override
public List<TicketModel> getTickets(RepositoryModel repository, TicketFilter filter) {
Jedis jedis = pool.getResource();
List<TicketModel> list = new ArrayList<TicketModel>();
if (jedis == null) {
return list;
}
try {
// Deserialize each journal, build the ticket, and optionally filter
Set<String> keys = jedis.keys(key(repository, KeyType.journal, "*"));
for (String key : keys) {
// {repo}:journal:{id}
String id = key.split(":")[2];
long ticketId = Long.parseLong(id);
List<Change> changes = getJournal(jedis, repository, ticketId);
if (ArrayUtils.isEmpty(changes)) {
log.warn("Empty journal for {}:{}", repository, ticketId);
continue;
}
TicketModel ticket = TicketModel.buildTicket(changes);
ticket.project = repository.projectPath;
ticket.repository = repository.name;
ticket.number = ticketId;
// add the ticket, conditionally, to the list
if (filter == null) {
list.add(ticket);
} else {
if (filter.accept(ticket)) {
list.add(ticket);
}
}
}
// sort the tickets by creation
Collections.sort(list);
} catch (JedisException e) {
log.error("failed to retrieve tickets from Redis @ " + getUrl(), e);
pool.returnBrokenResource(jedis);
jedis = null;
} finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
return list;
}
Aggregations