Search in sources :

Example 1 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method deactivateOffShoot.

@Override
public void deactivateOffShoot(Object offshootImpl) throws AcsJContainerServicesEx {
    checkOffShoot(offshootImpl);
    try {
        acsCorba.deactivateOffShoot(m_activatedOffshootsMap.get(offshootImpl), m_clientPOA);
        m_activatedOffshootsMap.remove(offshootImpl);
        m_logger.fine("successfully deactivated offshoot of type " + offshootImpl.getClass().getName());
    } catch (AcsJContainerEx e) {
        throw new AcsJContainerServicesEx(e);
    }
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 2 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method getComponentDescriptor.

/**
	 * 
	 * @see alma.acs.container.ContainerServices#getComponentDescriptor(java.lang.String)
	 */
public ComponentDescriptor getComponentDescriptor(String curl) throws AcsJContainerServicesEx {
    if (curl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("curl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    ComponentDescriptor desc = m_componentDescriptorMap.get(curl);
    if (desc == null) {
        // try to get it from the manager
        ComponentInfo[] compInfos;
        try {
            compInfos = m_acsManagerProxy.get_component_info(new int[0], curl, "*", false);
        } catch (Throwable thr) {
            m_logger.log(Level.FINE, "Unexpected failure calling 'get_component_info'.", thr);
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
            ex.setContextInfo("CURL=" + curl);
            throw ex;
        }
        if (compInfos.length == 1) {
            desc = new ComponentDescriptor(compInfos[0]);
            m_componentDescriptorMap.put(curl, desc);
        } else {
            String msg = "failed to retrieve a unique component descriptor for the component instance " + curl;
            m_logger.fine(msg);
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
            ex.setContextInfo(msg);
            throw new AcsJContainerServicesEx();
        }
    }
    return desc;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) ComponentDescriptor(alma.acs.component.ComponentDescriptor) ComponentInfo(si.ijs.maci.ComponentInfo) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 3 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method activateOffShoot.

/**
	 * @see alma.acs.container.ContainerServices#activateOffShoot(org.omg.PortableServer.Servant)
	 */
@Override
public <T extends OffShootOperations> OffShoot activateOffShoot(T offshootImpl, Class<T> idlOpInterface) throws AcsJContainerServicesEx {
    Servant servant = null;
    boolean isTie = false;
    boolean haveToInject = false;
    // Checks
    checkOffShoot(offshootImpl);
    // and set the offshoot implementation as the final delegate
    if (!(offshootImpl instanceof Servant)) {
        if (idlOpInterface == null)
            throw new AcsJContainerServicesEx(new NullPointerException("Received null idlOpInterface when asking to activate XML offshoot"));
        if (!idlOpInterface.isAssignableFrom(offshootImpl.getClass())) {
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
            ex.setContextInfo("Received OffShoot of type '" + offshootImpl.getClass().getName() + "' does not inherits from '" + idlOpInterface.getName() + "'");
            throw ex;
        }
        // Guess the name of the xyzPOATie class, build it, and delegate
        String poaTieClassName = null;
        try {
            m_logger.fine("Creating POATie servant for offshoot '" + offshootImpl.getClass().getName() + "'");
            // Get the POATie class and the expected xyzOperations interface
            String baseClassName = idlOpInterface.getName().substring(0, idlOpInterface.getName().length() - 1);
            poaTieClassName = baseClassName + "POATie";
            Class<?> poaTieClazz = Class.forName(poaTieClassName);
            Method implGetter = poaTieClazz.getMethod("_delegate", (Class[]) null);
            Class<?> operationsIF = implGetter.getReturnType();
            // Create the dynamic XML entities wrapper
            Object proxy = DynamicProxyFactory.getDynamicProxyFactory(m_logger).createServerProxy(operationsIF, offshootImpl, idlOpInterface);
            // Create the POATie object, give it the proxy, and set it as our servant
            Constructor<?> c = poaTieClazz.getConstructor(new Class[] { operationsIF });
            servant = (Servant) c.newInstance(proxy);
            if (m_componentXmlTranslatorProxy != null)
                haveToInject = true;
        } catch (ClassNotFoundException e) {
            String msg = "Failed to create servant for offshoot " + offshootImpl.getClass().getName() + ": class '" + poaTieClassName + "' cannot be found";
            m_logger.log(AcsLogLevel.ERROR, msg, e);
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
            ex.setContextInfo(msg);
            throw ex;
        } catch (Exception e) {
            throw new AcsJContainerServicesEx(e);
        }
    } else {
        m_logger.fine("Don't need to create servant for offshoot '" + offshootImpl.getClass().getName() + "'");
        servant = (Servant) offshootImpl;
    }
    // check if the servant is the Tie variant, which allows proxy-based call interception by the container
    String servantName = servant.getClass().getName();
    if (servantName.endsWith("POATie")) {
        try {
            // the _delegate getter method is mandated by the IDL-to-Java mapping spec
            Method implGetter = servant.getClass().getMethod("_delegate", (Class[]) null);
            isTie = true;
            Class<?> operationsIF = implGetter.getReturnType();
            java.lang.Object offshootTiedImpl = implGetter.invoke(servant, (java.lang.Object[]) null);
            // now we insert the interceptor between the tie skeleton and the impl.
            // Offshoots have no name, so we construct one from the component name and the offshoot interface name
            // 
            String qualOffshootName = getName() + "/" + operationsIF.getName().substring(0, operationsIF.getName().length() - "Operations".length());
            java.lang.Object interceptingOffshootImpl = ContainerSealant.createContainerSealant(operationsIF, offshootTiedImpl, qualOffshootName, true, m_logger, Thread.currentThread().getContextClassLoader(), methodsExcludedFromInvocationLogging);
            Method implSetter = servant.getClass().getMethod("_delegate", new Class[] { operationsIF });
            implSetter.invoke(servant, new java.lang.Object[] { interceptingOffshootImpl });
            m_logger.fine("created sealant for offshoot " + qualOffshootName);
        } catch (NoSuchMethodException e) {
        // so this was not a Tie skeleton, even though its name ends misleadingly with "POATie"
        } catch (Exception e) {
            m_logger.log(Level.WARNING, "Failed to create interceptor for offshoot " + servantName, e);
        }
    }
    if (!isTie) {
    // TODO: perhaps require tie offshoots with ACS 5.0, and enable this warning log			
    //			m_logger.warning("Offshoot servant '" + servantName + "' from component '" + getName() + 
    //					"' does not follow the tie approach. Calls can thus not be intercepted by the container.");
    }
    OffShoot shoot = null;
    try {
        org.omg.CORBA.Object obj = acsCorba.activateOffShoot(servant, m_clientPOA);
        m_activatedOffshootsMap.put(offshootImpl, servant);
        shoot = OffShootHelper.narrow(obj);
    } catch (Throwable thr) {
        String msg = "failed to activate offshoot object of type '" + servant.getClass().getName() + "' for client '" + m_clientName + "'. ";
        // flatten the exception chain by one level if possible
        if (thr instanceof AcsJContainerServicesEx && thr.getCause() != null) {
            msg += "(" + thr.getMessage() + ")";
            thr = thr.getCause();
        }
        m_logger.log(Level.FINE, msg, thr);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
        throw ex;
    }
    // so when requesting an offshoot into the component, we return the corresponding CORBA object
    if (haveToInject) {
        m_logger.fine("Injecting offshoot '" + offshootImpl.getClass().getName() + "' to '" + m_clientName + "' component XML binder");
        ComponentInvocationHandler handler = (ComponentInvocationHandler) Proxy.getInvocationHandler(m_componentXmlTranslatorProxy);
        handler.addOffshoot(offshootImpl, shoot);
    }
    m_logger.fine("successfully activated offshoot of type " + offshootImpl.getClass().getName());
    return shoot;
}
Also used : Method(java.lang.reflect.Method) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Servant(org.omg.PortableServer.Servant) InvocationTargetException(java.lang.reflect.InvocationTargetException) AcsJException(alma.acs.exceptions.AcsJException) OffShoot(alma.ACS.OffShoot) ComponentInvocationHandler(alma.acs.component.dynwrapper.ComponentInvocationHandler)

Example 4 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method getCollocatedComponent.

public org.omg.CORBA.Object getCollocatedComponent(String compUrl, String targetCompUrl) throws AcsJContainerServicesEx {
    if (compUrl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("compUrl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    if (targetCompUrl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("targetCompUrl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    ComponentQueryDescriptor cqd = new ComponentQueryDescriptor(compUrl, null);
    return getCollocatedComponent(cqd, false, targetCompUrl);
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) ComponentQueryDescriptor(alma.acs.component.ComponentQueryDescriptor) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 5 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method getCollocatedComponent.

public org.omg.CORBA.Object getCollocatedComponent(ComponentQueryDescriptor spec, boolean markAsDefaul, String targetCompUrl) throws AcsJContainerServicesEx {
    if (spec == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("ComponentQueryDescriptor");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    if (targetCompUrl == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("targetCompUrl");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    ComponentInfo cInfo = null;
    try {
        // the call
        cInfo = m_acsManagerProxy.get_collocated_component(getEffectiveClientHandle(), spec.toComponentSpec(), false, targetCompUrl);
    } catch (AcsJmaciErrTypeEx ex) {
        String msg = "Failed to retrieve component '" + spec.getComponentName() + "' created such that it runs collocated with '" + targetCompUrl + "'.";
        // it's serious, but the caller is supposed to log this. Container only logs just in case.
        m_logger.log(Level.FINE, msg, ex);
        throw new AcsJContainerServicesEx(ex);
    } catch (Throwable thr) {
        String msg = "Unexpectedly failed to retrieve component '" + spec.getComponentName() + "' created such that it runs collocated with '" + targetCompUrl + "'.";
        m_logger.log(Level.FINE, msg, thr);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
        ex.setContextInfo(msg);
        throw ex;
    }
    // @todo check and remove this
    if (cInfo.reference == null) {
        String msg = "Failed to retrieve component '" + spec.getComponentName() + "' created such that it runs collocated with '" + targetCompUrl + "'.";
        m_logger.info(msg);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
        ex.setContextInfo(msg);
        throw ex;
    }
    m_usedComponentsMap.put(cInfo.name, cInfo.reference);
    m_componentDescriptorMap.put(cInfo.name, new ComponentDescriptor(cInfo));
    return cInfo.reference;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) ComponentDescriptor(alma.acs.component.ComponentDescriptor) ComponentInfo(si.ijs.maci.ComponentInfo) AcsJmaciErrTypeEx(alma.maciErrType.wrappers.AcsJmaciErrTypeEx) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Aggregations

AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)51 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJException (alma.acs.exceptions.AcsJException)6 AcsJmaciErrTypeEx (alma.maciErrType.wrappers.AcsJmaciErrTypeEx)6 ComponentDescriptor (alma.acs.component.ComponentDescriptor)5 DAL (com.cosylab.CDB.DAL)5 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)4 ComponentInfo (si.ijs.maci.ComponentInfo)4 OffShootOperations (alma.ACS.OffShootOperations)3 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)3 EntityT (alma.entities.commonentity.EntityT)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Any (org.omg.CORBA.Any)3 NamingContext (org.omg.CosNaming.NamingContext)3 Servant (org.omg.PortableServer.Servant)3 OffShoot (alma.ACS.OffShoot)2 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)2 ComponentClient (alma.acs.component.client.ComponentClient)2 AcsManagerProxy (alma.acs.container.AcsManagerProxy)2