// 4.
log.debug("refreshing resource {}",resource);
this.lock.readLock().lock();
try {
ClientResponse response = ldclient.retrieveResource(resource.stringValue());
if(response != null) {
log.info("refreshed resource {}",resource);
// obtain a new cache connection, since we closed the original connection above
LDCachingConnection cacheConnection1 = backend.getCacheConnection(resource.stringValue());
cacheConnection1.begin();
try {
URI subject = cacheConnection1.getValueFactory().createURI(resource.stringValue());
RepositoryConnection respConnection = response.getTriples().getConnection();
cacheConnection1.remove(subject, null, null);
RepositoryResult<Statement> triples = respConnection.getStatements(null,null,null,true);
while(triples.hasNext()) {
Statement triple = triples.next();
try {
cacheConnection1.add(triple);
} catch (RuntimeException ex) {
log.warn("not adding triple {}: an exception occurred ({})",triple,ex.getMessage());
}
}
triples.close();
respConnection.close();
CacheEntry newEntry = new CacheEntry();
newEntry.setResource(subject);
newEntry.setExpiryDate(response.getExpires());
newEntry.setLastRetrieved(new Date());
if(entry != null) {
newEntry.setUpdateCount(entry.getUpdateCount()+1);
} else {
newEntry.setUpdateCount(1);