680 likes | 781 Views
Getting started with OpenCCM Tutorial. An OpenCCM application : The demo3 “ Client / Server-Producer / Consumer ”. Areski Flissi (IR CNRS / LIFL) flissi@lifl.fr. Tutorial Objectives. An OpenCCM application
E N D
Getting started with OpenCCMTutorial An OpenCCM application : The demo3 “Client / Server-Producer / Consumer” Areski Flissi (IR CNRS / LIFL) flissi@lifl.fr Getting started with OpenCCM
Tutorial Objectives • An OpenCCM application • How to design, build, implement, compile, deploy and execute an application according to the OMG CORBA Component Model with the OpenCCM platform • Illustrated with a concrete example : demo3 • A simple Client / Server-Producer / Consumer application • Build with OpenCCM 0.4 and ORBacus 4.1 and Java programming language Getting started with OpenCCM
Agenda 1. OMG IDL3 : design the application by defining components and assembling component instances 2. OpenCCM compilation and generation chain for the demo3 example 3. OpenCCM execution chain for the demo3 example 4. Package, assembly and deploy the CCM application with XML descriptors (edited using simple GUI) Getting started with OpenCCM
OMG IDL 2.x IDL3 Building a CCM application with OpenCCM is very easy... Java implementation patterns User written files demo3.idl3 Compiler Generated files ir3_feed ir3_jimpl User’s Java implementation file IR3 demo3.jar Compile and Build archive ir3_idl2 jidl Java Corba 2 stubs demo3.idl Packaging, Assembling and Deployment done by XML descriptors ir3_java GUI XML descriptors Java OpenCCM Skeletons Getting started with OpenCCM
Agenda 1.OMG IDL3 : design the application by defining components and assembling component instances 2. OpenCCM compilation and generation chain for the demo3 example 3. OpenCCM execution chain for the demo3 example 4. Package, assembly and deploy the CCM application with XML descriptors (edited using simple GUI) Getting started with OpenCCM
1. OMG IDL3 : design the application by defining components and assembling component instances • OMG IDL3 : defining demo3 module • Interfaces • Eventtypes • Components and interconnections between components (facets, receptacles, event sources, event sinks) • Component homes for instantiating and managing components Getting started with OpenCCM
The Client/Server-Producer/Consumer Example • Client components synchronously invoke a Server component which asynchronously publishes Events to the set of connected Consumer components. • Components are created by simple component homes or managers with primary keys Getting started with OpenCCM
Component Client Component Server Component Base ref. Consumer Component Facet Receptacle Event Sink Event Source Building the application : • Assembling CORBA Component instances Getting started with OpenCCM
OMG IDL 3.0 for demo3 example // Importation of the Components module // when access to OMG IDL definitions contained // into the CCM's Components module is required. import Components; moduledemo3 { // Sets the prefix of all these OMG IDL definitions. // Prefix generated Java mapping classes. typeprefixdemo3"ccm.objectweb.org"; . . . }; Getting started with OpenCCM
Defining a base component type // A base type for named component. componentNamedComponent { /** The identifier name property. */ attribute string name; }; // The primary key to identify components valuetypeNamePrimaryKey : ::Components::PrimaryKeyBase { /** Just a string name. */ public /*string*/ long name; }; Getting started with OpenCCM
The Service Interface and Event valuetype interfaceService { void display(in string text); }; // The Event valuetype published by the Server // component and consumed by its Consumer components eventtypeTextEvent { /** Just contains a string. */ public string text; }; Getting started with OpenCCM
Server Component The Server Component // The Server component type componentServer :NamedComponent { // Provides a Service to its Client components providesService the_service; // Publishes Events to its Consumer components publishesTextEvent to_consumers; }; // Simple home for instantiating Server component homeServerHomemanagesServer {}; Getting started with OpenCCM
ServerHome Server Component The Server Component // The Server component type componentServer : NamedComponent { // Provides a Service to its Client components providesService the_service; // Publishes Events to its Consumer components publishesTextEvent to_consumers; }; // Simple home for instantiating Server component homeServerHomemanagesServer {}; Getting started with OpenCCM
Server Component The Server Component ServerManager // The home for managing Server components homeServerManager manages Server primarykey NamePrimaryKey { // To create a new Server identified by the name factory create_server(in string name); // To find a Server identified by the name finder find_server(in string name); }; Getting started with OpenCCM
Client Component The Client Component // The Client component type componentClient :NamedComponent { // Uses the service provided by the Server component usesService the_service; }; // Simple home for instanciating Client components homeClientHome manages Client { }; // The home for managing Client components homeClientManager manages Client primarykey NamePrimaryKey { /** To create a new Client identified by the name. */ factory create_client(in string name); /** To find a Client identified by the name. */ finder find_client(in string name); }; Getting started with OpenCCM
ClientHome Client The Client Component // The Client component type componentClient :NamedComponent { // Uses the service provided by the Server component usesService the_service; }; // Simple home for instanciating Client components homeClientHome manages Client { }; // The home for managing Client components homeClientManager manages Client primarykey NamePrimaryKey { /** To create a new Client identified by the name. */ factory create_client(in string name); /** To find a Client identified by the name. */ finder find_client(in string name); }; Getting started with OpenCCM
Consumer The Consumer Component // The Consumer component type componentConsumer : NamedComponent { // Consumes Events published by Server components consumesTextEvent from_servers; }; // Simple home for instanciating Client components homeConsumerHome manages Consumer { }; // The home for managing Client components homeConsumerManager manages Consumer primarykey NamePrimaryKey { /** To create a new Consumer identified by the name. */ factory create_consumer(in string name); /** To find a Consumer identified by the name. */ finder find_consumer(in string name); }; Getting started with OpenCCM
ConsumerHome Consumer The Consumer Component // The Consumer component type componentConsumer : NamedComponent { // Consumes Events published by Server components consumesTextEvent from_servers; }; // Simple home for instanciating Client components homeConsumerHome manages Consumer { }; // The home for managing Client components homeConsumerManager manages Consumer primarykey NamePrimaryKey { /** To create a new Consumer identified by the name. */ factory create_consumer(in string name); /** To find a Consumer identified by the name. */ finder find_consumer(in string name); }; Getting started with OpenCCM
Consumer Consumer Client Client Client ConsumerHome ClientHome Consumer ServerHome Server Component Interconnections between CORBA component instances Getting started with OpenCCM
Agenda 1. OMG IDL3 : design the application by defining components and assembling component instances 2.OpenCCM compilation and generation chain for the demo3 example 3. OpenCCM execution chain for the demo3 example 4. Package, assembly and deploy the CCM application with XML descriptors (edited using simple GUI) Getting started with OpenCCM
2. OpenCCM compilation and generation chain for the demo3 example • Loading the OpenCCM environment • Start the OpenCCM's OMG IDL3 Repository (named IR3) • Checking the demo3.idl3 file • Feeding the demo3.idl3 file into the OpenCCM's IR3 • Generating equivalent OMG IDL 2.4 mapping for demo3 • Generating the Java OpenCCM skeletons for demo3 • Implementing the Client/Server–Producer/Consumer example • Compiling generated Java CORBA 2 stubs, generated Java OpenCCM skeletons, all Java implementation sources and building archive demo3.jar Getting started with OpenCCM
Loading the OpenCCM environment • Assuming OpenCCM is compiled and installed in C:\OpenCCM with ORBacus-4.1 under Windows NT : C:\OpenCCM>ORBacus-4.1\bin\envi_OpenCCM.bat To have access to all OpenCCM’s tools Getting started with OpenCCM
Start the OpenCCM's OMG IDL3 Repository C:\OpenCCM\demo\demo3>ir3_start • Start the OpenCCM’s IR3 • Feed the OpenCCM's IR3 with the IFR_3_0.idl file • Feed the OpenCCM's IR3 with the Components.idl file this script automatically creates the $OpenCCM_CONFIG_DIR directory Getting started with OpenCCM
Checking the demo3.idl3 file C:\OpenCCM\demo\demo3>idl3_check demo3.idl3 OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Reading from file demo3.idl3... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Preprocessing file demo3.idl3... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: File demo3.idl3 preprocessed OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Feeding the Interface Repository ... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Compilation completed: 0 warnings. • This script checks if if the specified OMG IDL 3.0 file “demo3.idl3” is correct Getting started with OpenCCM
Feeding the demo3.idl3 file into the OpenCCM's IR3 C:\OpenCCM\demo\demo3>ir3_feed demo3.idl3 OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Reading from file demo3.idl3... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Preprocessing file demo3.idl3... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: File demo3.idl3 preprocessed OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Feeding the Interface Repository ... OpenCCM's OMG IDL 3.0 Compiler 0.5.0: Compilation completed: 0 warnings. • The ir3_feed script allows to compile demo3.idl3 file and to feed the OpenCCM's IR3 (necessary to use any of the OpenCCM tools) Getting started with OpenCCM
Generating equivalent OMG IDL 2.4 mapping for the demo3 IR3 object • The ir3_idl2 script generates the OMG IDL 2.4 CCM's mapping associated to an OpenCCM's IR3 object (demo3.idl) : C:\OpenCCM\demo\demo3>ir3_idl2 demo3 • Add –o filename option to produce an output file and –i option to add the #include statement, ie : C:\OpenCCM\demo\demo3>ir3_idl2 -i Components.idl -o demo3.idl demo3 In this case, “-i Components.idl” produces the “#include Components.idl” statement in the demo3.idl file Getting started with OpenCCM
OMG IDL 3.0 Component Implementer Component Designer Component Client uses implemented by Client-side OMG IDL 2.x Local server-side OMG IDL 2.x OMG IDL 3.0 Compiler Component Executor Client Application implemented by delegates to User written Client Stub Component Skeleton Compiler ORB Generated files Client-side and Server-sideOMG IDL Mappings Getting started with OpenCCM
Client-Side OMG IDL Mapping rules • A component type is mapped to an interface inheriting from Components::CCMObject • Facets and event sinks are mapped to an operation for obtaining the associated reference • Receptacles are mapped to operations for connecting, disconnecting, and getting the associated reference(s) • Event sources are mapped to operations for subscribing and unsubscribing to produced events Getting started with OpenCCM
Client-Side OMG IDL Mapping rules • An event type is mapped to • A value type • inheriting from Components::EventBase • A consumer interface • inheriting from Components::EventConsumerBase • A home type is mapped to three interfaces • One for explicit operations user-defined • inheriting from Components::CCMHome • One for implicit operations generated • One inheriting from both previous interfaces Getting started with OpenCCM
Client-Side OMG IDL Mapping rules • TextEvent eventtype is mapped to : eventtypeTextEvent { /** Just contains a string. */ public string text; }; valuetypeTextEvent : ::Components::EventBase { public string text; }; interface TextEventConsumer : ::Components::EventConsumerBase { void push_TextEvent(in ::demo3::TextEvent the_textevent); }; Is mapped to Getting started with OpenCCM
Server Component Client-Side OMG IDL Mapping rules • Server Component componentServer :NamedComponent { providesService the_service; publishesTextEvent to_consumers; }; interfaceServer : ::demo3::NamedComponent { ::demo3::Service provide_the_service(); ::Components::Cookie subscribe_to_consumers(in ::demo3::TextEventConsumer consumer); ::demo3::TextEventConsumer unsubscribe_to_consumers(in ::Components::Cookie ck); }; Is mapped to Getting started with OpenCCM
ServerHome Server Component Client-Side OMG IDL Mapping rules • home ServerHome homeServerHome manages Server {}; interface ServerHomeExplicit : ::Components::CCMHome { }; interface ServerHomeImplicit : ::Components::KeylessCCMHome { ::demo3::Server create(); }; interface ServerHome : ::demo3::ServerHomeExplicit, ::demo3::ServerHomeImplicit { }; Is mapped to Getting started with OpenCCM
ServerManager Server Component Client-Side OMG IDL Mapping rules • home ServerManager homeServerManager manages Server primarykey NamePrimaryKey { factory create_server(in string name); finder find_server(in string name); }; Is mapped to Getting started with OpenCCM
Client-Side OMG IDL Mapping rules Is mapped to • home ServerManager interface ServerManagerExplicit : ::Components::CCMHome { ::demo3::Server create_server(in string name); ::demo3::Server find_server(in string name); }; interface ServerManagerImplicit { ::demo3::Server create(in ::demo3::NamePrimaryKey key); ::demo3::Server find_by_primary_key(in ::demo3::NamePrimaryKey key); void remove(in ::demo3::NamePrimaryKey key); ::demo3::NamePrimaryKey get_primary_key(in ::demo3::Server comp); }; interface ServerManager : ::demo3::ServerManagerExplicit, ::demo3::ServerManagerImplicit { }; Getting started with OpenCCM
Client Component Client-Side OMG IDL Mapping rules • Client Component componentClient :NamedComponent { usesService the_service; }; interfaceClient : ::demo3::NamedComponent { void connect_the_service(in ::demo3::Service connexion); ::demo3::Service disconnect_the_service(); ::demo3::Service get_connection_the_service(); }; Is mapped to Getting started with OpenCCM
Consumer Client-Side OMG IDL Mapping rules • Consumer Component componentConsumer: NamedComponent { consumesTextEvent from_servers; }; interfaceConsumer : ::demo3::NamedComponent { ::demo3::TextEventConsumer get_consumer_from_servers(); }; Is mapped to Getting started with OpenCCM
Server-Side OMG IDL Mapping rules • A component type is mapped to three local interfaces • The main component executor interface • Inheriting from Components::EnterpriseComponent • The monolithic component executor interface • Operations to obtain facet executors and receive events • The component specific context interface • Operations to access component receptacles and event sources • A home type is mapped to three local interfaces • One for explicit operations user-defined • Inheriting from Components::HomeExecutorBase • One for implicit operations generated • One inheriting from both previous interfaces Getting started with OpenCCM
NamedComponent name = xxx Server-Side OMG IDL Mapping rules : NamedComponent // Main component executor interface local interface CCM_NamedComponent_Executor : ::Components::EnterpriseComponent { attribute string name; }; // Monolithic component executor interface local interface CCM_NamedComponent : ::demo3::CCM_NamedComponent_Executor { // no operations to obtain facet executors and receive events }; // Component-specific context interface. local interface CCM_NamedComponent_Context : ::Components::CCMContext { // no operations to access component receptacles and event sources }; Getting started with OpenCCM
Server Component Server-Side OMG IDL Mapping rules : Server Component // Main component executor interface local interface CCM_Server_Executor : ::demo3::CCM_NamedComponent_Executor { }; // Monolithic component executor interface local interface CCM_Server : ::demo3::CCM_Server_Executor { ::demo3::CCM_Service get_the_service(); }; // Component-specific context interface. local interface CCM_Server_Context : ::demo3::CCM_NamedComponent_Context { void push_to_consumers(in ::demo3::TextEvent event); }; Getting started with OpenCCM
Server Server Component CCM_Server SessionComponent Monolithic executor Service CCM_Service CCM_Server_Context SessionContext Server-Side OMG IDL Mapping rules : Server Component Getting started with OpenCCM
Client Component Server-Side OMG IDL Mapping rules : Client Component // Main component executor interface local interface CCM_Client_Executor : ::demo3::CCM_NamedComponent_Executor { }; // Monolithic component executor interface local interface CCM_Client : ::demo3::CCM_Client_Executor { }; // Component-specific context interface. local interface CCM_Client_Context : ::demo3::CCM_NamedComponent_Context { ::demo3::Service get_connection_the_service(); }; Getting started with OpenCCM
Client Client Component CCM_Client SessionComponent Monolithic executor CCM_Client_Context SessionContext Server-Side OMG IDL Mapping rules : Client Component Getting started with OpenCCM
Consumer Server-Side OMG IDL Mapping rules : Consumer Component local interface CCM_TextEventConsumer { void push(in ::demo3::TextEvent event); }; // Main component executor interface local interface CCM_Consumer_Executor : ::demo3::CCM_NamedComponent_Executor { }; // Monolithic component executor interface local interface CCM_Consumer : ::demo3::CCM_Consumer_Executor { void push_from_servers(in ::demo3::TextEvent event); };// Component-specific context interface. local interface CCM_Consumer_Context : ::demo3::CCM_NamedComponent_Context { }; Getting started with OpenCCM
Consumer Consumer CCM_Consumer SessionComponent Monolithic Executor CCM_TextEventConsumer CCM_Consumer_Context TextEventConsumer SessionContext Server-Side OMG IDL Mapping rules : Consumer Component Getting started with OpenCCM
Generating the Java OpenCCM skeletonsassociated to demo3 • The script id3_java.bat allows to generate skeletons C:\OpenCCM\demo\demo3>ir3_java ::demo3 • Files generated : Getting started with OpenCCM
Generating the Java OpenCCM skeletonsassociated to demo3 Getting started with OpenCCM
Generating Java CORBA 2 stubs • Using jidl compiler for ORBacus-4.1, --tie option allows to generate tie classes, -I option to include idl files, this generate stubs for demo3 in demo3\generated\stubs directory. C:\OpenCCM\demo\demo3>jidl --auto-package --tie -I. -I../../ORBacus-4.1/idl --output-dir generated/stubs demo3.idl Getting started with OpenCCM
Implementing the Client/Server –Producer/Consumer OpenCCM example • Now we have to implement this example by writing Java implementation files • Only functional parts of the application have to be implemented Files to write : Getting started with OpenCCM
Implementing the Client/Server –Producer/Consumer OpenCCM example • Demo3.java is the bootstrap of the application, here we have to • Initialise the ORB, obtain the Name Service • Obtain component servers ComponentServer1 and ComponentServer2 • Obtain the container homes • Instantiate a container on each server • Install homes for Client, Server and Consumer • Create components with create() method of homes : here we have three clients, three consumers and one server-producer • Configure components • Connect each client and consumer to server • Call the configuration_complete() method of components implementation Getting started with OpenCCM
Client Component Server Component Consumer Component Implementing the Client/Server –Producer/Consumer OpenCCM example Demo3.java Connect each client and consumer to server .... Service the_service = s.provide_the_service(); c1.connect_the_service(the_service); c2.connect_the_service(the_service); c3.connect_the_service(the_service); s.subscribe_to_consumers(cs1.get_consumer_from_servers()); s.subscribe_to_consumers(cs2.get_consumer_from_servers()); s.subscribe_to_consumers(cs3.get_consumer_from_servers()); .... Getting started with OpenCCM