Search in sources :

Example 1 with Consumer

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

the class EventConsumerImpl method initialize.

/**
	 * Sets up the {@link Consumer}.
	 * <p>
	 * {@inheritDoc}
	 */
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
    super.initialize(containerServices);
    m_logger.info("initialize() called...");
    try {
        //subscribe to real channel and name
        m_consumer = new Consumer("blar", m_containerServices);
        m_consumer.addSubscription(EventDescription.class, this);
        //			m_consumer.addSubscription(NestedFridgeEventSeqHolder.class, this);
        m_logger.info("Subscribed to 'EventDescription' " + /*and 'NestedFridgeEventSeqHolder'*/
        " types of events on channel 'blar'");
        //try to add a subscription to the same type
        try {
            m_consumer.addSubscription(EventDescription.class, this);
            throw new ComponentLifecycleException("subscription to the same type should fail!");
        } catch (ComponentLifecycleException e) {
            throw e;
        } catch (Exception e) {
            //good, expected this.
            m_logger.info("Good... attempt to subscribe twice to the same event type failed with " + e.getClass().getName());
        }
        //add a subscription to something that exists but we will never actually receive
        try {
            m_consumer.addSubscription(alma.acstime.Epoch.class, this);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Bad...cannot subscribe to multiple events types.");
        // @TODO: throw exception. Perhaps move these checks to separate functional method to be called by test client.
        }
        //add a subscription to something that exists but there is no receive method implemented for.
        try {
            m_consumer.addSubscription(org.omg.CosNotification.StructuredEvent.class, this);
            System.out.println("If you'return reading this message, addSubscription is broken!");
        // @TODO: throw exception. Perhaps move these checks to separate functional method to be called by test client.
        } catch (Exception e) {
            System.out.println("Good...cannot subscribe to events where the receive method has not been implemented");
        }
        //try to add a bad filter
        try {
            if (m_consumer.addFilter(EventDescription.class, "hope to god this filter doesn't work") != -1) {
                System.out.println("If you're reading this message, stupid API allows subscribing to bad filters!");
            }
        } catch (alma.acs.exceptions.AcsJException e) {
            System.out.println("Good...cannot add a bad filter: " + e.getMessage());
        }
        //test the helper
        if (m_consumer.getHelper() == null) {
            System.out.println("Damn helper was null!");
        }
        //test offer_change
        m_consumer.offer_change(new org.omg.CosNotification.EventType[] {}, new org.omg.CosNotification.EventType[] {});
        //test disconnect_structured_push_consumer
        m_consumer.disconnect_structured_push_consumer();
        //start receiving events
        m_consumer.consumerReady();
        //test suspend
        m_consumer.suspend();
        //test resume
        m_consumer.resume();
        m_logger.info("Waiting for events...");
    } catch (ComponentLifecycleException e) {
        throw e;
    } catch (Exception e) {
        throw new ComponentLifecycleException(e);
    }
}
Also used : Consumer(alma.acs.nc.Consumer) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) EventDescription(alma.acsnc.EventDescription) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException)

Example 2 with Consumer

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

the class EventConsumerImpl method initialize.

/**
    * Sets up the {@link Consumer}.
    * <p>
    * {@inheritDoc}
    */
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
    super.initialize(containerServices);
    m_logger.info("initialize() called...");
    try {
        //subscribe to real channel and name
        m_consumer = new Consumer("blarIL", m_containerServices);
        m_consumer.addSubscription(EventDescription.class, this);
        //try to add a subscription to the same type
        try {
            m_consumer.addSubscription(EventDescription.class, this);
        } catch (Exception e) {
        //good, expected this.
        }
        //add a subscription to something that exists but we will never actually receive
        try {
            m_consumer.addSubscription(alma.acstime.Epoch.class, this);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Bad...cannot subscribe to multiple events types.");
        }
        //add a subscription to something that exists but there is no receive method implemented for.
        try {
            m_consumer.addSubscription(org.omg.CosNotification.StructuredEvent.class, this);
            System.out.println("If you'return reading this message, addSubscription is broken!");
        } catch (Exception e) {
            System.out.println("Good...cannot subscribe to events where the receive method has not been implemented");
        }
        //try to add a bad filter
        try {
            if (m_consumer.addFilter(EventDescription.class, "hope to god this filter doesn't work") != -1) {
                System.out.println("If you're reading this message, stupid API allows subscribing to bad filters!");
            }
        } catch (alma.acs.exceptions.AcsJException e) {
            System.out.println("Good...cannot add a bad filter: " + e.getMessage());
        }
        //test the helper
        if (m_consumer.getHelper() == null) {
            System.out.println("Damn helper was null!");
        }
        //test offer_change
        m_consumer.offer_change(new org.omg.CosNotification.EventType[] {}, new org.omg.CosNotification.EventType[] {});
        //test disconnect_structured_push_consumer
        m_consumer.disconnect_structured_push_consumer();
        //start receiving events
        m_consumer.consumerReady();
        //test suspend
        m_consumer.suspend();
        //test resume
        m_consumer.resume();
        System.out.println("Waiting for events...consumer");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Consumer(alma.acs.nc.Consumer) EventDescription(alma.acsnc.EventDescription) ComponentLifecycleException(alma.acs.component.ComponentLifecycleException)

Aggregations

ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)2 Consumer (alma.acs.nc.Consumer)2 EventDescription (alma.acsnc.EventDescription)2