Search in sources :

Example 6 with RemoteException

use of com.cosylab.acs.maci.RemoteException in project ACS by ACS-Community.

the class ManagerImpl method internalNoSyncDeactivateComponent.

/**
	 * Deactivate component, issue deactivate reeust to container (or other manager).
	 * @param componentInfo	info about component to be deactivated.
	 */
private void internalNoSyncDeactivateComponent(ComponentInfo componentInfo) throws Throwable {
    // unbind from remote directory
    //unbind(convertToHiearachical(componentInfo.getName()), "O");
    int handle = componentInfo.getHandle() & HANDLE_MASK;
    int owners = componentInfo.getClients().size();
    try {
        //
        // get container/remote manager
        //
        String name = componentInfo.getName();
        boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
        if (isOtherDomainComponent) {
            Manager remoteManager = null;
            // @todo MF do the login?
            try {
                String domainName = CURLHelper.createURI(name).getAuthority();
                remoteManager = getManagerForDomain(domainName);
                if (remoteManager == null)
                    throw new CoreException("Failed to obtain manager for domain '" + domainName + "'.");
            } catch (Throwable th) {
                logger.log(Level.WARNING, "Failed to obtain non-local manager required by component '" + name + "'.", th);
                throw th;
            }
            // release component
            try {
                URI curlName = CURLHelper.createURI(name);
                // @todo MF tmp (handle)
                remoteManager.releaseComponent(INTERDOMAIN_MANAGER_HANDLE, curlName);
            } catch (Throwable th) {
                logger.log(Level.WARNING, "Failed to release component '" + componentInfo.getName() + "' on remote manager.'", th);
                throw th;
            }
        } else {
            //
            // search for container by its name
            //
            Container container = null;
            ContainerInfo containerInfo = null;
            int containerHandle = componentInfo.getContainer();
            // if containerHandle equals 0, we have unavailable or registered component
            if (containerHandle != 0) {
                containerInfo = getContainerInfo(containerHandle);
                if (containerInfo != null) {
                    // remove component from container component list
                    synchronized (containerInfo.getComponents()) {
                        // !!! ACID
                        if (containerInfo.getComponents().contains(componentInfo.getHandle()))
                            executeCommand(new ContainerInfoCommandComponentRemove(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
                    //containerInfo.getComponents().remove(componentInfo.getHandle());
                    }
                    // we allow this (since releasing components is part of container shutdown procedure)
                    //checkContainerState(containerInfo);
                    container = containerInfo.getContainer();
                }
                // required container is not logged in
                if (container == null) {
                    // then simply do not do the deactivation
                    String containerName;
                    if (containerInfo != null)
                        containerName = containerInfo.getName();
                    else
                        containerName = HandleHelper.toString(componentInfo.getContainer());
                    logger.log(Level.WARNING, "Container '" + containerName + "' required by component '" + componentInfo.getName() + "' is not logged in.");
                }
            }
            if (container != null) {
                // log info
                logger.log(Level.INFO, "Deactivating component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.");
                // destruct
                try {
                    componentInfo.getComponent().destruct();
                } catch (Throwable ex) {
                    RemoteException re = new RemoteException("Failed to destruct component '" + componentInfo.getName() + "', exception caught when invoking 'destruct()' method.", ex);
                    logger.log(Level.SEVERE, re.getMessage(), re);
                    throw ex;
                }
                long deactivationTime = 0;
                // deactivate component in anycase
                try {
                    container.deactivate_component(componentInfo.getHandle());
                    deactivationTime = System.currentTimeMillis();
                } catch (AcsJException aex) {
                    logger.log(Level.SEVERE, aex.getMessage(), aex);
                    throw aex;
                } catch (Throwable ex) {
                    RemoteException re = new RemoteException("Failed to deactivate component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.", ex);
                    logger.log(Level.SEVERE, re.getMessage(), re);
                    throw ex;
                }
                // notify administrators about deactivation, but not if failed
                if (deactivationTime != 0)
                    notifyComponentDeactivated(componentInfo.getHandle(), deactivationTime);
                // shutdown container if required (and necessary)
                conditionalShutdownContainer(containerInfo);
            }
        }
    } finally {
        if (owners == 0) {
            // deallocate Component
            componentsLock.lock();
            try {
                executeCommand(new ComponentCommandDeallocate(handle, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
            //components.deallocate(handle);
            } finally {
                componentsLock.unlock();
            }
        }
    }
    // log info
    logger.log(Level.INFO, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") deactivated.");
    // release all subcomponents (just like client logoff)
    // component should have already done this by itself, but take care of clean cleanup
    // what about that: if subcomponent becomes unavailable, does component also becomes?!
    // no, it is notified and it handles situation by its own way (e.g. changes component state).
    // Just like it already handles activation (manager does not care for dependecy trees).
    int[] subcomponents = null;
    // no not hold the lock
    synchronized (componentInfo.getComponents()) {
        if (componentInfo.getComponents().size() > 0) {
            IntArray toCleanupList = new IntArray();
            IntArray comps = componentInfo.getComponents();
            for (int i = 0; i < comps.size(); i++) if (components.isAllocated(comps.get(i) & HANDLE_MASK))
                toCleanupList.add(comps.get(i));
            if (toCleanupList.size() > 0)
                subcomponents = toCleanupList.toArray();
        }
    //subcomponents = componentInfo.getComponents().toArray();
    }
    if (subcomponents != null && subcomponents.length > 0)
        new ReleaseComponentTask(componentInfo.getHandle(), subcomponents).run();
    // make unavailable (deactivation was forced)
    if (owners > 0)
        makeUnavailable(componentInfo);
}
Also used : AcsJException(alma.acs.exceptions.AcsJException) Manager(com.cosylab.acs.maci.Manager) URI(java.net.URI) Container(com.cosylab.acs.maci.Container) CoreException(com.cosylab.acs.maci.CoreException) IntArray(com.cosylab.acs.maci.IntArray) ContainerInfoCommandComponentRemove(com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentRemove) ComponentCommandDeallocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandDeallocate) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException)

Example 7 with RemoteException

use of com.cosylab.acs.maci.RemoteException in project ACS by ACS-Community.

the class AdministratorProxy method component_activated.

/**
	 * @see com.cosylab.acs.maci.Administrator#component_activated(com.cosylab.acs.maci.ComponentInfo, long, long)
	 */
public void component_activated(ComponentInfo info, long timeStamp, long executionId) throws RemoteException {
    try {
        // invalid info (replacement for null)
        final si.ijs.maci.ComponentInfo invalidInfo = new si.ijs.maci.ComponentInfo("<invalid>", "<invalid>", null, "<invalid>", new int[0], 0, "<invalid>", 0, 0, new String[0]);
        si.ijs.maci.ComponentInfo componentInfo = invalidInfo;
        if (info != null) {
            Object obj = null;
            if (info.getComponent() != null)
                obj = (Object) info.getComponent().getObject();
            String[] interfaces;
            if (info.getInterfaces() != null)
                interfaces = info.getInterfaces();
            else
                interfaces = new String[0];
            componentInfo = new si.ijs.maci.ComponentInfo(info.getType(), info.getCode(), obj, info.getName(), info.getClients().toArray(), info.getContainer(), info.getContainerName(), info.getHandle(), ManagerProxyImpl.mapAccessRights(info.getAccessRights()), interfaces);
        }
        administrator.component_activated(componentInfo, UTCUtility.utcJavaToOmg(timeStamp), executionId);
    } catch (TIMEOUT te) {
        throw new RemoteTimeoutException("Failed to invoke 'component_activated()' method due to timeout.", te);
    } catch (TRANSIENT tre) {
        throw new RemoteTransientException("Failed to invoke 'component_activated()' method due to transient exception.", tre);
    } catch (Throwable ex) {
        throw new RemoteException("Failed to invoke 'component_activated()' method.", ex);
    }
}
Also used : RemoteTimeoutException(com.cosylab.acs.maci.RemoteTimeoutException) Object(org.omg.CORBA.Object) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) TIMEOUT(org.omg.CORBA.TIMEOUT) RemoteException(com.cosylab.acs.maci.RemoteException) TRANSIENT(org.omg.CORBA.TRANSIENT) RemoteTransientException(com.cosylab.acs.maci.RemoteTransientException)

Example 8 with RemoteException

use of com.cosylab.acs.maci.RemoteException in project ACS by ACS-Community.

the class ClientProxy method components_available.

/**
	 * @see com.cosylab.acs.maci.Client#components_available(ComponentInfo[])
	 */
public void components_available(ComponentInfo[] cobs) throws RemoteException {
    try {
        // invalid info (replacement for null)
        final si.ijs.maci.ComponentInfo invalidInfo = new si.ijs.maci.ComponentInfo("<invalid>", "<invalid>", null, "<invalid>", new int[0], 0, "<invalid>", 0, 0, new String[0]);
        // transform to CORBA specific 
        si.ijs.maci.ComponentInfo[] infos = null;
        if (cobs != null) {
            infos = new si.ijs.maci.ComponentInfo[cobs.length];
            for (int i = 0; i < cobs.length; i++) if (cobs[i] == null)
                infos[i] = invalidInfo;
            else {
                Object obj = null;
                if (cobs[i].getComponent() != null)
                    obj = (Object) cobs[i].getComponent().getObject();
                String[] interfaces;
                if (cobs[i].getInterfaces() != null)
                    interfaces = cobs[i].getInterfaces();
                else
                    interfaces = new String[0];
                infos[i] = new si.ijs.maci.ComponentInfo(cobs[i].getType(), cobs[i].getCode(), obj, cobs[i].getName(), cobs[i].getClients().toArray(), cobs[i].getContainer(), cobs[i].getContainerName(), cobs[i].getHandle(), ManagerProxyImpl.mapAccessRights(cobs[i].getAccessRights()), interfaces);
            }
        } else
            infos = new si.ijs.maci.ComponentInfo[0];
        client.components_available(infos);
    } catch (TIMEOUT te) {
        throw new RemoteTimeoutException("Failed to invoke 'components_available()' method due to timeout.", te);
    } catch (TRANSIENT tre) {
        throw new RemoteTransientException("Failed to invoke 'components_available()' method due to transient exception.", tre);
    } catch (Throwable ex) {
        throw new RemoteException("Failed to invoke 'component_available()' method.", ex);
    }
}
Also used : RemoteTimeoutException(com.cosylab.acs.maci.RemoteTimeoutException) Object(org.omg.CORBA.Object) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) TIMEOUT(org.omg.CORBA.TIMEOUT) RemoteException(com.cosylab.acs.maci.RemoteException) TRANSIENT(org.omg.CORBA.TRANSIENT) RemoteTransientException(com.cosylab.acs.maci.RemoteTransientException)

Example 9 with RemoteException

use of com.cosylab.acs.maci.RemoteException in project ACS by ACS-Community.

the class ClientProxy method taggedmessage.

/**
	 * @see com.cosylab.acs.maci.Client#message(MessageType, String)
	 */
public void taggedmessage(MessageType type, short id, String message) throws RemoteException {
    try {
        short msgType;
        if (type == MessageType.MSG_ERROR)
            msgType = si.ijs.maci.Client.MSG_ERROR;
        else
            msgType = si.ijs.maci.Client.MSG_INFORMATION;
        client.taggedmessage(msgType, id, message);
    } catch (TIMEOUT te) {
        throw new RemoteTimeoutException("Failed to invoke 'tagged_message()' method due to timeout.", te);
    } catch (TRANSIENT tre) {
        throw new RemoteTransientException("Failed to invoke 'tagged_message()' method due to transient exception.", tre);
    } catch (Throwable ex) {
        throw new RemoteException("Failed to invoke 'tagged_message()' method.", ex);
    }
}
Also used : RemoteTimeoutException(com.cosylab.acs.maci.RemoteTimeoutException) TIMEOUT(org.omg.CORBA.TIMEOUT) RemoteException(com.cosylab.acs.maci.RemoteException) TRANSIENT(org.omg.CORBA.TRANSIENT) RemoteTransientException(com.cosylab.acs.maci.RemoteTransientException)

Example 10 with RemoteException

use of com.cosylab.acs.maci.RemoteException in project ACS by ACS-Community.

the class ClientProxyImpl method taggedmessage.

/**
	 * @see si.ijs.maci.ClientOperations#taggedmessage(short, String)
	 */
public void taggedmessage(short type, short id, String message) {
    try {
        MessageType msgType;
        if (type == Client.MSG_ERROR)
            msgType = MessageType.MSG_ERROR;
        else
            msgType = MessageType.MSG_INFORMATION;
        client.taggedmessage(msgType, id, message);
    } catch (RemoteException re) {
    // noop.
    }
}
Also used : RemoteException(com.cosylab.acs.maci.RemoteException) MessageType(com.cosylab.acs.maci.MessageType)

Aggregations

RemoteException (com.cosylab.acs.maci.RemoteException)21 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)8 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)7 RemoteTransientException (com.cosylab.acs.maci.RemoteTransientException)7 TIMEOUT (org.omg.CORBA.TIMEOUT)7 RemoteTimeoutException (com.cosylab.acs.maci.RemoteTimeoutException)6 IOException (java.io.IOException)6 TRANSIENT (org.omg.CORBA.TRANSIENT)6 AcsJException (alma.acs.exceptions.AcsJException)5 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)4 IntArray (com.cosylab.acs.maci.IntArray)4 BadParametersException (com.cosylab.acs.maci.BadParametersException)3 Container (com.cosylab.acs.maci.Container)3 URI (java.net.URI)3 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)2 ClientInfo (com.cosylab.acs.maci.ClientInfo)2 Component (com.cosylab.acs.maci.Component)2 CoreException (com.cosylab.acs.maci.CoreException)2 Manager (com.cosylab.acs.maci.Manager)2 MessageType (com.cosylab.acs.maci.MessageType)2