use of lombok.Synchronized in project cas by apereo.
the class AbstractMetadataResolverAdapter method buildMetadataResolverAggregate.
/**
* Build metadata resolver aggregate. Loops through metadata resources
* and attempts to resolve the metadata.
*
* @param entityId the entity id
*/
@Synchronized
@SneakyThrows
public void buildMetadataResolverAggregate(final String entityId) {
LOGGER.debug("Building metadata resolver aggregate");
this.metadataResolver = new ChainingMetadataResolver();
final List<MetadataResolver> resolvers = new ArrayList<>();
final Set<Map.Entry<Resource, MetadataFilterChain>> entries = this.metadataResources.entrySet();
entries.forEach(entry -> {
final Resource resource = entry.getKey();
LOGGER.debug("Loading [{}]", resource.getFilename());
resolvers.addAll(loadMetadataFromResource(entry.getValue(), resource, entityId));
});
this.metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
this.metadataResolver.setResolvers(resolvers);
LOGGER.info("Collected metadata from [{}] resolvers(s). Initializing aggregate resolver...", resolvers.size());
this.metadataResolver.initialize();
LOGGER.info("Metadata aggregate initialized successfully.");
}
use of lombok.Synchronized in project cas by apereo.
the class JcifsSpnegoAuthenticationHandler method doAuthentication.
@Override
@Synchronized
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) throws GeneralSecurityException {
final SpnegoCredential spnegoCredential = (SpnegoCredential) credential;
final java.security.Principal principal;
final byte[] nextToken;
if (!this.ntlmAllowed && spnegoCredential.isNtlm()) {
throw new FailedLoginException("NTLM not allowed");
}
try {
this.authentication.reset();
LOGGER.debug("Processing SPNEGO authentication");
this.authentication.process(spnegoCredential.getInitToken());
principal = this.authentication.getPrincipal();
LOGGER.debug("Authenticated SPNEGO principal [{}]", principal != null ? principal.getName() : null);
LOGGER.debug("Retrieving the next token for authentication");
nextToken = this.authentication.getNextToken();
} catch (final jcifs.spnego.AuthenticationException e) {
LOGGER.debug("Processing SPNEGO authentication failed with exception", e);
throw new FailedLoginException(e.getMessage());
}
if (nextToken != null) {
LOGGER.debug("Setting nextToken in credential");
spnegoCredential.setNextToken(nextToken);
} else {
LOGGER.debug("nextToken is null");
}
boolean success = false;
if (principal != null) {
if (spnegoCredential.isNtlm()) {
LOGGER.debug("NTLM Credential is valid for user [{}]", principal.getName());
} else {
LOGGER.debug("Kerberos Credential is valid for user [{}]", principal.getName());
}
spnegoCredential.setPrincipal(getPrincipal(principal.getName(), spnegoCredential.isNtlm()));
success = true;
}
if (!success) {
throw new FailedLoginException("Principal is null, the processing of the SPNEGO Token failed");
}
return new DefaultAuthenticationHandlerExecutionResult(this, new BasicCredentialMetaData(credential), spnegoCredential.getPrincipal());
}
use of lombok.Synchronized in project pravega by pravega.
the class SegmentInputStreamImpl method read.
/**
* @see SegmentInputStream#read()
*/
@Override
@Synchronized
public ByteBuffer read(long timeout) throws EndOfSegmentException, SegmentTruncatedException {
log.trace("Read called at offset {}", offset);
Exceptions.checkNotClosed(asyncInput.isClosed(), this);
long originalOffset = offset;
boolean success = false;
try {
ByteBuffer result = readEventData(timeout);
success = true;
return result;
} finally {
if (!success) {
outstandingRequest = null;
offset = originalOffset;
buffer.clear();
}
}
}
use of lombok.Synchronized in project pravega by pravega.
the class SegmentMonitorLeader method takeLeadership.
/**
* This function is called when the current instance is made the leader. The leadership is relinquished when this
* function exits.
*
* @param client The curator client.
* @throws Exception On any error. This would result in leadership being relinquished.
*/
@Override
@Synchronized
public void takeLeadership(CuratorFramework client) throws Exception {
log.info("Obtained leadership to monitor the Host to Segment Container Mapping");
// Attempt a rebalance whenever leadership is obtained to ensure no host events are missed.
hostsChange.release();
// Start cluster monitor.
pravegaServiceCluster = new ClusterZKImpl(client, ClusterType.HOST);
// Add listener to track host changes on the monitored pravega cluster.
pravegaServiceCluster.addListener((type, host) -> {
switch(type) {
case HOST_ADDED:
case HOST_REMOVED:
// We don't keep track of the hosts and we always query for the entire set from the cluster
// when changes occur. This is to avoid any inconsistencies if we miss any notifications.
log.info("Received event: {} for host: {}. Wake up leader for rebalancing", type, host);
hostsChange.release();
break;
case ERROR:
// This event should be due to ZK connection errors and would have been received by the monitor too,
// hence not handling it explicitly here.
log.info("Received error event when monitoring the pravega host cluster, ignoring...");
break;
}
});
// Keep looping here as long as possible to stay as the leader and exclusively monitor the pravega cluster.
while (true) {
try {
if (suspended.get()) {
log.info("Monitor is suspended, waiting for notification to resume");
suspendMonitor.acquire();
log.info("Resuming monitor");
}
hostsChange.acquire();
log.info("Received rebalance event");
// Wait here until rebalance can be performed.
waitForRebalance();
// Clear all events that has been received until this point since this will be included in the current
// rebalance operation.
hostsChange.drainPermits();
triggerRebalance();
} catch (InterruptedException e) {
log.warn("Leadership interrupted, releasing monitor thread");
// Stop watching the pravega cluster.
pravegaServiceCluster.close();
throw e;
} catch (Exception e) {
// We will not release leadership if in suspended mode.
if (!suspended.get()) {
log.warn("Failed to perform rebalancing, relinquishing leadership");
// Stop watching the pravega cluster.
pravegaServiceCluster.close();
throw e;
}
}
}
}
use of lombok.Synchronized in project pravega by pravega.
the class MockController method deleteStream.
@Override
@Synchronized
public CompletableFuture<Boolean> deleteStream(String scope, String streamName) {
Stream stream = new StreamImpl(scope, streamName);
if (createdStreams.get(stream) == null) {
return CompletableFuture.completedFuture(false);
}
for (Segment segment : getSegmentsForStream(stream)) {
deleteSegment(segment.getScopedName(), new PravegaNodeUri(endpoint, port));
}
createdStreams.remove(stream);
createdScopes.get(scope).remove(stream);
return CompletableFuture.completedFuture(true);
}
Aggregations