Title: OpenCOM V2: Theory
1OpenCOM V2 Theory Practice
2Overview of the talk
- V2 Concepts in General
- Applying V2 principles
- OpenCOMLinux
- Case Study Microcode C
- OpenCOMv2Java
- Exploring the kernel API in detail
- Case Study Java C
3Motivation for Version 2
- Support component deployment in a wide range of
environments - OpenCOM v1 is platform specific
- Negligible Overheads
- E.g. Small (15k), simple runtime
- Fine-grained, language independent and
format-independent components - A Configurable Reconfigurable Component runtime
4OpenCOM v2 Overall Architecture
Generic support for reconfiguration inspect,
adapt and extend at runtime
Minimal kernel Loads and binds
Caplets, loaders and binders
Component run-time kernel
5CRTK API
- template load(comp_type name)
- Loads component template into the runtime
- comp_inst instantiate(template t, opaque arg)
- Create component instance from template
- status unload(template t)
- Remove loaded template
- status destroy(comp_inst comp)
- Delete a component instance
- ipnt_inst getinteractionpoint(comp_ist, kind,
ipnt_type) - Obtain Intf or Recp identifier from a component
- comp_inst bind(ipnt_inst, ipnt_inst receptacle)
- Bind together specified interface receptacle
binding is a component that can be destroyed
(unbind)
6OpenCOM v2 concepts
- Capsule
- Unit of scope that offers the kernel API
- Caplets
- Sub-scopes within capsule
- Loaders
- Provide various ways of loading component into
various types of caplet - Binders
- Various ways of binding components both within
and across different caplet
7Overview of Capsules, Loaders Binders
8Extensions Layer
9Extension Layer API
- template load(comp_type name, comp_inst loader,
comp_inst caplet) - Loads using specified Loader Caplet
- comp_inst bind(ipnt_inst interface, ipnt_inst
receptacle, comp_inst binder) - Bind using specified binder
- comp_inst extend(extension_type ext_type,
comp_type extension, opaque arg) - Load extension component using CRTK loader
- status setdefaultextension(extension_type
ext_type, comp_inst extension) - Set a default loader, binder or caplet
10CRTK reflect operation
- Used by components implementing meta-models or
architecture management - Register for callbacks from run-time
- Provides information about requests of the
run-time - Loads, binds, etc
- Two-phase
- 1st callback -gt whats about to happen
- Veto
- 2nd callback -gthappened
- Update meta-data
- Plugable Meta-models
- Add components begin to reify information about
components - Further research into application to
architecture, interface and interception required
CRTK
Reflect(Callback cb)
Register Callback Interface
11CRTK putmeta, getmeta
- status putmeta(ID entity, string key, opaque
value) - opaque getmeta(ID entity, string key)
- Add meta-data about any component model element
to an internal CRTK registry - Separate meta models?
- Attach to elements in meta-architecture
interface - Plugable registry?
12OpenCOMLinux CRTK
- Implements the API to load and bind components
- Coded in C
- OSPL - Operating System Portable Layer is a
subset of NSPR (e.g. can be easily ported to
Windows) - Components are stored in a Shared Object file
(.so) - Provides dynamic linking
13OpenCOMLinux CRTK Load/Bind
- Loading a component
- Pass the component type and get the componentID
- Load(componentType, componentID)
- Instantiating a component
- Pass the loaded componentID and returns the
pointer to the component instance - Instantiate(componentID, intf, intfID, instID)
- Binding components
- Pass the interfaceID and receptacleID
- Bind(intfID, receptID, connID)
14Cross Caplet Binder
15Case Study C Microcode Scenario
Microcode - C Binding
Microcode
C
16- A Case Study Java and C Component Integration
on Win32 Desktops and CE 3.0 Pocket PCs
17GRIDKit Heterogeneity Problem
ICalculate int Add(int x, int y) int Sub(int x,
int y)
Java Runtime
Java Calculator Component
Java Calculator Component
ISub int Sub(int x, int y)
IAdd int Add(int x, int y)
Java Subtract Component
Java Random Number Component
Java Subtract Component
C Adder Component
C Runtime
C Adder Component
IRandomNumber int GetRandomNumber(int t)
Java Random Number Component
18Theory versus Practice
Reflective Meta Models
CRTK API
IOpenCOM
CRTK
OpenCOMJ Component runtime
Windows Operating System (Win32 or CE 3.0)
deployment environment (hardware and/or software)
19Component Run-time Kernel
- Define What is your base CRTK?
- Base component-runtime
- Load components
- Bind components
- Many possibilities
- OpenCOMJ, OpenCOMWin32, OpenCOMLinux, COM, EJB,
CCM, - The primary component development tool for
Gridkit is OpenCOMJ. - ? CRTK OpenCOMJ
20CRTK API (1)
- template load(comp_type name)
- Utilise Java ClassLoader to perform Load
behaviour - Not implemented (yet). Relies on Java automation
- comp_inst instantiate(template t, opaque arg)
- CreateInstance(String comp_type, String
comp_name) - Comp_type String Class Name
- status unload(template t)
- Cant unload class explicitly in Java
- status destroy(comp_inst comp)
- DeleteInstance(IUnknown pComp)
- Cant explicitly delete the component this just
supports removal of meta-data.
21CRTK API (2)
- ipnt_inst getinteractionpoint(comp_ist, kind,
ipnt_type) - IUnknown QueryInterface(ipnt_type)
- Implemented per component
- Cant Get a receptacle
- No problem to add above behaviour to the runtime
- comp_inst bind(ipnt_inst, ipnt_inst receptacle)
- Connect(comp_ist, comp_ist, ipnt_type)
- Identical behaviour
- status putmeta(ID entity, String key, opaque
value) - status reflect(Callback callback)
- Need to examine how these methods relate to
meta-implementation already in place
22CRTK Load Bind
OpenCOM runtime new OpenCOM()
IOpenCOM pIOCM (IOpenCOM)
runtime.QueryInterface("OpenCOM.IOpenCOM")
CRTK (OpenCOMJ Runtime)
Java Calculator Component
IUnknown CalcUnk pIOCM.CreateInstance( Calcula
tor, The_Caculator_Component)
Iunknown SubUnk pIOCM.CreateInstance( Subtract
, The_Subtract_Component)
Java Random Number Component
Java Subtract Component
Iunknown Ran pIOCM.CreateInstance( Random,
The_Random_Component)
unsigned long ConnID pIOCM.Connect( CalcUnk,
SubUnk, ISubtract)
23Extension Caplet (Win32 C)
- Adder is a C Win32 component
- we need to create extension caplet to execute it
in
Calculator Component
- C Caplet Properties
- OpenCOMJ component
- Loaded and Instantiated through PRIMARY java
caplet - Named CAPLETWin32C in primary graph for
introspection - Startup -gt Call JNI Method in JavaConnect DLL
Load_Caplet() - Creates a new OpenCOM runtime
- Provides Invoke() Service
- Allows C code to Invoke Java operations
(CtoJava see later)
Random Number Component
Subtract Component
24Dual role of Java Connect DLL
- Implements 5 Java Native Interface Operations 1
Global DLL variable - LoadCaplet() - Create the C caplet with OCM
runtime - Instantiate(CompType, CompName)
- Load Instantiate components into C caplet
- Connect(CompName, CompName, Interface)
- Connect components within the C Caplet
- Invoke(compname, Interface, method,args)
- Call operations on Interfaces of components
within C Caplet - Supports Java to C bind
- Persistent_Reference(Java Object)
- Manages C reference persistence versus Java
Garbage Collection - Global Variable - Pointer to OCM runtime
- Could get away without it (OCM singleton) ?
Performance - JavaConnect Component
- Created / Loaded into Caplet runtime when Caplet
initiated - Interface to Continuous Queued RPC ? to support
C to Java bind (see later) - Proxy to the OCM runtime ? Redirect the above DLL
operations
25Load component into extension caplet
- Loader Properties
- OpenCOMJ component implements ILOAD
- Load(Component Type, Component Name)
- Named LoaderWin32C in primary graph for
introspection
Java Runtime
C Caplet
C Loader
- Load Adder What happens ??
- Load((Comp) Adder, (Name) CAdder)
- Calls JNI_ Instantiate() in Java Connect DLL
- Redirect to JavaConnect ?Calls OpenCOM
createInstance(..) Startup() - Surely there is a Type mismatch ??
- COM uses 16 byte Ids for component types not a
string! - ? Use the registry to find win32 CLSID
- Assume Java String TypeName relation to CLSID
e.g. Adder equals CLSID_Adder equals
89FFFCB1-FC74-481D-ACB1-3C1FE929462A
JNI-DLL Magic
C Runtime
JavaConnect DLL
JavaConnect
26Components in Extension Caplets
- Does the primary caplet need to maintain
information about components in extension caplets
? - For Java/C Binding Yes (see later)
- For Meta-space (Architecture, Interface
Interception) - No but it will simplify
implementation - To support bindings Ive applied a component
proxy approach - Each component in the Extension Caplet has a
mirror proxy in the Primary Caplet - In reality it is an OpenCOMJ stub (No function
implementation) - Implement the interfaces of C component as JNI
calls - DOWNSIDE Has to be coded
- Feasible it could be generated from the C
component code - Not dynamic e.g. ExposeInterface() of CFs lost
27System Snapshot After Load
Calculator Component
Adder Proxy Component
C Loader
Random Number Component
Subtract Component
C Caplet
JNI-DLL Magic
C Runtime
JavaConnect DLL
C Adder Component
JavaConnect Component
28Bind Primary to Extension (Java2C)
- Java component has receptacle IAdd that must be
connected to interface of C Adder - V2 ? Load the binder
- However, because we have a stub in place in
Primary - Connect Java component to the proxy in primary
- Call Connect(CalcUnk, AdderUnk, IAdd)
- Load returned Unknown pointer
- Could Wrap this as a binder component if
necessary - Is transparency good or bad here
- Programming API v Consistent behaviour
Java Runtime
Java2C Binder
C Caplet
C Loader
JNI-DLL Magic
C Runtime
JavaConnect DLL
JavaConnect
29Adder Proxy Example
- public int add(int x, int y)
- Object args new Object2
- args0 new Integer(x)
- args1 new Integer(y)
- Object jresult
-
- try
- jresult invoke("Adder","1EA921FB-5FA
B-4172-8206- - 1BA7880551C0","add",args)
-
- catch(Java2CBindException e)
- throw new OpenCOMReceptacleException(
Invoke failede) -
- Integer result (Integer) jresult
- return result.intValue()
-
30Snapshot Java to C receptacle
31Bind Extension (C) component to Primary
component (Java)
- Surprisingly this is a much harder problem !!
(Thanks to JNI) - C caplet implements a service allowing dynamic
invocations - ?Use same Proxy approach again?
- Unfortunately not
- You cannot pass a Java reference to the C
runtime because all JNI Operations are garbage
collected - The reference is garbage collected after the JNI
operation that called it returns - OKAY Lock a JNI thread pass its reference to
the runtime fail - JNI references only operate in single thread of
invocation - Solution Queued RPC approach
C Adder Component
IRandomNumber
?
InvokeService()
Java Random Number Component
C Caplet
32JavaConnect Q-RPC
Persistent_Reference(Jobject Caplet)
Adder Receptacle Proxy
JavaConnect
IJavaConnect
Continous Thread
Proxy connects to Java Connect
Java Connect places each receptacle invocation in
the queue
Queue Buffer
Data in Queue ? Invoke Caplet
C Caplet
33Example Adder receptacle proxy
- int CAdderProxyGetRandomNumber(int x)
- FunctionInfo newF
- strcpy((char) newF.name, (char)
GetRandomNumber") - newF.returnType VT_INT
- newF.NoParams1
- VARIANT v1
- v1.vt VT_INT
- v1.intVal x
- newF.list0v1
- VARIANT result
- result.vt VT_INT
- HRESULT hr m_pSR_IJavaConnect-gtInvokeService((L
PSTR) RandomNumber", newF, result) - return result.intVal
34Snapshot C to Java receptacle
Adder Component
IRandomNumber
Adder Receptacle Proxy
JavaConnect DLL
IJavaConnect
JavaConnect
IRandomNumber
Java Random Number Component
35Binder Implementation
- Create the binder component
- OpenCOMJ component
- Named Binder CPlusPlus2Java for Introspection
- Invoke Bind(Adder, Random,IRandomNumber,
intfID) - Loads the receptacle proxy
- Connects proxy to JavaConnect
- Connect Adder to its proxy
Java Runtime
C Caplet
C Loader
C2Java Binder
JNI
JNI-DLL Magic
C Runtime
C Adder
JavaConnect DLL
JavaConnect
36Meta Space (1) Architecture
- Standard OpenCOMJ graph view
- Same Interface
- Info about Components, Connections etc..
- C proxies represent component in OpenCOM graph
- Extend meta-architecture to enumerate Loaders,
Binders, Caplets, Component Frameworks - Fails for composite C components
- JNI_CFMetaInterface ?
IMetaArchitecture
OpenCOMJ Runtime
37Meta Space (2) Interception
- Add Interceptors to Java Interfaces
- Add to proxy component direct
- AddPre, AddPost, Enumerate
- Pre/Post interceptors called before and after the
JNI invocation - Maintain Javas improved Interception API
- Again breaks with composite components
- Cannot attach interceptor to internal interface
Pre Methods
Post Methods
Adder Proxy Component
38Meta Space (3) - Interface
- Fudged to match the Java QI interface
- QueryInterface gives you proxy interface Not
the interface of the component - Overall Meta-Space Approach Improvements
- Loadable
- Consistent across all caplet types
- It just happens that Java and C integrate
easily - Implement to the V2 Callback style
39Implementation Availability
- Java-C
- Separate components added to Java and C
runtimes - Tested in Win32 environment
- Preliminary Testing on PPCs (CReMe JVM)
- Available to use for prototyping
- Issues
- Bug in Q-RPC
- Hit the code hard enough (10000s continuous
receptacle calls) causes crash ? data
synchronisation error - OpenCOMLinux version
- Available for prototyping