Search in sources :

Example 51 with ComponentInfo

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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 52 with ComponentInfo

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;
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) AcsJException(alma.acs.exceptions.AcsJException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) RemoteTransientException(com.cosylab.acs.maci.RemoteTransientException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) URISyntaxException(java.net.URISyntaxException) NamingException(javax.naming.NamingException) BadParametersException(com.cosylab.acs.maci.BadParametersException) CoreException(com.cosylab.acs.maci.CoreException) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 53 with ComponentInfo

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();
    }
}
Also used : AcsJCyclicDependencyDetectedEx(alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 54 with ComponentInfo

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;
    }
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 55 with ComponentInfo

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;
    }
}
Also used : IntArray(com.cosylab.acs.maci.IntArray) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) NoPermissionEx(alma.maciErrType.NoPermissionEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) IOException(java.io.IOException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException)

Aggregations

ComponentInfo (com.cosylab.acs.maci.ComponentInfo)66 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)24 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)24 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ClientInfo (com.cosylab.acs.maci.ClientInfo)23 RemoteException (com.cosylab.acs.maci.RemoteException)22 HashMap (java.util.HashMap)20 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)19 Component (com.cosylab.acs.maci.Component)18 URISyntaxException (java.net.URISyntaxException)18 Map (java.util.Map)18 URI (java.net.URI)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)15 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)10 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)9 ArrayList (java.util.ArrayList)8 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)7 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)6 CoreException (com.cosylab.acs.maci.CoreException)6