Search in sources :

Example 16 with AcsJContainerServicesEx

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

the class ControllerImpl method initialize.

//////////////////////////////////////
///////// ComponentLifecycle /////////
//////////////////////////////////////
@Override
public void initialize(ContainerServices inContainerServices) throws ComponentLifecycleException {
    super.initialize(inContainerServices);
    try {
        String[] componentNames = getConfiguredBlobberCompNames();
        if (componentNames.length == 0) {
            throw new ComponentLifecycleException("No blobbers (" + BLOBBER_IDL_TYPE + ") found in the CDB. At least one must be configured.");
        }
        for (String componentName : componentNames) {
            try {
                blobberList.createBlobberInfo(componentName);
            } catch (AcsJIllegalArgumentEx ex) {
                m_logger.warning("Failed to process blobber component name '" + componentName + "', which apparently is a duplicate.");
            }
        }
        m_logger.info("The following configured blobber components were found: " + blobberList.getBlobberNames(false) + ". Blobbers will be requested later on demand.");
    } catch (AcsJContainerServicesEx e) {
        throw new ComponentLifecycleException(e);
    }
}
Also used : AcsJIllegalArgumentEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Example 17 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 18 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 19 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 20 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)

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