use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class RdfDatasetConverter method writeInternal.
@Override
protected void writeInternal(Dataset dataset, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
MediaType contentType = httpOutputMessage.getHeaders().getContentType();
Lang rdfLanguage = mimeTypeToJenaLanguage(contentType, Lang.TRIG);
WonEtagHelper.setMediaTypeForEtagHeaderIfPresent(contentType, httpOutputMessage.getHeaders());
RDFDataMgr.write(httpOutputMessage.getBody(), dataset, rdfLanguage);
// append content type to ETAG header to avoid confusing different representations of the same resource
httpOutputMessage.getBody().flush();
stopWatch.stop();
logger.debug("writing dataset took " + stopWatch.getLastTaskTimeMillis() + " millls");
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readConnectionEvents.
@RequestMapping(value = "${uri.path.data.connection}/{identifier}/events", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readConnectionEvents(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String beforeId, @RequestParam(value = "resumeafter", required = false) String afterId, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "deep", required = false, defaultValue = "false") boolean deep) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
logger.debug("readConnection() called");
Dataset rdfDataset;
HttpHeaders headers = new HttpHeaders();
Integer preferedSize = getPreferredSize(request);
URI connectionUri = URI.create(this.connectionResourceURIPrefix + "/" + identifier);
URI connectionEventsURI = URI.create(connectionUri.toString() + "/" + "events");
WonMessageType msgType = getMessageType(type);
try {
String passableMap = getPassableQueryMap("type", type);
if (preferedSize == null) {
// client doesn't not support paging - return all members; does not support type
// filtering for clients that do
// not support paging
rdfDataset = linkedDataService.listConnectionEventURIs(connectionUri, deep);
} else if (page == null && beforeId == null && afterId == null) {
// client supports paging but didn't specify which page to return - return page
// with latest events
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIs(connectionUri, 1, preferedSize, msgType, // TODO: does not
deep);
// respect
// preferredSize if
// deep is used
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
} else if (page != null) {
// a page having particular page number is requested
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIs(connectionUri, page, preferedSize, msgType, deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, page, passableMap);
} else if (beforeId != null) {
// a page that precedes the item identified by the beforeId is requested
URI referenceEvent = uriService.createEventURIForId(beforeId);
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsBefore(connectionUri, referenceEvent, preferedSize, msgType, deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
} else {
// a page that follows the item identified by the afterId is requested
URI referenceEvent = uriService.createEventURIForId(afterId);
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsAfter(connectionUri, referenceEvent, preferedSize, msgType, deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionEventsURI, resource, passableMap);
}
} catch (NoSuchConnectionException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
// TODO: events list information does change over time, unless the connection is
// closed and cannot be reopened.
// The events list of immutable connection information should never expire, the
// mutable should
addLocationHeaderIfNecessary(headers, URI.create(request.getRequestURI()), URI.create(this.connectionResourceURIPrefix));
addMutableResourceHeaders(headers);
addCORSHeader(headers);
stopWatch.stop();
logger.debug("readConnectionEvents took " + stopWatch.getLastTaskTimeMillis() + " millis");
return new ResponseEntity<>(rdfDataset, headers, HttpStatus.OK);
}
use of org.springframework.util.StopWatch in project gocd by gocd.
the class UserSqlMapDaoCachingTest method enabledUserCacheShouldBeThreadSafe.
@Test(timeout = 60000)
public void enabledUserCacheShouldBeThreadSafe() throws Exception {
ThreadSafetyChecker threadSafetyChecker = new ThreadSafetyChecker(10000);
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("enabledUserCount");
stopWatch.start("enabledUserCount");
userDao.enabledUserCount();
stopWatch.stop();
System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("deleteAll");
stopWatch.start("deleteAll");
userDao.deleteAll();
stopWatch.stop();
System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("saveOrUpdate");
stopWatch.start("saveOrUpdate");
userDao.saveOrUpdate(new User("some-random-user " + runIndex));
stopWatch.stop();
System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {
@Override
public void execute(int runIndex) {
StopWatch stopWatch = new StopWatch("enableUsers");
stopWatch.start("enableUsers");
userDao.enableUsers(Arrays.asList("some-random-user " + runIndex));
stopWatch.stop();
System.out.println(stopWatch.shortSummary());
}
});
threadSafetyChecker.run(250);
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class DefaultWoNAccessDecisionVoter method vote.
@Override
public int vote(final Authentication authentication, final Object object, final Collection collection) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
if (!(authentication instanceof PreAuthenticatedAuthenticationToken))
return ACCESS_ABSTAIN;
Object principal = authentication.getPrincipal();
if (!(principal instanceof WebIdUserDetails))
return ACCESS_ABSTAIN;
WebIdUserDetails userDetails = (WebIdUserDetails) principal;
if (!(object instanceof FilterInvocation))
return ACCESS_ABSTAIN;
String webId = userDetails.getUsername();
String resource = ((FilterInvocation) object).getRequest().getRequestURL().toString();
if (authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).filter(r -> "ROLE_WEBID".equals(r)).findAny().isPresent()) {
// perform our hard coded access control checks
List<String> webIDs = new ArrayList<>(1);
webIDs.add(webId);
if (defaultAccessControlRules.isAccessPermitted(resource, webIDs)) {
stopWatch.stop();
logger.debug("access control check took " + stopWatch.getLastTaskTimeMillis() + " millis");
return ACCESS_GRANTED;
}
return ACCESS_DENIED;
}
return ACCESS_DENIED;
}
use of org.springframework.util.StopWatch in project webofneeds by researchstudio-sat.
the class WebIdUserDetailsService method loadUserDetails.
@Override
public UserDetails loadUserDetails(final PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
String principal = (String) token.getPrincipal();
Certificate certificate = (Certificate) token.getCredentials();
logger.debug("Adding userDetails for '" + principal + "'");
URI webID = null;
try {
webID = new URI(principal);
} catch (URISyntaxException e) {
throw new BadCredentialsException("Principal of X.509 Certificate must be a WebId URI. Actual value: '" + principal + "'");
}
// at this point, we know that a client certificate was presented. Grant this role:
List<GrantedAuthority> authorities = new ArrayList<>(3);
authorities.add(new SimpleGrantedAuthority("ROLE_CLIENT_CERTIFICATE_PRESENTED"));
logger.debug("verifying webId '" + principal + "'");
try {
if (webIDVerificationAgent.verify(certificate.getPublicKey(), webID)) {
authorities.add(new SimpleGrantedAuthority("ROLE_WEBID"));
logger.debug("webId '" + principal + "' successfully verified - ROLE_WEBID granted");
} else {
logger.debug("could not verify webId '" + principal + "'. ROLE_WEBID not granted");
}
} catch (Exception e) {
logger.debug("could not verify webId '" + principal + "' because of an error during verification. ROLE_WEBID " + "not granted. Cause is logged", e);
}
stopWatch.stop();
logger.debug("webID check took " + stopWatch.getLastTaskTimeMillis() + " millis");
return new WebIdUserDetails(webID, authorities);
}
Aggregations