[AG-TECH] AGService development problem

Ismail Bhana i.m.bhana at reading.ac.uk
Sat Jan 13 09:01:57 CST 2007


I've been developing a set of node services called JMast (JMastConsumer 
and JMastProducer services) which basically provide a form of 
application sharing using streaming technologies. However, whilst I can 
get the software to boot from AG 3.0.2 with parameters passed correctly 
I'm having a problem where I'm being passed the same multicast 
address/port as the vic tool which causes vic to crash. If I change the 
Capabilities type (say, from "JMAST" to "jmast1") a different address to 
vic is assigned in the first instance of execution but the next time I 
run the software its back to giving me the same address/port as vic and 
I can't really work out why.

Posted below are the scripts I've been using, I'm a novice at this so 
any comments/help would be greatly appreciated.

Thanks,

Ismail Bhana

#-----------------------------------------------------------------------------
# Name:        JMastProducerService.py
# Author:      IMB
# Created:     2007/01/01
# Copyright:   (c) 2007
# Licence:     See LICENSE.TXT
#-----------------------------------------------------------------------------
import os
import time

import agversion
agversion.select(3)
from AccessGrid import Toolkit

from AccessGrid.Descriptions import Capability
from AccessGrid.AGService import AGService
from AccessGrid.AGParameter import OptionSetParameter

class JMastProducerService( AGService ):
   
    encodings = [ "jpeg/rtp" ]
    quality = [ "Highest", "High", "Medium", "Low", "Lowest" ]
    size = [ "None", "800x600", "600x400", "640x480", "480x300", "300x200" ]

    def __init__( self ):
        AGService.__init__( self )

        self.capabilities = [ Capability(Capability.PRODUCER,
                                         "JMAST",
                                          "JPEG/RTP",
                                          100000,
                                          self.id) ]
       
        self.executable = os.path.join(os.getcwd(), "JMastProducer.exe")

        # Set configuration parameters
        self.encoding = OptionSetParameter("Stream Encoding", 
"jpeg/rtp", JMastProducerService.encodings)
        self.quality = OptionSetParameter("Stream Quality", "Medium", 
JMastProducerService.quality)
        self.size = OptionSetParameter("Max. Window Size", "None", 
JMastProducerService.size)

        self.configuration.append(self.encoding)
        self.configuration.append(self.quality)
        self.configuration.append(self.size)

        self.profile = None

    def Start(self):
       
        self.log.debug("JMastProducerService.Start: Starting Service")
       
        try:
            options = []

            if self.enabled:
                self.log.debug('self.streamDescription: %s', 
self.streamDescription)
                options.append("-streamName")
                options.append(self.streamDescription.name)
                options.append("-streamType")
                options.append(self.streamDescription.location.type)
                options.append("-streamAddr")
                options.append(self.streamDescription.location.host)
                options.append("-streamPort")
                options.append(self.streamDescription.location.port)
                options.append("-streamTTL")
                options.append(self.streamDescription.location.ttl)
                options.append("-optionEncoding")
                options.append(self.encoding.value)
                options.append("-optionQuality")
                options.append(self.quality.value)
                options.append("-optionSize")
                options.append(self.size.value)
               
            self.log.debug(" executable = %s" % self.executable)
            self.log.debug(" options = %s" % options)
       
            self._Start(options)
   
        except:
            self.log.exception("Exception in JMastProducerService.Start")
            raise Exception("Failed to start service")
   
    def Stop(self):
       
        self.log.debug("JMastProducerService.Stop: Stopping Service")
        jmastKill = os.path.join(os.getcwd(), "KillProducer.exe")
        self.processManager.StartProcess(jmastKill, [])
        time.sleep(0.2)
        AGService.ForceStop(self)
   
    def SetStream(self, streamDescription):
   
        self.log.debug('JMastProducerService.SetStream: %s', 
streamDescription)
        self.log.debug('  enabled: %d', self.enabled)
   
        ret = AGService.ConfigureStream(self, streamDescription)
        if ret and self.started:
            # service is already running with this config; ignore
            return
   
        # if started, stop
        if self.started:
            self.Stop()
   
        # if enabled, start
        if self.enabled:
            self.Start()
       
    def SetIdentity(self, profile):
       
        self.log.debug("JMastProducerService.SetIdentity: %s %s", 
profile.name, profile.email)
        self.profile = profile
                  
if __name__ == "__main__":

    from AccessGrid.interfaces.AGService_interface import AGService as 
AGServiceI
    from AccessGrid.AGService import RunService

    service = JMastProducerService()
    serviceI = AGServiceI(service)
    RunService(service, serviceI)
 

#-----------------------------------------------------------------------------
# Name:        JMastConsumerService.py
# Author:      IMB
# Created:     2007/01/01
# Copyright:   (c) 2007
# Licence:     See LICENSE.TXT
#-----------------------------------------------------------------------------
import os
import time

import agversion
agversion.select(3)
from AccessGrid import Toolkit

from AccessGrid.Descriptions import Capability
from AccessGrid.AGService import AGService
from AccessGrid.AGParameter import OptionSetParameter

class JMastConsumerService( AGService ):

    def __init__( self ):
        AGService.__init__( self )

        self.capabilities = [ Capability(Capability.CONSUMER,
                                          "JMAST",
                                          "JPEG/RTP",
                                          100000,
                                          self.id) ]
       
        self.executable = os.path.join(os.getcwd(), "JMastConsumer.exe")
        self.profile = None

    def Start(self):
       
        self.log.debug("JMastConsumer.Start: Starting Service")
       
        try:
            options = []

            if self.enabled:
                self.log.debug('self.streamDescription: %s', 
self.streamDescription)
                options.append("-streamName")
                options.append(self.streamDescription.name)
                options.append("-streamType")
                options.append(self.streamDescription.location.type)
                options.append("-streamAddr")
                options.append(self.streamDescription.location.host)
                options.append("-streamPort")
                options.append(self.streamDescription.location.port)
                options.append("-streamTTL")
                options.append(self.streamDescription.location.ttl)
               
            self.log.debug(" executable = %s" % self.executable)
            self.log.debug(" options = %s" % options)
       
            self._Start(options)
   
        except:
            self.log.exception("Exception in JMastConsumerService.Start")
            raise Exception("Failed to start service")
   
    def Stop(self):
       
        self.log.debug("JMastConsumerService.Stop: Stopping Service")
        jmastKill = os.path.join(os.getcwd(), "KillConsumer.exe")
        self.processManager.StartProcess(jmastKill, [])
        time.sleep(0.2)
        AGService.ForceStop(self)
   
    def SetStream(self, streamDescription):
   
        self.log.debug('JMastConsumerService.SetStream: %s', 
streamDescription)
        self.log.debug('  enabled: %d', self.enabled)
   
        ret = AGService.ConfigureStream(self, streamDescription)
        if ret and self.started:
            # service is already running with this config; ignore
            return
   
        # if started, stop
        if self.started:
            self.Stop()
   
        # if enabled, start
        if self.enabled:
            self.Start()
       
    def SetIdentity(self, profile):
       
        self.log.debug("JMastConsumerService.SetIdentity: %s %s", 
profile.name, profile.email)
        self.profile = profile
                  
if __name__ == "__main__":

    from AccessGrid.interfaces.AGService_interface import AGService as 
AGServiceI
    from AccessGrid.AGService import RunService

    service = JMastConsumerService()
    serviceI = AGServiceI(service)
    RunService(service, serviceI)



[ServiceDescription]
name = JMastProducerService
description = JMast Multicast Application Sharing Tool Producer
capabilities = Capability1
executable = JMastProducerService.py
platform = neutral
version = 0.1

[Capability1]
role = producer
type = JMAST

[ServiceDescription]
name = JMastConsumerService
description = JMast Multicast Application Sharing Tool Consumer
capabilities = Capability1
executable = JMastConsumerService.py
platform = neutral
version = 0.1

[Capability1]
role = consumer
type = JMAST




More information about the ag-tech mailing list