use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class DocumentNodeState method getChildNodeDoc.
//------------------------------< internal >--------------------------------
@CheckForNull
private AbstractDocumentNodeState getChildNodeDoc(String childNodeName) {
AbstractDocumentNodeState secondaryState = getSecondaryNodeState();
if (secondaryState != null) {
NodeState result = secondaryState.getChildNode(childNodeName);
//else return null
if (result.exists()) {
return (AbstractDocumentNodeState) result;
}
return null;
}
Matcher child = bundlingContext.matcher.next(childNodeName);
if (child.isMatch()) {
if (bundlingContext.hasChildNode(child.getMatchedPath())) {
return createBundledState(childNodeName, child);
} else {
return null;
}
}
return store.getNode(concat(getPath(), childNodeName), lastRevision);
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class DocumentNodeStoreBranch method acquireMergeLock.
/**
* Acquires the merge lock either exclusive or shared.
*
* @param exclusive whether to acquire the merge lock exclusive.
* @return the acquired merge lock or {@code null} if the operation timed
* out.
* @throws CommitFailedException if the current thread is interrupted while
* acquiring the lock
*/
@CheckForNull
private Lock acquireMergeLock(boolean exclusive) throws CommitFailedException {
final long start = perfLogger.start();
Lock lock;
if (exclusive) {
lock = mergeLock.writeLock();
} else {
lock = mergeLock.readLock();
}
boolean acquired;
try {
acquired = lock.tryLock(maxLockTryTimeMS, MILLISECONDS);
} catch (InterruptedException e) {
throw new CommitFailedException(OAK, 1, "Unable to acquire merge lock", e);
}
String mode = exclusive ? "exclusive" : "shared";
if (acquired) {
perfLogger.end(start, 1, "Merge - Acquired lock ({})", mode);
} else {
LOG.info("Time out while acquiring merge lock ({})", mode);
lock = null;
}
return lock;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class EffectiveType method getDefaultType.
/**
* Finds the default node type for a child node with the given name.
*
* @param nameWithIndex child node name, possibly with an SNS index
* @return default type, or {@code null} if not found
*/
@CheckForNull
String getDefaultType(@Nonnull String nameWithIndex) {
String name = dropIndexFromName(nameWithIndex);
boolean sns = !name.equals(nameWithIndex);
for (NodeState type : types) {
NodeState named = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
for (ChildNodeEntry entry : concat(named.getChildNodeEntries(), residual.getChildNodeEntries())) {
NodeState definition = entry.getNodeState();
String defaultType = definition.getName(JCR_DEFAULTPRIMARYTYPE);
if (defaultType != null && snsMatch(sns, definition)) {
return defaultType;
}
}
}
return null;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class AbstractLoginModule method getRoot.
/**
* Tries to obtain a {@code Root} object from the callback handler using
* a new RepositoryCallback and keeps the value as private field.
* If the callback handler isn't able to handle the RepositoryCallback
* this method returns {@code null}.
*
* @return The {@code Root} associated with this {@code LoginModule} or
* {@code null}.
*/
@CheckForNull
protected Root getRoot() {
if (root == null && callbackHandler != null) {
try {
final RepositoryCallback rcb = new RepositoryCallback();
callbackHandler.handle(new Callback[] { rcb });
final ContentRepository repository = rcb.getContentRepository();
if (repository != null) {
systemSession = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws LoginException, NoSuchWorkspaceException {
return repository.login(null, rcb.getWorkspaceName());
}
});
root = systemSession.getLatestRoot();
} else {
log.debug("Unable to retrieve the Root via RepositoryCallback; ContentRepository not available.");
}
} catch (UnsupportedCallbackException | PrivilegedActionException | IOException e) {
log.debug(e.getMessage());
}
}
return root;
}
use of javax.annotation.CheckForNull in project jackrabbit-oak by apache.
the class AbstractLoginModule method getCredentials.
/**
* Tries to retrieve valid (supported) Credentials:
* <ol>
* <li>using a {@link CredentialsCallback},</li>
* <li>looking for a {@link #SHARED_KEY_CREDENTIALS} entry in the
* shared state (see also {@link #getSharedCredentials()} and finally by</li>
* <li>searching for valid credentials in the subject.</li>
* </ol>
*
* @return Valid (supported) credentials or {@code null}.
*/
@CheckForNull
protected Credentials getCredentials() {
Set<Class> supported = getSupportedCredentials();
if (callbackHandler != null) {
log.debug("Login: retrieving Credentials using callback.");
try {
CredentialsCallback callback = new CredentialsCallback();
callbackHandler.handle(new Callback[] { callback });
Credentials creds = callback.getCredentials();
if (creds != null && supported.contains(creds.getClass())) {
log.debug("Login: Credentials '{}' obtained from callback", creds);
return creds;
} else {
log.debug("Login: No supported credentials obtained from callback; trying shared state.");
}
} catch (UnsupportedCallbackException e) {
log.warn(e.getMessage());
} catch (IOException e) {
log.error(e.getMessage());
}
}
Credentials creds = getSharedCredentials();
if (creds != null && supported.contains(creds.getClass())) {
log.debug("Login: Credentials obtained from shared state.");
return creds;
} else {
log.debug("Login: No supported credentials found in shared state; looking for credentials in subject.");
for (Class clz : getSupportedCredentials()) {
Set<Credentials> cds = subject.getPublicCredentials(clz);
if (!cds.isEmpty()) {
log.debug("Login: Credentials found in subject.");
return cds.iterator().next();
}
}
}
log.debug("No credentials found.");
return null;
}
Aggregations