You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Introduction

The most common use of communication in ACS is the use of synchronous calls, however there are different reasons why someone could be interested in a different kind of calls. For this, CORBA provides the definition of 'oneway' methods, which basically are dispatched and no response is expected by the client. ACS increases this functionality by adding callbacks functionality to the 'oneway' mechanism offered by CORBA (If the developer desires). These callbacks are based on the off-shoot and callback interfaces and are a CORBA object on their own, although they don't represent an ACS component, they can be interacted in a very similar fashion, except for the lifecycle, which is tied to the process creating it.

OffShoot is a base interface used to identify CORBA objects created by components, clients, or other processes, and whose lifecycle is limited to the that of the component or process who created it.

A callback is the technical mechanism underlying the concepts of asynchronous notification. It is an object passed by the client to the server, so that the server can later invoke methods on the callback and thus inform the client of a change in status, completion of some operation, and the like. During this notification the roles of the client and the server are reversed. Every callback must be subclassed from the Callback interface.

ACS provides some Callbacks for basic types:

  • 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

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

Implementation

AsyncImpl.h
#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 cb, ACS::CBDescIn desc);
};
#endif


ACS::Time timestamp;
completion = ACSErrTypeOK::ACSErrOKCompletion();
completion = ACSErrTypeCommon::CouldntPerformActionCompletion(error_p, __FILE__, __LINE__, "::Door::closeAction");
AsyncImpl.h
#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;


    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

<e Name="ASYNC"
   Code="asyncImpl"
   Type="IDL:alma/workshop/Async:1.0"
   Container="bilboContainer"
   ImplLang="cpp"
   KeepAliveTime="0"
/>

Python

import ACS
import time


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


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


cb = CBuLong()
cbObj = client.activateOffShoot(cb)
desc = 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()

Java

package ...;


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 unsigned long value;
        public String status;
        public MyTestCBvoid(Logger logger) {
            status = "INIT";
            this.value = 0;
        }
        public void working(unsigned long value, Completion completion, CBDescOut desc) {
            status = "WORKING";
            this.value = value;
        }
        public void done(unsigned 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() {
        String managerLoc = System.getProperty("ACS.manager");
        super(null, managerLoc, clientName);
        m_logger = getContainerServices().getLogger()
    }


    public doStuff() {
        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_logger.info(cb.status);
        comp.delayResult(8, cbObj, desc);

        m_logger.info(cb.status);
        Thread.sleep(5000);
        m_logger.info(cb.status);
        Thread.sleep(5000);

        m_logger.info(cb.status);
        m_logger.info(cb.value);
    }


    public static void main(String[] args) {
        AsyncClient client = new AsyncClient();
        client.doStuff();


    }
}

C++


Discussion

  • Improvements / Suggestions
  • No labels