use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ComponentInfoTopologicalSortManager method getComponentShutdownOrder.
/**
* Get component shutdown order for container.
* @param containerInfo valid container's info, if <code>null</code> complete TS is returned.
* @return component shutdown order
*/
public ComponentInfo[] getComponentShutdownOrder(ContainerInfo containerInfo) {
if (containerInfo == null) {
synchronized (listLock) {
return currentTSList;
}
}
String containerName = containerInfo.getName();
ComponentInfo[] orderedList;
synchronized (listLock) {
orderedList = currentTSList;
}
List containerOrderdList = new ArrayList(10);
for (int j = 0; j < orderedList.length; j++) {
// if component already deactivated, skip it
if (orderedList[j].getContainer() == 0)
continue;
// this is null proof
if (containerName.equals(orderedList[j].getContainerName())) {
containerOrderdList.add(orderedList[j]);
}
}
ComponentInfo[] retVal = new ComponentInfo[containerOrderdList.size()];
containerOrderdList.toArray(retVal);
return retVal;
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponents.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponents(int, com.cosylab.acs.maci.ComponentSpec[])
* @todo this method still returns null in case of errors and only throws AcsJNoPermissions or
* a couple of runtime exceptions.
* Needs to be refactored or, probably better, deprecated.
*/
public ComponentInfo[] getDynamicComponents(int id, ComponentSpec[] components) throws AcsJNoPermissionEx {
// check if null
if (components == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'components' expected.");
throw af;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
int obtained = 0;
ComponentInfo[] componentInfos = new ComponentInfo[components.length];
for (int i = 0; i < components.length; i++) {
try {
componentInfos[i] = getDynamicComponent(id, components[i], false);
obtained++;
} catch (Exception ex) {
componentInfos[i] = null;
CoreException ce = new CoreException("Failed to get dynamic component '" + components[i] + "'.", ex);
reportException(ce);
}
}
logger.log(Level.INFO, obtained + " of " + components.length + " dynamic components obtained.");
return componentInfos;
}
use of com.cosylab.acs.maci.ComponentInfo 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();
}
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerImpl method internalRestartComponent.
/**
* Internal method for restarting components.
*
* @param owner owner of the component.
* @param h handle of the component to be restarted.
* @return Newly restarted component, <code>null</code> if failed.
*/
private Component internalRestartComponent(int owner, int h) throws AcsJNoPermissionEx {
// extract name
String name = null;
componentsLock.lock();
try {
int handle = h & HANDLE_MASK;
ComponentInfo componentInfo = null;
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;
}
name = componentInfo.getName();
} finally {
componentsLock.unlock();
}
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeout, "restart 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();
return internalNoSyncRestartComponent(owner, h);
} finally {
if (releaseRWLock)
activationPendingRWLock.readLock().unlock();
releaseSynchronizationObject(name);
}
} else {
NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for component '" + name + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
throw nre;
}
}
use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.
the class ManagerProxy method getComponentInfo.
/**
* @see com.cosylab.acs.maci.Manager#getComponentInfo(int, int[], java.lang.String, java.lang.String, boolean)
*/
public ComponentInfo[] getComponentInfo(int id, int[] handles, String name_wc, String type_wc, boolean activeOnly) throws AcsJNoPermissionEx {
try {
// returned value
ComponentInfo[] retVal = null;
// transform to CORBA specific
si.ijs.maci.ComponentInfo[] infos = manager.get_component_info(id, handles, name_wc, type_wc, activeOnly);
if (infos != null) {
retVal = new ComponentInfo[infos.length];
for (int i = 0; i < infos.length; i++) {
ComponentInfo componentInfo = new ComponentInfo(infos[i].h, infos[i].name, infos[i].type, infos[i].code, new ComponentProxy(infos[i].name, infos[i].reference));
componentInfo.setContainer(infos[i].container);
componentInfo.setContainerName(infos[i].container_name);
componentInfo.setAccessRights(ContainerProxy.inverseMapAccessRights(infos[i].access));
componentInfo.setClients(new IntArray(infos[i].clients));
componentInfo.setInterfaces(infos[i].interfaces);
retVal[i] = componentInfo;
}
}
return retVal;
} catch (NoPermissionEx npex) {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Remote manager has thrown no permission exception.");
npe.setID(HandleHelper.toString(id));
throw npe;
} catch (Exception ex) {
//throw re;
return null;
}
}
Aggregations