29
A Quick CCM Example

A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Embed Size (px)

Citation preview

Page 1: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

A Quick CCM Example

Page 2: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Introduction A Simple Sender&Receiver Scenario

local_message

Sender

click_out

push_message Recei ver

click_inread_message

•Sender sends out the click-out event to inform the Receiver.

•Receiver reads the message from Sender.

•Multiple instances of the Receiver could be deployed.

• $CIAO_ROOT/examples/Hello

• $CIAO_ROOT/examples/Hello/step-by-step.html

local_message

Sender

click_out

push_message

Recei ver1

click_inread_message

Recei ver2

click_inread_message

Page 3: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Steps To Develop A CIAO Based Application1. Define your IDL

types.

2. Define your Component types.

3. Implement your components.

4. Assemble your components.

5. Deploy and run your application.

Page 4: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

A Quick CCM Example Define IDL/Component

Types

Page 5: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Common IDLmodule Hello

{

interface message

{

string get_message();

};

eventtype timeout { };

};

•Common IDL definition.

•Used by both Sender and Receiver.

•$CIAO_ROO/examples/Hello/Hello_Base/Hello_Base.idl

•This file could be skipped if not necessary.

Page 6: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Component Definition (IDL) – Receiver 1/3

Recei ver

click_inread_message

//Receiver.idl

component Receiver {

uses message read_message;

consumes timeout click_in;

};

home ReceiverHome manages Receiver{};

• Define the event receptacle.

Page 7: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Component Definition (IDL) – Receiver 2/3

Recei ver

click_inread_message

//Receiver.idl

component Receiver {

uses message read_message;

consumes timeout click_in;

};

home ReceiverHome manages Receiver{};

• Define the interface receptacle.

Page 8: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Component Definition (IDL) – Receiver 3/3

//Receiver.idl

component Receiver {

uses message read_message;

consumes timeout click_in;

};

home ReceiverHome manages Receiver{};

• Define the component home

Recei ver

click_inread_message

Recei verHome

Page 9: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Component Definition (IDL) – Sender 1/5

//Sender.idl

interface trigger

{ void start (); };

component Sender supports trigger

{ provides message push_message;

publishes timeout click_out;

attribute string local_message;};

home SenderHome manages Sender {};

• Define the event source.

local_message

Sender

click_out

push_message

Page 10: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

• Define the interface facet.

• The interface facet is plugged into the component in the way of composition.

//Sender.idl

interface trigger

{ void start (); };

component Sender supports trigger

{ provides message push_message;

publishes timeout click_out;

attribute string local_message;};

home SenderHome manages Sender {};

local_message

Sender

click_out

push_message

Component Definition (IDL) – Sender 2/5

Page 11: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

• Define the attribute.

//Sender.idl

interface trigger

{ void start (); };

component Sender supports trigger

{ provides message push_message;

publishes timeout click_out;

attribute string local_message;};

home SenderHome manages Sender {};

local_message

Sender

click_out

push_message

Component Definition (IDL) – Sender 3/5

Page 12: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

• Sender specific interface.

//Sender.idl

interface trigger

{ void start (); };

component Sender supports trigger

{ provides message push_message;

publishes timeout click_out;

attribute string local_message;};

home SenderHome manages Sender {};

local_message

Sender

click_out

push_message

Component Definition (IDL) – Sender 4/5

• Supported interface which is part of the component (inheritance).

Page 13: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

• Define the component home.

//Sender.idl

interface trigger

{ void start (); };

component Sender supports trigger

{ provides message push_message;

publishes timeout click_out;

attribute string local_message;};

home SenderHome manages Sender {};

Component Definition (IDL) – Sender 5/5SenderHome

local_message

Sender

click_out

push_message

Page 14: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

A Quick CCM Example

Component Implementations

Page 15: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

What does CIDL do? 1/2 CIDL is part of CCM strategy for

managing complex applications

• Helps separation of concerns

• Helps coordination of tools

• Increases the ratio of generated to hand-written code

• Server code is now generated, startup automated by other CCM tools

Stub

Impl

Skel

IDL Compiler

IDL

CIDL

CIDL Compiler

Executor IDL

Servants

Executors

IDL Compiler

XMLComponentDescriptors

uses

Page 16: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

• A CIDL file is Passed to CIDL compiler

• Triggers code generation for– Component Home (SenderHome)– managed component (Senderer)

• CIDL compiler generates–SenderHome servant–Senderer servant

• attribute operations• port operations• supported interface operations• container callback operations• navigation operation overrides

– IDL executor mapping– XML descriptor with meta-data

Generated by CIDL compiler(For both the Component and the Home)

Servant ImplementationExecutor Interface

//Sender.cidlcomposition session Sender_Impl{ home executor SenderHome_Exec { implements Hello::SenderHome; manages Sender_Exec; };};

Executor Implementation

User writes

Forward Request

Imp

lem

en

ts

What does CIDL do? 2/2

Page 17: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Sender.cidl

SenderHome servant

Sender servant

SenderHome_Exec

Sender_Exec

Manages

// Sender.cidl

composition session Sender_Impl

{

home executor SenderHome_Exec

{implements SenderHome;

manages Sender_Exec; }

};

• An executor is where a component/home is implemented

–The component/home’s servant will forward a client’s business logic request on the component to its corresponding executor

• User should write the implementations (specified in the exacutor mapping IDL file) of:

–SenderHome_Exec

–Sender_Exec

Which are (In the example):

–class SenderHome_exec_i

–class Sender_exec_i

Page 18: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Executor Mapping 1/2 CIDL compiler generates the Executor

Mapping

• An IDL file consists of local interface definitions.

• IDL compiler will generate the stubs for these local interfaces.

Stub

Impl

Skel

IDL Compiler

IDL

CIDL

CIDL Compiler

Executor IDL

Servants

Executors

IDL Compiler

XMLComponentDescriptors

uses

Home servant

Component servant

Home_Exec

Component_Exec

ManagesDefines

Page 19: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Executor Mapping 2/2//Sender.cidl –snipped--

composition session Sender_Impl

{

home executor SenderHome_Exec

{

implements Hello::SenderHome;

manages Sender_Exec;

}; };

//SenderE.idl --snipped—

Module Sender_Impl

{

local interface Sender_Exec: …

Local interface SenderHome_Exec: …

};

CIDL Compiler

//SenderEC.h --snipped—

namespace Sender_Impl

{

class Sender_Exec: …

class SenderHome_Exec: …

};

IDL Compiler

Inheritance

//Sender_exec.h --snipped—

namespace Sender_Impl

{

class Sender_Exec_i: public virtual Sender_Exec …

class SenderHome_Exec_i: public virtual SenderHome_Exec …

};

User writes

Auto-generate

d

Page 20: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

A Quick CCM Example

Implementation in Detail

Page 21: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Implementation in Detail - Overview• Component Specific

context

• Interface connection– Facet– Receptacle

• Event connection– Event source– Event receptacle

• Attribute

• Component Entry point

Handles all connections/subscriptions

local_message

Sender

Page 22: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Initializing Component-specific Context• Component-specific context manages

connections & subscriptions

• Container passes component its context via either

– set_session_context()– set_entity_context()

Container

Servant

ComponentSpecificContext

CCMContext

MainComponent

Executor

ExecutorsExecutorsExecutors

POA

EnterpriseComponent

CCMContext

Container

Servant

ComponentSpecificContext

CCMContext

MainComponent

Executor

ExecutorsExecutorsExecutors

POA

EnterpriseComponent

CCMContext

class Sender_exec_i : public virtual Sender_Exec, public virtual CORBA::LocalObject{protected: Sender_Exec_Context_var context_;public: … void set_session_context (Components::SessionContext_ptr c) { this->context_ = Sender_Exec_Context::narrow (c); } …};

//SenderE.idl –snipped--

local interface Sender_Exec : Hello::CCM_Sender, Components::SessionComponent{ };

local_message

Sender

click_out

push_message

Page 23: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Implement the Provided Interface Facet 1/2

//Sender.idl –snipped--

component Sender supports trigger

{ provides message push_message; …};

//SenderE.idl --snipped—

Module Hello {

local interface CCM_message:message …

local interface CCM_Sender : …

{

Hello::CCM_message get_push_message();

}

};

//Hello_Base.idl –snipped--

Module Hello {

interface message { …}; …

}

local_message

Sender

click_out

push_message

//Sender_exec.h --snipped—

namespace Sender_Impl

{

class Sender_Exec_i: public virtual Sender_Exec …

{

public :

… get_push_message ()

{return

(new Message_Impl(…)); }

};

class Message_Impl : public virtual CCM_message …

{

//All operations in interface //message

};

};We use Message_Impl to implement interface message. In this example, we intend to plug the facet into the component. In C++ terminology, we use composition but not inheritance.

Page 24: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Implement the Provided Interface Facet 2/2

//Sender.idl –snipped--

component Sender supports trigger

{ provides message push_messagepush_message; …};

//SenderE.idl --snipped—

Module Hello {

local interface CCM_message:message …

local interface CCM_Sender : …

{

Hello::CCM_message get_push_messagepush_message();

} };

//Hello_Base.idl –snipped--

Module Hello {

interface message { …}; …

}

local_message

Sender

click_out

push_message

//Sender_exec.h --snipped—

namespace Sender_Impl

{

class Sender_Exec_i: public virtual Sender_Exec …

{

public :

… get_push_messagepush_message ()

{return

(new Message_Impl(…)); }

};

class Message_Impl : public virtual CCM_message …

{

//All operations in interface //message

}; };

We plug the interface facet into the component and implement the get_<facet-name> method, which will be called by D&C tools or client to get the object reference of the interface servant implementation. User is responsible for managing the lifecycle of the facet object.

Page 25: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Invocation on Interface Receptacle

Recei ver

click_inread_message

//Receiver.idl –snipped--

component Receiver

{

uses message read_messageread_message; …

};

//Hello_Base.idl –snipped--

Module Hello {

interface message {

String get_message ();

}; … };

//Receiver_exec.h/cpp --snipped—

namespace Receiver_Impl

{

class Receiver_Exec_i: public virtual Receiver_Exec …

{

public :

void push_click_in ()

{

Hello::message_var rev = this->context_->get_connection_read_messageread_message();

CORBA::String_var str = rev->get_message();

} };}; •Component specific context manages the receptacle connections.

•Component executor implementation acquires the connected reference by calling:

•get_connection_<receptacle-name>. Then you can invoke opertaions supported by the interface on the OBJ reference.

Get the Obj-Ref

Operation invocation

Page 26: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Send out an Event

local_message

Sender

click_out

push_message

//Sender.idl –snipped--

Component Sender.idl

{ publishes timeout click_outclick_out; … };

//Hello_Base.idl –snipped--

Module Hello {

eventtype timeout { …}; …

}

//Sender_exec.h/cpp --snipped—

namespace Sender_Impl

{

class Sender_Exec_i: public virtual Sender_Exec …

{

public :

void start ()

{

this->context_->

push_click_outclick_out();

}

};};

•Component specific context manages the event source.

• push_<eventsource-name> sends out a event.

//SenderE.idl --snipped—

module Hello {

local interface CCM_Sender_Contex : …{

void push_click_outclick_out();

} };

module Sender_Impl {

typedef Hello::CCM_Sender_Contex Sender_Exec_Contex; };

Page 27: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Upon Receiving an Event

Recei ver

click_inread_message

//Receiver.idl –snipped--

component Receiver {

consuems timeout click_inclick_in;

… };

//Hello_Base.idl –snipped--

Module Hello {

eventtype timeout {}; …

};

//Receiver_exec.h --snipped—

namespace Receiver_Impl

{

class Receiver_Exec_i: public virtual Receiver_Exec …

{

public :

void push_click_in ();

};

};

•CIDL generates event consumer servants•Executor mapping defines push operations directly•push_<eventsink-name> will be called upon receiving an event.

//ReceiverE.idl --snipped—

module Hello {

local interface CCM_Receiver : …{

void push_click_inclick_in();

} };

module Sender_Impl {

Hello::CCM_Receiver_Exec : CCM_Receiver {}; };

Page 28: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Attribute Implementation//Sender.idl –snipped--

component Sender {

attribute string local_messagelocal_message;

… };

//Sender_exec.h --snipped—

namespace Sender_Impl

{

class Sender_Exec_i: public virtual Sender_Exec …

{

public :

void local_message (const char* );

char * local_message ();

}; };

•Intended for component configuration

•User need to implement the Accessor and Mutator methods.

//SenderE.idl --snipped—

module Hello {

local interface CCM_Sender : …{

attribute string local_message;

} };

module Sender_Impl {

Hello::CCM_Receiver_Exec : CCM_Receiver {}; };

local_message

Sender

Page 29: A Quick CCM Example. Tutorial on CCM Introduction A Simple Sender&Receiver Scenario Sender sends out the click-out event to inform the Receiver. Receiver

Tutorial on CCM

Component Entry Pointextern "C" {

Components::HomeExecutorBase_ptrcreatSenderHome_Impl (void) { return new Sender_Impl::SenderHome_exec_i();} }

• The signature is defined by the CCM spec

• Container calls this method to create a home executor

• extern “C” required to prevent C++ name mangling, so function name can be resolved in DLL

• XML tag reserved for entry point name

AssemblyServerActivator

ComponentServer

Container

CCMHome

«instantiates»

«instantiates»

«instantiates»

...createSenderHome_Impl ()