use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class DefaultContentIndexManager method getIndexedStoreKey.
@Override
@Measure
public StoreKey getIndexedStoreKey(final StoreKey key, final String rawPath) {
if (!config.isEnabled()) {
logger.debug("Content indexing is disabled.");
return null;
}
String path = getStrategyPath(key, rawPath);
IndexedStorePath ispKey = new IndexedStorePath(key, path);
IndexedStorePath val = contentIndex.get(ispKey);
logger.trace("Get index{}, key: {}", (val == null ? " (NOT FOUND)" : ""), ispKey);
if (val == null) {
return null;
}
StoreKey ret = val.getOriginStoreKey();
if (ret == null) {
// for self-to-self index
ret = val.getStoreKey();
}
return ret;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class CassandraNotFoundCache method addMissing.
@Override
@Measure
public void addMissing(final ConcreteResource resource) {
KeyedLocation location = (KeyedLocation) resource.getLocation();
StoreKey key = location.getKey();
int timeoutInSeconds = DEFAULT_NOT_FOUND_CACHE_TIMEOUT_SECONDS;
int t = getTimeoutInSeconds(resource);
if (t > 0) {
timeoutInSeconds = t;
}
Date curDate = new Date();
Date timeoutDate = new Date(curDate.getTime() + (timeoutInSeconds * 1000));
logger.debug("[NFC] {} will not be checked again until {}", resource, new SimpleDateFormat(TIMEOUT_FORMAT).format(timeoutDate));
BoundStatement bound = preparedInsert.bind(key.toString(), resource.getPath(), curDate, timeoutDate, timeoutInSeconds);
session.execute(bound);
inMemoryCache.put(resource, DUMB_CACHE_VALUE, timeoutInSeconds, TimeUnit.SECONDS);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class CassandraNotFoundCache method isMissing.
@Override
@Measure
public boolean isMissing(final ConcreteResource resource) {
if (inMemoryCache.get(resource) != null) {
return true;
}
StoreKey key = getResourceKey(resource);
BoundStatement bound = preparedExistQuery.bind(key.toString(), resource.getPath());
ResultSet result = session.execute(bound);
Row row = result.one();
if (row == null) {
return false;
}
Date expiration = row.get(0, Date.class);
boolean missing = true;
logger.trace("NFC check: {}, missing: {}", resource, missing);
if (missing) {
long timeout = expiration.getTime() - System.currentTimeMillis();
if (timeout > 1000) {
inMemoryCache.put(resource, DUMB_CACHE_VALUE, new Long(timeout / 1000).intValue(), TimeUnit.SECONDS);
}
}
return missing;
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class CassandraNotFoundCache method getSize.
@Override
@Measure
public long getSize(StoreKey storeKey) {
BoundStatement bound = preparedCountByStore.bind(storeKey.toString());
ResultSet result = session.execute(bound);
return result.one().get(0, Long.class);
}
use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.
the class IspnNotFoundCache method getAllMissing.
@Override
@Measure
public Map<Location, Set<String>> getAllMissing() {
logger.debug("[NFC] getAllMissing start");
Map<Location, Set<String>> result = new HashMap<>();
Query query = queryFactory.from(NfcConcreteResourceWrapper.class).maxResults(maxResultSetSize).build();
List<NfcConcreteResourceWrapper> all = query.list();
for (NfcConcreteResourceWrapper entry : all) {
String loc = entry.getLocation();
StoreKey storeKey = fromString(loc);
Set<String> paths = result.computeIfAbsent(new NfcKeyedLocation(storeKey), k -> new HashSet<>());
paths.add(entry.getPath());
}
logger.debug("[NFC] getAllMissing complete, size: {}", all.size());
return result;
}
Aggregations