def sendMessages(self):
    supplier = Supplier(perftest.NOTIFICATION_STRESS_CHANNEL_NAME)
    for i in range(0, self.numMessages):
       supplier.publishEvent(self.event)
       if(self.delayBetweenMessages > 0):
          sleep(self.delayBetweenMessages / 1000.)
    supplier.disconnect()
    return
 def sendMessages(self):
     supplier = Supplier(perftest.NOTIFICATION_STRESS_CHANNEL_NAME)
     for i in range(0, self.numMessages):
         supplier.publishEvent(self.event)
         if (self.delayBetweenMessages > 0):
             sleep(self.delayBetweenMessages / 1000.)
     supplier.disconnect()
     return
Esempio n. 3
0
class AlarmPublisher(object):
    """
    This class provides the interface to the CORBA Notification Service used
    to send alarms to the LASER alarm server via a CORBA notification channel.
    """
    def __init__(self, topicName=None, component=None, domain=None):
        """
        Constructor

        Params:
        - topicName is the name of the notification channel to use
        - component is object generating the alarms (optional)
        - domain is the name of the domain of notification channels
          the channel belongs to. (optional)

        Returns: Nothing

        Raises:  Nothing
        """
        if domain is None:
            self.supplier = Supplier(topicName, component, ACS_NC_DOMAIN_ALARMSYSTEM)
        else:
            self.supplier = Supplier(topicName, component, domain)


    def __del__(self):
        """
        Destructor

        Params: None

        Returns: Nothing

        Raises:  Nothing
        """
        self.supplier.disconnect()
        self.supplier = None


    def publishAlarm(self, msg):
        """
        Send an alarm to the notification channel.

        Params:
        - msg is the alarm information to be sent

        Returns: Nothing

        Raises: Nothing
        """

        # The alarm notification channel expects ACSJMSMessageEntity structures to be
        # sent.  The XML form of the message is passed in the text field.  The
        # remaining fields are not used but must have default values set.
        emsg = ACSJMSMessageEntity_idl._0_com.cosylab.acs.jms.ACSJMSMessageEntity(msg.toXML(),0,False,"",0,0,[])
        self.supplier.publishEvent(simple_data=emsg)
Esempio n. 4
0
class CounterSupplier(
        COUNTER__POA.CounterSupplier,  #CORBA stubs for IDL interface
        ACSComponent,  #Base IDL interface
        ContainerServices,  #Developer niceties
        ComponentLifecycle):  #HLA stuff
    '''
    Simple component implementation provided as a reference for developers.
    '''
    def __init__(self):
        '''
        Just call superclass constructors here.
        '''
        ACSComponent.__init__(self)
        ContainerServices.__init__(self)

        self.LOGGER = getLogger("CounterSupplier")
        #LOGGER.logInfo('Passed through __init__')
        return

    #------------------------------------------------------------------------------
    #--Override ComponentLifecycle methods-----------------------------------------
    #------------------------------------------------------------------------------
    def initialize(self):
        '''
        Override this method inherited from ComponentLifecycle
        '''

        self.LOGGER.logTrace("CounterSupplier.CounterSupplier")

        #Create a supplier
        self.LOGGER.logInfo('Creating an instance of Supplier')
        self.supplier = Supplier(COUNTER.CHANNELNAME_COUNTER)

    #------------------------------------------------------------------------------
    def cleanUp(self):
        '''
        Override this method inherited from ComponentLifecycle
        '''

        if self.name == None:
            self.LOGGER.logInfo("Stopping main ...")
        else:
            self.LOGGER.logInfo("Destroying " + self.name + "...")

        #cleanly disconnect from the channel
        self.supplier.disconnect()

    #------------------------------------------------------------------------------
    #--Implementation of IDL methods-----------------------------------------------
    #------------------------------------------------------------------------------
    def sendBlocks(self, initialVal, lastVal, changeVal, period):
        '''
        Python implementation of IDL method.
        '''

        self.LOGGER.logInfo("called...")

        #Send the events
        self.LOGGER.logInfo("Ready to send NC events...")
        myString = "Python supplier"
        val = initialVal
        eventCount = 0

        while val < lastVal:
            if val < changeVal:
                flag = False
            else:
                flag = True

            self.supplier.publishEvent(
                COUNTER.statusBlockEvent(COUNTER.ON, myString, val, lastVal,
                                         changeVal, flag, period))
            eventCount = eventCount + 1
            self.LOGGER.logInfo(
                "Counting ongoing with period %.3fs up to %d, now %d" %
                (period, lastVal, val))
            val = val + 1
            sleep(period)

        # Tell consumers this is the last event
        myString = "Last event from Python supplier"
        self.supplier.publishEvent(
            COUNTER.statusBlockEvent(COUNTER.OFF, myString, lastVal, lastVal,
                                     changeVal, True, period))
        eventCount = eventCount + 1
        self.LOGGER.logInfo("Counter stopped, last value %d" % val)

        return eventCount
#--REGULAR IMPORTS-------------------------------------------------------------
from time import sleep
#--CORBA STUBS-----------------------------------------------------------------
import FRIDGE
#--ACS Imports-----------------------------------------------------------------
from Acspy.Nc.Supplier import Supplier
from Acspy.Common.Log import getLogger
#--GLOBALS---------------------------------------------------------------------
LOGGER = getLogger("FridgeNCSupplier")
#------------------------------------------------------------------------------
if __name__ == "__main__":

    #Create a supplier
    LOGGER.logInfo('Creating an instance of Supplier')
    g = Supplier(FRIDGE.CHANNELNAME_FRIDGE)

    #Create an instance of our user-defined IDL structure
    h = FRIDGE.temperatureDataBlockEvent(3.7, FRIDGE.ATREF)

    #Send 50 events
    LOGGER.logInfo("Ready to send NC events...")
    for i in range(50):
        g.publishEvent(simple_data=h)
        #Really just used for testing purposes
        sleep(1)

    LOGGER.logInfo("Events all done . . . exiting")
    #cleanly disconnect from the channel
    g.disconnect()
#------------------------------------------------------------------------------
#create data to send
h = acsnc.EventDescription("no name",
                           17L,
                           17L)

publish_all_data([g], num_events, h)

for idx in range(len(transitions)):
    n_transitions = len(transitions[idx])
    if autoreconnect:
        if ns_restarted:
            if n_transitions != 0 and n_transitions != 2:
                print datetime.datetime.now(),"===  %d: Wrong number of transitions. We expected 0 or 2 but was %d" % (idx,n_transitions)
        else:
            if n_transitions != 1:
                print datetime.datetime.now(),"===  %d: Wrong number of transitions. We expected 1 but was %d" % (idx,n_transitions)

    else:
        if ns_restarted:
            if n_transitions != 1:
                print datetime.datetime.now(),"===  %d: Wrong number of transitions. We expected 1 but was %d" % (idx,n_transitions)
        else:
            if n_transitions != 1:
                print datetime.datetime.now(),"===  %d: Wrong number of transitions. We expected 1 but was %d" % (idx,n_transitions)


#disconnect
g.disconnect()
#g_autorec.disconnect()
Esempio n. 7
0
#!/usr/bin/env python

from Acspy.Nc.Supplier import Supplier
from time import sleep
import acsnc

<<<<<<< HEAD
#channelName = "CONTROL_SYSTEM"
=======
>>>>>>> 07e962d7853ac0fea4be44e5d6acb5d48556170a
channelName = "BD_ERR_PROP"
supplier = Supplier(channelName)


for x in range(0,10000):
    h = acsnc.EventDescription("mysupplier", x, x)
    supplier.publishEvent(h)
    sleep(0.1)
    print x

supplier.disconnect()

Esempio n. 8
0
class CounterSupplier(COUNTER__POA.CounterSupplier,  #CORBA stubs for IDL interface
                ACSComponent,  #Base IDL interface
                ContainerServices,  #Developer niceties
                ComponentLifecycle):  #HLA stuff
    '''
    Simple component implementation provided as a reference for developers.
    '''
    

    def __init__(self):
        '''
        Just call superclass constructors here.
        '''
        ACSComponent.__init__(self)
        ContainerServices.__init__(self)

        self.LOGGER = getLogger("CounterSupplier")
        #LOGGER.logInfo('Passed through __init__')
        return
    #------------------------------------------------------------------------------
    #--Override ComponentLifecycle methods-----------------------------------------
    #------------------------------------------------------------------------------
    def initialize(self):
        '''
        Override this method inherited from ComponentLifecycle
        '''

        self.LOGGER.logTrace("CounterSupplier.CounterSupplier")

        #Create a supplier
        self.LOGGER.logInfo('Creating an instance of Supplier')
        self.supplier = Supplier(COUNTER.CHANNELNAME_COUNTER)


    #------------------------------------------------------------------------------
    def cleanUp(self):
        '''
        Override this method inherited from ComponentLifecycle
        '''

        if self.name == None:
            self.LOGGER.logInfo("Stopping main ...") 
        else:
            self.LOGGER.logInfo("Destroying " + self.name + "...") 

        #cleanly disconnect from the channel
        self.supplier.disconnect()
        
    #------------------------------------------------------------------------------
    #--Implementation of IDL methods-----------------------------------------------
    #------------------------------------------------------------------------------
    def sendBlocks(self, initialVal, lastVal, changeVal, period):
        '''
        Python implementation of IDL method.
        '''
        
        self.LOGGER.logInfo("called...")
        
        
        #Send the events
        self.LOGGER.logInfo("Ready to send NC events...")
        myString = "Python supplier"
        val = initialVal
        eventCount = 0

        while val < lastVal:
            if val < changeVal:
                flag = False
            else:
                flag = True
            
            self.supplier.publishEvent(COUNTER.statusBlockEvent(COUNTER.ON, myString, val, lastVal, changeVal, flag, period))
            eventCount = eventCount + 1
            self.LOGGER.logInfo("Counting ongoing with period %.3fs up to %d, now %d" % (period,  lastVal, val) )
            val = val + 1
            sleep(period)
        
        # Tell consumers this is the last event
        myString = "Last event from Python supplier"
        self.supplier.publishEvent(COUNTER.statusBlockEvent(COUNTER.OFF, myString, lastVal, lastVal, changeVal, True, period))
        eventCount = eventCount + 1
        self.LOGGER.logInfo("Counter stopped, last value %d" % val)


        return eventCount
#--GLOBALS---------------------------------------------------------------------
sup = Supplier("perf channel")

count = 0
magicNumber = long(argv[1])
#------------------------------------------------------------------------------
def eventHandler(someParam):
    '''
    '''
    global count
    count = count + 1    
    return
#------------------------------------------------------------------------------
if __name__ == "__main__":

    print 'Creating Consumer'
    g = Consumer("perf channel")
    g.addSubscription(perftest.charSeqStruct,
                      handler_function=eventHandler)
    g.consumerReady()

    #After five events have been received, disconnect from the channel
    print "Waiting for events . . ."
    while(count<magicNumber):
        sleep(1)

    print "Events all done . . . exiting"
    g.disconnect()
    sup.disconnect()
#------------------------------------------------------------------------------
Esempio n. 10
0
#!/usr/bin/env python
from Acspy.Clients.SimpleClient import PySimpleClient
from Acspy.Common.Err import ACSError
from Acspy.Common import TimeHelper
from Acspy.Nc.Supplier import Supplier
from time import sleep, time
import bulkdata

c = PySimpleClient()
supplier = Supplier(bulkdata.CHANNELNAME_ERR_PROP)
#print bulkdata.BAD_SENDER
#print bulkdata.BAD_RECEIVER
#print bulkdata.OK
print "I will send events ..."
flow = "00"
for x in range(0, 10000):
    timestamp = TimeHelper.TimeUtil().epoch2py(TimeHelper.getTimeStamp())
    h = bulkdata.errorStatusBlock(flow, bulkdata.BAD_RECEIVER, timestamp)
    #    if x % 2 == 0:
    #        h.status = bulkdata.OK
    supplier.publishEvent(h)
    sleep(0.1)
    print(x, h)

supplier.disconnect()