use of alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx in project ACS by ACS-Community.
the class ManagerImpl method internalRequestComponent.
/**
* Internal method for requesting components.
* @param requestor requestor of the component.
* @param name name of component to be requested, non-<code>null</code>.
* @param type type of component to be requested; if <code>null</code> CDB will be queried.
* @param code code of component to be requested; if <code>null</code> CDB will be queried.
* @param containerName container name of component to be requested; if <code>null</code> CDB will be queried.
* @param status returned completion status of the request.
* @param activate <code>true</code> if component has to be activated
* @return componentInfo <code>ComponentInfo</code> of requested component.
*/
private ComponentInfo internalRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJSyncLockFailedEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
AcsJCannotGetComponentEx bcex = null;
if (name == null) {
bcex = new AcsJCannotGetComponentEx();
logger.log(Level.SEVERE, "Cannot activate component with NULL name.", bcex);
throw bcex;
}
if (status == null) {
bcex = new AcsJCannotGetComponentEx();
logger.log(Level.SEVERE, "Component " + name + " has NULL status.", bcex);
throw bcex;
}
try {
checkCyclicDependency(requestor, name);
} catch (AcsJCyclicDependencyDetectedEx e) {
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
cgce.setCURL(name);
throw cgce;
}
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(name, getLockTimeout(), "request component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = true;
try {
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
activationPendingRWLock.readLock().lock();
// AcsJComponentSpecIncompatibleWithActiveComponentEx flies up
return internalNoSyncRequestComponent(requestor, name, type, code, containerName, keepAliveTime, status, activate);
} finally {
if (releaseRWLock)
activationPendingRWLock.readLock().unlock();
releaseSynchronizationObject(name);
}
} else {
AcsJSyncLockFailedEx slfe = new AcsJSyncLockFailedEx();
slfe.setCURL(name);
slfe.setRequestor(requestor);
slfe.setProperty("lockCause", lockNotAcquiredCause);
throw slfe;
}
}
use of alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx in project ACS by ACS-Community.
the class ManagerImpl method internalRequestComponent.
/**
* Internal method for requesting components.
* @param requestor requestor of the component.
* @param curl curl of the component to be requested.
* @param status status of the component.
* @param activate <code>true</code> if component has to be activated
* @return component requested component.
*/
private Component internalRequestComponent(int requestor, URI curl, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx {
// extract unique name
String name = extractName(curl);
try {
checkCyclicDependency(requestor, name);
} catch (AcsJCyclicDependencyDetectedEx e) {
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
cgce.setCURL(name);
throw cgce;
}
// try to acquire lock
long lockTimeoutMillis = getLockTimeout();
String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeoutMillis, "request component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = true;
try {
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
activationPendingRWLock.readLock().lock();
// Let AcsJCannotGetComponentEx fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalNoSyncRequestComponent(requestor, name, null, null, null, RELEASE_TIME_UNDEFINED, status, activate);
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(ciwace);
cgce.setCURL(name);
throw cgce;
}
if (componentInfo != null) {
return componentInfo.getComponent();
} else {
return null;
}
} finally {
if (releaseRWLock) {
activationPendingRWLock.readLock().unlock();
}
releaseSynchronizationObject(name);
}
} else {
String msg = "Failed to obtain synchronization lock for component '" + name + "' within '" + lockTimeoutMillis + "' ms, possible deadlock; locked to '" + lockNotAcquiredCause + "'.";
logger.fine(msg);
NoResourcesException nre = new NoResourcesException(msg);
throw nre;
}
}
use of alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx in project ACS by ACS-Community.
the class ManagerImpl method checkCyclicDependency.
/**
* Check for cyclic dependency between components, if detected <code>NoResourcesException</code> exception is thrown.
* @param requestor
* @param requestedComponentName
*/
private void checkCyclicDependency(int requestor, String requestedComponentName) throws AcsJCyclicDependencyDetectedEx {
// check only if component is requesting component
if ((requestor & TYPE_MASK) != COMPONENT_MASK)
return;
// check if requested component is already activated (and pending activations)
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
int h = components.first();
while (h != 0) {
ComponentInfo info = (ComponentInfo) components.get(h);
if (info.getName().equals(requestedComponentName)) {
// yes, component is already activated
componentInfo = info;
break;
} else
h = components.next(h);
}
// check pending activations...
ComponentInfo pendingComponentInfo;
synchronized (pendingActivations) {
pendingComponentInfo = pendingActivations.get(requestedComponentName);
}
// if component is already completely activated, we allow cyclic dependencies (but their usage is discouraged)
if (componentInfo != null && pendingComponentInfo == null)
return;
// take pending activation...
if (componentInfo == null)
componentInfo = pendingComponentInfo;
// not activated yet, so no cyclic dependency is possible
if (componentInfo == null)
return;
ArrayList<ComponentInfo> pathList = doCycleCheck(requestor, componentInfo.getHandle());
// no dependency detected
if (pathList == null)
return;
// stringify
StringBuffer pathBuffer = new StringBuffer();
for (int i = pathList.size() - 1; i >= 0; i--) pathBuffer.append(pathList.get(i).getName()).append(" -> ");
pathBuffer.append(componentInfo.getName());
// TODO @todo no pathBuffer is used, printed-out
// If we get to this point there is a cyclical dependency and we throw the exception
// not an owner
AcsJCyclicDependencyDetectedEx cde = new AcsJCyclicDependencyDetectedEx();
cde.setCURL(requestedComponentName);
cde.setRequestor(requestor);
throw cde;
} finally {
componentsLock.unlock();
}
}
Aggregations