Versions Compared

Key

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

...

  • CBvoid
  • CBdouble(Seq)
  • CBfloat(Seq)
  • CBstring(Seq)
  • CBlong(Seq)
  • CBuLong(Seq)
  • CBboolean(Seq)
  • CBlongLong
  • CBuLongLong

Presentation

  • Scope
    • Simple oneway calls
    • Offshoot/Callback Architecture
  • Duration: 10 minutes

Hands-On Exercise

Component IDL

Code Block
languagecpp
titleAsync.idl
linenumberstrue
collapsetrue
#ifndef _ASYNC_IDL_
#define _ASYNC_IDL_

#pragma prefix "alma"

#include <acscommon.idl>
#include <acscomponent.idl>
 
module workshop 
{
    interface Async : ACS::ACSComponent {
        oneway void delayResult(in ACS::uLong delay, in ACS::CBuLong cb, in ACS::CBDescIn desc);
    };
};
#endif

...

Code Block
languagecpp
titleAsyncImpl.h
linenumberstrue
collapsetrue
#ifndef _ASYNC_IMPL_H
#define _ASYNC_IMPL_H
 
#include <acscomponentImpl.h>
#include <AsyncS.h>
 
class AsyncImpl : public virtual acscomponent::ACSComponentImpl, public virtual POA_workshop::Async
{
  public:
    AsyncImpl(const ACE_CString& name, maci::ContainerServices* containerServices);
    virtual ~AsyncImpl();
    void delayResult(ACS::uLong delay, ACS::CBuLong_ptr cb, const ACS::CBDescIn& desc);
};
#endif
Code Block
languagecpp
titleAsyncImpl.cpp
linenumberstrue
collapsetrue
#include <AsyncImpl.h>
#include <ACSErrTypeOK.h>

ACSAsyncImpl::Time timestamp;
completion = ACSErrTypeOK::ACSErrOKCompletion();
completion = ACSErrTypeCommon::CouldntPerformActionCompletion(error_p, __FILE__, __LINE__, "::Door::closeAction");
Code Block
languagecpp
titleAsyncImpl.cpp
linenumberstrue
collapsetrue
#include <AsyncImpl.h>
 
AsyncImpl::AsyncImpl(const ACE_CString& name, maci::ContainerServices* containerServices) : acscomponent::ACSComponentImpl(name, containerServices) {
}

AsyncImpl::~AsyncImpl() {
}

void AsyncImpl::delayResult(ACS::uLong delay, ACS::CBuLong cb, ACS::CBDescIn desc) {
    ACSErr::Completion completion; 
    ACS::CBDescOut descOut;


AsyncImpl(const ACE_CString& name, maci::ContainerServices* containerServices) : acscomponent::ACSComponentImpl(name, containerServices) {
}

AsyncImpl::~AsyncImpl() {
}

void AsyncImpl::delayResult(ACS::uLong delay, ACS::CBuLong_ptr cb, const ACS::CBDescIn& desc) {
    ACSErr::Completion completion;
    ACS::CBDescOut descOut;

    completion = ACSErrTypeOK::ACSErrOKCompletion();
    cb->working(0, completion, descOut);
    sleep(delay);
    cb->done(delay, completion, descOut);
}


/* --------------- [ MACI DLL support functions ] -----------------*/
#include <maciACSComponentDefines.h>
MACI_DLL_SUPPORT_FUNCTIONS(AsyncImpl)
/* ----------------------------------------------------------------*/

Configuration

Code Block
titleComponents.xml
linenumberstrue
collapsetrue
<e Name="ASYNC"
   Code="asyncImplAsyncImpl"
   Type="IDL:alma/workshop/Async:1.0"
   Container="bilboContainer"
   ImplLang="cpp"
   KeepAliveTime="0"
/>

...

Code Block
languagepy
titleAsyncClient.py
linenumberstrue
collapsetrue
import ACS
import time

from Acspy.Common.Callbacks import CBuLongCBuLongLong
from Acspy.Clients.SimpleClient import PySimpleClient

client = PySimpleClient()
comp = client.getComponent('ASYNC')

cb = CBuLongCBuLongLong()
cbObj = client.activateOffShoot(cb)
desc = ACS.CBDescIn(0, 0, 0)

print(cb.status)
comp.delayResult(8, cbObj, desc)

print(cb.status)
time.sleep(5)
print(cb.status)
time.sleep(5)
print(cb.status)

print(cb.values)

client.releaseComponent(comp.name)
client.disconnect()

...

Code Block
languagejava
titleAsyncClient.java
linenumberstrue
collapsetrue
package workshop...async;
 
import java.util.logging.Logger;
 
import alma.acs.component.client.ComponentClient;
 
import alma.ACS.CBDescIn;
import alma.ACS.CBDescOut;
import alma.ACSErr.Completion;
 
import alma.workshop.Async;
import alma.workshop.AsyncHelper;
 
import alma.ACS.CBuLong;
import alma.ACS.CBuLongPOA;
 
public class AsyncClient extends ComponentClient {
    class CBuLongImpl extends CBuLongPOA
    {
        public unsignedint long value;
        public String status;
        public MyTestCBvoidCBuLongImpl(Logger logger) {
            status = "INIT";
            this.value = 0;
        }
        public void working(unsigned longint value, Completion completion, CBDescOut desc) {
            status = "WORKING";
            this.value = value;
        }
        public void done(unsignedint long value, Completion completion, CBDescOut desc) {
            status = "DONE";
            this.value = value;
        }
        public boolean negotiate(long timeToTransit, CBDescOut desc) {
            return true;
        }
    }
 
    private Logger m_logger;
 
    public AsyncClient() throws Exception {
        String managerLoc = super(null, System.getProperty("ACS.manager"), "AsyncClient");
        super(null, managerLoc, clientNamem_logger = getContainerServices().getLogger();
    }
 
    m_loggerpublic =void getContainerServicesdoStuff().getLogger() {
    }

    public doStuff()try {
            org.omg.CORBA.Object obj = getContainerServices().getComponent("ASYNC");
 
            Async comp = AsyncHelper.narrow(obj);
            CBuLongImpl cb = new CBuLongImpl(m_logger);
            CBuLong cbObj = alma.ACS.CBuLongHelper.narrow(getContainerServices().activateOffShoot(cb));
            CBDescIn desc = new CBDescIn();
 
        m    m_logger.info(String.valueOf(cb.status));
            comp.delayResult(8, cbObj, desc);
 
            m_logger.info(String.valueOf(cb.status));
            Thread.sleep(5000);
            m_logger.info(String.valueOf(cb.status));
            Thread.sleep(5000);
 
            m_logger.info(String.valueOf(cb.status));
            m_logger.info(String.valueOf(cb.value));
 

            getContainerServices().releaseComponent("ASYNC");
    }

    public static void main(String[] args} catch(Exception e) {
        AsyncClient client = new AsyncCliente.printStackTrace();
        client.doStuff();}
    }
}

C++

Code Block
languagecpp
titleAsyncClient.cpp
linenumberstrue
collapsetrue
#include <maciSimpleClient.h>
#include <AsyncC.h>
#include <ACSErrTypeCommon.h>
#include <acsutilTimeStamp.h>

using namespace maci;
class CBuLongImpl : public virtual POA_ACS::CBuLong {
  public:
    CBuLongImpl() {value = 0; status=std::string("INIT")}
 
    public static void main(String[] args) {
        try {
            AsyncClient client = new AsyncClient();
    virtual ~MyCBdouble() {}
    void working (CORBA::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &descclient.doStuff();
        } catch(Exception e) {
          status = std::string("WORKING" e.printStackTrace();
        this.value = value;}
    }
}

C++

Code Block
languagecpp
titleAsyncClient.cpp
linenumberstrue
collapsetrue
#include <maciSimpleClient.h>
#include <AsyncC.h>
#include <ACSErrTypeCommon.h>
#include <acsutilTimeStamp.h>
 
using namespace maci;
class CBuLongImpl : public virtual POA_ACS::CBuLong {
  public:    void done (CORBA::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &desc){
    CBuLongImpl() {value = 0; status = std::string("DONEINIT");}
    virtual ~CBuLongImpl() {}
  this.value = value;
void    }
    CORBA::Boolean negotiate (ACS::TimeInterval time_to_transmitworking (ACS::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &desc) {
        status    return true= std::string("WORKING");
    }
     CORBA::uLongthis->value = value;
    public std::string status;
};

int main(int argc, char *argv[]) }
    void done (ACS::uLong value, const ACSErr::Completion &c, const ACS::CBDescOut &desc){
    SimpleClient  client;
  status = workshopstd::Async_var comp;
string("DONE");
    if (client.init(argc,argv) == 0) {
        return -1 this->value = value;
    } else {
    CORBA::Boolean negotiate   client.login();
(ACS::TimeInterval time_to_transmit, const ACS::CBDescOut &desc) {
        }

    tryreturn {true;
    }
  public:
  comp = client.getComponent<workshopACS::Async>("ASYNC", 0, true)uLong value;
    std::string status;
};
 
int catch(maciErrType::CannotGetComponentExImpl& _exmain(int argc, char *argv[]) {
        _ex.log()SimpleClient client;
        return -1;workshop::Async_var comp;
 
    }


    CBuLongImpl cb();
if (client.init(argc,argv) == 0) {
      ACS::CBuLong_var cbObj = cb._this()return -1;
    ACS::CBDescIn desc;} else {
    desc.id_tag = 2;

    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    client.login();
    }
 
    try {
        comp.delayResult(8, cbObj.in(), desc = client.getComponent<workshop::Async>("ASYNC", 0, true);

    } ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
catch(maciErrType::CannotGetComponentExImpl& _ex) {
        Thread_ex.sleeplog(5000);
       ACS_SHORT_LOG((LM_INFO, "%s", cb.status)) return -1;
    Thread.sleep(5000);
}
 
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status))CBuLongImpl cb{};
    ACS_SHORT_LOG((LM_INFO, "%ul",::CBuLong_var cbObj = cb.value_this());


    try {ACS::CBDescIn desc;
    desc.id_tag    client.releaseComponent("ASYNC")= 2;
 
   } catch(maciErrType::CannotReleaseComponentExImpl &_ex) {
        _ex.log( ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    comp->delayResult(8,    return -1;
    }
cbObj.in(), desc);
 
    client.logout();

ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    ACE_OS::sleep(35);
    return 0;
}

...

 ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    sleep(5);
 
    ACS_SHORT_LOG((LM_INFO, "%s", cb.status));
    ACS_SHORT_LOG((LM_INFO, "%ul", cb.value));
 
    try {
        client.releaseComponent("ASYNC");
    } catch(maciErrType::CannotReleaseComponentExImpl &_ex) {
        _ex.log();
        return -1;
    }
 
    client.logout();
 
    ACE_OS::sleep(3);
    return 0;
}

Makefile

Code Block
titleMakefile
linenumberstrue
collapsetrue
#Component IDL
IDL_FILES_L = Async
AsyncStubs_LIBS = acscomponentStubs acscommonStubs

#C++ Component
LIBRARIES_L     = AsyncImpl
AsyncImpl_OBJECTS = AsyncImpl
AsyncImpl_LIBS = AsyncStubs acscomponent

#C++ Client
EXECUTABLES_L   = AsyncExample
AsyncExample_OBJECTS = AsyncClient
AsyncExample_LIBS = maciClient AsyncStubs

#Java Client
JARFILES_L = AsyncJar
AsyncJar_DIRS = workshop

#Python Client
PY_SCRIPTS_L       = AsyncClient


Discussion

  • Asynchronous calls and oneway operations
    • It's not mandatory to make use of oneway keyword, depends on the design
      • For instance, adding to a queue may return immediately with a boolean with success or failure status of adding the element to a queue and may still register a callback for when the element is executed and something needs to be done
  • Existing CBxxxx are used for monitoring, alarms and other internals of ACS, they're not meant for generic use. Your own callbacks can have the desired set of methods
  • Improvements / Suggestions