Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following depicts the usage of a SimpleConsumer. As always, bolded text should be adapted for your particular needs and error handling has been omitted. ACS/LGPL/CommonSoftware/acsexmpl/ws/src/acsexmplClientFridgeNC.cpp:

Code Block
languagecpp
titleACS/LGPL/CommonSoftware/acsexmpl/ws/src/acsexmplClientFridgeNC.cpp
linenumberstrue
#include "acsexmplFridgeC.h"
//…
//-----------------------------------------------------------------------------
void myHandlerFunction(FRIDGE::temperatureDataBlockEvent joe, void *other)
{
ACS_SHORT_LOG((LM_INFO, "::myHandlerFunction(...): %f is the tempdiff.",
joe.absoluteDiff));
}
//-----------------------------------------------------------------------------
//…

nc::SimpleConsumer<FRIDGE::temperatureDataBlockEvent> {}simpConsumer_p{*}=0;
ACS_NEW_SIMPLE_CONSUMER(simpConsumer_p,
						FRIDGE::temperatureDataBlockEvent,
						FRIDGE::CHANNELNAME_FRIDGE,
						myHandlerFunction,
						(void *)0);

simpConsumer_p->consumerReady();

ACE_Time_Value time(150);
client.run(time);
simpConsumer_p->disconnect(); simpConsumer_p=0;
//…

...

The following depicts the full implementation of a Supplier which publishes one event and then disconnects from the channel. As always, bolded text should be adapted for your particular needs and error handling has been omitted.

Code Block
languagepy
titleACS/LGPL/CommonSoftware/acspyexmpl/src/acspyexmplFridgeNCSupplier.py
linenumberstrue
#!/usr/bin/env python

...


#------------------------------------------------------------------------------

...


import FRIDGE

...


from Acspy.Nc.Supplier import Supplier

...


#------------------------------------------------------------------------------

...


g = Supplier(FRIDGE.CHANNELNAME_FRIDGE)

...


h = FRIDGE.temperatureDataBlockEvent(3.7, FRIDGE.ATREF)

...


g.publishEvent(h)

...


g.disconnect()

...


#------------------------------------------------------------------------------

3

FRIDGE is the CORBA stub module generated by the IDL compiler. It contains the user-defined IDL structure this script is designed to publish as well as the channel's name.

6

This supplier will publish events to the "fridge" channel. Within a component, a second parameter (i.e., self) would also have to be passed.

7

Create an instance of the user-defined IDL structure to be published.

8

Publish the IDL structure created on line 7.

9

Disconnect from the notification channel.

...

...

Python Consumer

A Python consumer is by far the easiest to use of the ACS-supported CORBA language mappings.

...

Example

The following depicts the full implementation of a Consumer. As always, bolded text should be adapted for your particular needs and error handling has been omitted.
ACS/LGPL/CommonSoftware/acspyexmpl/src/acspyexmplFridgeNCConsumer.py



Code Block
languagepy
titleACS/LGPL/CommonSoftware/acspyexmpl/src/acspyexmplFridgeNCConsumer.py
linenumberstrue
#!/usr/bin/env python

...


from time import sleep

...


import FRIDGE

...


from Acspy.Nc.Consumer import Consumer

...


#------------------------------------------------------------------------------

...


def fridgeDataHandler(some_param):

...


tempDiff = some_param.absoluteDiff

...


print 'The temperature difference is', tempDiff

...


return

...


#------------------------------------------------------------------------------

...


g = Consumer(FRIDGE.CHANNELNAME_FRIDGE)

...


g.addSubscription(FRIDGE.temperatureDataBlockEvent, fridgeDataHandler)

...


g.consumerReady()

...


sleep(50)

...


g.disconnect()

...


#---------------------------------------------------------------------------


3

FRIDGE is the CORBA stub module generated by the IDL compiler. It contains the user-defined IDL structure this script is designed to process as well as the channel's name.

6-9

We must define a function which is capable of manipulating FRIDGE.temperatureDataBlockEvent's. This function will be invoked each time an event is received from the notification channel by registering it with the consumer (line 12). Take note that someParam will always be an instance of FRIDGE.temperatureDataBlockEvent.

11

Create an instance of Consumer connecting to the "fridge" channel.

12

Subscribe to FRIDGE.temperatureDataBlockEvent events and inform the consumer it needs to invoke fridgeDataHandler each time a temperatureDataBlockEvent event is received.

13

Let the channel know we are ready to start processing events.

14

Give suppliers time to publish events…

15

Disconnect from the channel.

...

Java Supplier

Java suppliers and consumer need to be run from the context of a component or ACS Java client.

...

Example

The following shows an example publishing one event and then disconnecting from the channel. Bold text needs to be adapted for your particular needs and error handling has been omitted.


Code Block
languagejava
titleACS/LGPL/CommonSoftware/jcontexmpl/src/alma/demo/EventSupplierImpl/EventSupplierImpl.java

...

linenumberstrue
//…

...


import alma.acs.nc.SimpleSupplier;

...


import alma.FRIDGE.temperatureDataBlockEvent;

...


import alma.FRIDGE.TemperatureStatus;

...


//…

...


SimpleSupplier m_supplier = null;

...


m_supplier = new SimpleSupplier(alma.FRIDGE.CHANNELNAME_FRIDGE.value, m_containerServices);

...



temperatureDataBlockEvent t_block = new temperatureDataBlockEvent(3.14F,

...


																TemperatureStatus.ATREF);

...



m_supplier.publishEvent(t_block);

...


m_supplier.disconnect();


1 & 5

Normally suppliers will be contained within components. This example assumes nothing about whether it's operating under the context of a component, client, etc.

2

Import the SimpleSupplier class used to publish events.

3-4

CORBA Stub classes generated by the IDL to Java compiler. These define the event to be published.

6

The SimpleSupplier variable to be used.

7

The first parameter of SimpleSupplier's constructor is the name of the channel events will be published on. A ContainerServices object is required as the second parameter to gain access to the ORB.

9-10

Create an instance of the IDL structure to publish.

12

Publish the event.

13

Disconnect from the channel.

...

...

Java Consumer

...

Example

What follows is a trivial consumer that processes one event and then disconnects from the channel.
ACS/LGPL/CommonSoftware/jcontexmpl/src/alma/demo/EventConsumerImpl/EventConsumerImpl.java:

...

ACS provides a graphical user interface which provides some high-level information about events being sent, number of consumers, etc.:

This GUI is started by running "acseventbrowser" from the command-line after Manager is up and running.

...


Known Problems


Not all Quality of Service and Administrative Properties Work

...