Search in sources :

Example 1 with AcsEventPublisher

use of alma.acs.nc.AcsEventPublisher in project ACS by ACS-Community.

the class EventSupplierImpl method initialize.

/**
     * Sets up the AcsEventPublisher.
     */
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
    super.initialize(containerServices);
    try {
        // Instantiate our supplier
        m_supplier = containerServices.createNotificationChannelPublisher(alma.FRIDGE.CHANNELNAME_FRIDGE.value, IDLEntity.class);
        // enable event queue and register callback handler, just to demonstrate how this is done
        AcsEventPublisher.EventProcessingHandler<IDLEntity> cbHandler = new EventProcessingCallbackImpl();
        m_supplier.enableEventQueue(100, cbHandler);
    } catch (Exception e) {
        throw new ComponentLifecycleException("failed to create AcsEventPublisher for channel " + alma.FRIDGE.CHANNELNAME_FRIDGE.value, e);
    }
}
Also used : AcsEventPublisher(alma.acs.nc.AcsEventPublisher) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) IDLEntity(org.omg.CORBA.portable.IDLEntity) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) AcsJException(alma.acs.exceptions.AcsJException)

Example 2 with AcsEventPublisher

use of alma.acs.nc.AcsEventPublisher in project ACS by ACS-Community.

the class ContainerServicesImpl method createNotificationChannelPublisher.

/**
	 * @TODO: once we support notification over other frameworks, check that configuration 
	 * and instantiate some class other than NCPublisher.
	 * 
	 * @see ContainerServices#createNotificationChannelPublisher(String, String)
	 */
@Override
public <T> AcsEventPublisher<T> createNotificationChannelPublisher(String channelName, String channelNotifyServiceDomainName, Class<T> eventType) throws AcsJContainerServicesEx {
    AcsEventPublisher<T> publisher = null;
    try {
        Object[] args = new Object[] { channelName, channelNotifyServiceDomainName, this, getNameService() };
        //			// TODO: Can we do this without the direct cast? The usual "asSubclass" is not enough 
        // because we don't create a subclass of Class<T> but rather of Class<U<T>>.
        // Also the getGenericInterfaces / ParameterizedType trick does not work because because we don't have a 
        // concrete parameterized type.
        Class<AcsEventPublisher<T>> clazz = (Class<AcsEventPublisher<T>>) Class.forName(CLASSNAME_NC_PUBLISHER);
        Constructor<? extends AcsEventPublisher<T>> constructor = clazz.getConstructor(String.class, String.class, ContainerServicesBase.class, NamingContext.class);
        publisher = constructor.newInstance(args);
    } catch (ClassNotFoundException e) {
        // TODO: maybe we could prevent future NCPublisher creation tries, since the class isn't and will not be loaded
        //       The same applies for the next "catch" block
        m_logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because the 'NCPublisher' class is not present in the classpath", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class not present in the classpath");
        throw ex;
    } catch (ClassCastException e) {
        m_logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because loaded class '" + CLASSNAME_NC_PUBLISHER + "' is not of type 'AcsEventPublisher", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class does not extend 'AcsEventPublisher'");
        throw ex;
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            // ctor ex, seen for example in ICT-1508
            e = e.getCause();
        }
        m_logger.log(AcsLogLevel.ERROR, "Unexpected error while creating new AcsEventPublisher object", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        throw ex;
    }
    m_publishers.put((channelNotifyServiceDomainName == null ? "" : channelNotifyServiceDomainName) + "/" + channelName, publisher);
    // crude and arbitrary measure against misbehaving clients. In one case we've seen more than 2000 suppliers created by accident. 
    if (m_publishers.size() > 200) {
        m_logger.warning("Component or client '" + m_clientName + "' has already created " + m_publishers.size() + " event publishers. Developers should check if this is really necessary.");
    }
    return publisher;
}
Also used : AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) InvocationTargetException(java.lang.reflect.InvocationTargetException) AcsEventPublisher(alma.acs.nc.AcsEventPublisher) EntityT(alma.entities.commonentity.EntityT)

Example 3 with AcsEventPublisher

use of alma.acs.nc.AcsEventPublisher in project ACS by ACS-Community.

the class ManagerContainerServices method createNotificationChannelPublisher.

@Override
public <T> AcsEventPublisher<T> createNotificationChannelPublisher(String channelName, String channelNotifyServiceDomainName, Class<T> eventType) throws AcsJContainerServicesEx {
    AcsEventPublisher<T> publisher = null;
    try {
        // TODO: Matej please help, is there a more elegant way to get the naming service ref?
        org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
        NamingContext ncRef = NamingContextHelper.narrow(objRef);
        Object[] args = new Object[] { channelName, channelNotifyServiceDomainName, this, ncRef };
        //				// TODO: Can we do this without the direct cast? The usual "asSubclass" is not enough 
        // because we don't create a subclass of Class<T> but rather of Class<U<T>>.
        // Also the getGenericInterfaces / ParameterizedType trick does not work because because we don't have a 
        // concrete parameterized type.
        Class<AcsEventPublisher<T>> clazz = (Class<AcsEventPublisher<T>>) Class.forName(CLASSNAME_NC_PUBLISHER);
        Constructor<? extends AcsEventPublisher<T>> constructor = clazz.getConstructor(String.class, String.class, ContainerServicesBase.class, NamingContext.class);
        publisher = constructor.newInstance(args);
    } catch (ClassNotFoundException e) {
        // TODO: maybe we could prevent future NCPublisher creation tries, since the class isn't and will not be loaded
        //       The same applies for the next "catch" block
        logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because the 'NCPublisher' class is not present in the classpath", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class not present in the classpath");
        throw ex;
    } catch (ClassCastException e) {
        logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because loaded class '" + CLASSNAME_NC_PUBLISHER + "' is not of type 'AcsEventPublisher", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class does not extend 'AcsEventPublisher'");
        throw ex;
    } catch (Throwable e) {
        logger.log(AcsLogLevel.ERROR, "Unexpected error while creating new AcsEventPublisher object", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        throw ex;
    }
    return publisher;
}
Also used : NamingContext(org.omg.CosNaming.NamingContext) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) AcsEventPublisher(alma.acs.nc.AcsEventPublisher) NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT)

Aggregations

AcsEventPublisher (alma.acs.nc.AcsEventPublisher)3 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)1 AcsJException (alma.acs.exceptions.AcsJException)1 EntityT (alma.entities.commonentity.EntityT)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NO_IMPLEMENT (org.omg.CORBA.NO_IMPLEMENT)1 IDLEntity (org.omg.CORBA.portable.IDLEntity)1 NamingContext (org.omg.CosNaming.NamingContext)1