use of com.cosylab.acs.maci.manager.recovery.ComponentCommandClientRemove in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component.
* @param h handle of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalNoSyncReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx {
int handle = h & HANDLE_MASK;
int owners = 0;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
if (components.isAllocated(handle))
componentInfo = (ComponentInfo) components.get(handle);
if (componentInfo == null || componentInfo.getHandle() != h) {
// invalid component handle
BadParametersException af = new BadParametersException("Invalid component handle.");
throw af;
}
// remove ownership of the component
if (!componentInfo.getClients().contains(owner)) {
if (!force) {
// not an owner
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Unregistering component that client does not own.");
npe.setID(HandleHelper.toString(owner));
npe.setProtectedResource(componentInfo.getName());
throw npe;
}
} else {
// ACID - !!!
// remove client/component as an owner
executeCommand(new ComponentCommandClientRemove(componentInfo.getHandle() & HANDLE_MASK, owner));
// remove component from client component list
if (owner != this.getHandle())
removeComponentOwner(componentInfo.getHandle(), owner);
}
owners = componentInfo.getClients().size();
if (owners == 0) {
// there is not owner to be unavailable for
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(componentInfo.getName())) {
// !!! ACID
executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
//unavailableComponents.remove(componentInfo.getName());
}
}
}
} finally {
componentsLock.unlock();
}
/****************** component deactivation ******************/
ReleaseComponentResult result = new ReleaseComponentResult(owners, null);
// there is no owners of the component, deactivate it
if (force) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (owners == 0) {
int keepAliveTime = RELEASE_IMMEDIATELY;
String name = componentInfo.getName();
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
if (!isOtherDomainComponent) {
keepAliveTime = componentInfo.getKeepAliveTime();
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// when info is passed from the container
DAOProxy dao = getComponentsDAOProxy();
if (dao != null)
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
else
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
if (keepAliveTime == 0) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (keepAliveTime > 0)
delayedDeactivationTask.schedule(new DeactivateComponentTask(name), keepAliveTime * 1000);
// negative means immortal, however this could not happen since immortal
// components have manager as an owner
}
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the release request
notifyComponentReleased(new int[] { owner }, new int[] { h }, System.currentTimeMillis());
logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") released.");
// component deactivated
if (owners == 0 || force) {
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
} else if ((owner & TYPE_MASK) == COMPONENT_MASK) {
// component dependency changed...
// notify about the change (only if on the same container)...
// on complete system shutdown sort will be done anyway
ComponentInfo ownerComponentInfo = getComponentInfo(owner);
if (ownerComponentInfo != null && ownerComponentInfo.getContainerName() != null && ownerComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
return result;
}
Aggregations