550 likes | 775 Views
EAS302 - EAServer Internals. Scott McReynolds OEM Engineering Manager e-Business scottmc@sybase.com. Agenda. Object References Naming and Security Interoperability Architecture Dispatcher (Server Kernel) Marshalling, Stubs and Skeletons Component Model Plug-in Architecture
E N D
EAS302 - EAServer Internals • Scott McReynolds • OEM Engineering Manager • e-Business • scottmc@sybase.com
Agenda • Object References • Naming and Security • Interoperability Architecture • Dispatcher (Server Kernel) • Marshalling, Stubs and Skeletons • Component Model Plug-in Architecture • Customizable Instance Life-Cycle
What is an Object Reference? • Also known as a CORBA IOR. It contains zero or more profiles (> 1 for load balancing and high availability). • A typical profile contains: • Protocol, e.g. IIOP. • Endpoint, e.g. myhost:9000. • Protocol + Endpoint = location of server. • ObjectKey, unique for the specified endpoint. Example Profile Protocol: IIOP/SSL (iiops) Endpoint: myhost:9001 ObjectKey: ………...
What is an Object Key? • The part of an Object reference that tells a server which of its objects is being referenced. • An opaque binary value whose contents are (usually) only understood by the server that created the owning object reference. • The value that is sent in the GIOP Request Header when a client invokes a method on an object reference. binary data
Naming and Security • CORBA 2.2 Interoperability • Uses SessionManager::Session::lookup – Sybase proprietary naming interface that allows clients that do not support any of the standard CORBA security mechanisms for authentication. • RMI/IIOP Interoperability • Uses CosNaming::NamingContext::resolve together with CSIv2 standard mechanisms for security interoperability.
Manager Object • A well-known object in each EAServer process. • Used implicitly by the PB connection object and the EJB InitialContext. • Allows simple URL based naming for clients’ initial object references, e.g. “iiop://myhost:9000”. interface Manager { Session createSession(in string user, in string password); void ping(); };
Manager ObjectKey • Since Manager objects are used for bootstrapping, a Manager ObjectKey can be created by a client given a server’s URL, e.g. String url = “iiop://myhost:9000”; Manager manager = ManagerHelper.narrow(orb.string_to_object(url)); NUL byte ‘M’
Manager View Client Server createSession Manager ObjectRef check Manager Object Operating System (user, password) (optional) Session ObjectRef checkSession (optional) Client AuthService ObjectRef AuthService Object Manager ObjectRef This is separate from, and additional to, any SSL authentication using server and client certificates. May return NO_PERMISSION system exception Session ObjectRef
Session Object • Returned bymanager.createSession(“user”, “password”) • Used implicitly by the PB connection object and the PowerJ/JNDI InitialContext. • Allows only authenticated clients to create object references. interface Session { Object create(in string factoryName); Object lookup(in string name); };
Session ObjectKey • Can only be created or decoded by the server. • Contains the client’s username & password(or CSIv2 flag). Is encrypted using a random key from $JAGUAR/Repository/Security/jaguar.key (the contents of which are assumed to be site-specific). • Has a 32 bit checksum using random data from jaguar.key to prevent clients creating ‘fake’ sessions. checksum user password ‘S’ encrypted
Session View Client Server create Session ObjectRef Session Object (factoryName) Note: all of a Session Object’s state is reconstructed from the ObjectKey in the client’s Session ObjectRef, each time ‘create’ or ‘lookup’ is called. Session Objects consume no server resources between calls from the client. ObjectRef May return OBJECT_NOT_EXIST system exception Client lookup Session ObjectRef Session Object (name) Factory/Home ObjectRef May return OBJECT_NOT_EXIST system exception
Factory/Home Object • Returned bysession.lookup(“MyPackage/MyComp”) • Used implicitly by the PB connection.createInstance call. • Allows only authenticated clients to create object references. interface Factory { Object create(); }; interface CustomerHome { Customer create(); };
Factory/Home ObjectKey • Can only be created or decoded by the server. • Contains the client’s username & password(or CSIv2 flag). • Contains the component name. • Uses same encryption and checksum mechanisms as Session ObjectKey. checksum user password component ‘H’ encrypted
Factory/Home View Client Server create Factory/Home ObjectRef Factory/Home Object Note: all of a Factory/Home Object’s state is reconstructed from the ObjectKey in the client’s Factory/Home ObjectRef, each time a ‘create’ or ‘finder’ method is called. Factory/Home Objects consume no server resources between calls from the client. ObjectRef Client find... Factory/Home ObjectRef Factory/Home Object ObjectRef
Component ObjectKey • Can only be created or decoded by the server. • Contains the client’s username & password(or CSIv2 flag). • Contains the component name. • Contains a unique ID (+ Primary Key for entity). • Uses same encryption and checksum mechanisms as Session ObjectKey. checksum user password component unique ID ‘E’ encrypted
Name Service • Manages bindings of names to Factory/Home objects. • All binding information is transient (in-memory) for maximum performance. • When a server starts, it consults its local repository for a list of installed components and binds each with the name server(s). • Lookup/resolve calls return ALL available locations (profiles) for the requested name, sorted according to the selected load balancing strategy. • Load balancing and failover is based on client run-time choosing from the available profiles.
Interoperability Architecture • Dual architecture: • CORBA 2.2 Interoperability • RMI/IIOP Interoperability (for EJB 2.0) • You can have your cake and eat it too
CORBA 2.2 Interoperability • Attempts to map all parameter types to: • Primitive IDL types, or • Object References (IDL interface types), or • Structures (IDL struct types), or • Sequences (IDL sequence types) • In principal, this allows any CORBA 2.0 – 2.2 compatible client (supporting IIOP 1.0 or 1.1) to easily communicate with components in EAServer.
RMI/IIOP Interoperability • Uses the same IDL as for CORBA 2.2 Interoperability. • ‘Clever’ stub and skeleton generation allows for the generated code to obey the Java to IDL (RMI/IIOP) mapping specification even though our IDL does not use valuetypes. • In other words, our wire-level interoperability is compliant with RMI/IIOP requirements, but our IDL is not generated in the ‘standard’ way, instead it is generated to facilitate access by non-Java clients.
What are valuetypes? • Valuetypes are the CORBA 2.3 IDL equivalent of classes that support inheritance - like ‘structs’ with inheritance and operations (methods).
What is the big deal with valuetypes? • Marshalling is complex. • Using CORBA 2.3 IDL for non-Java clients requires the customer to re-write the valuetype operations in the target client language, e.g. porting the java.util classes and marshalling code to C++, COM or PB. • Their use precludes interoperability with pre-CORBA 2.3 ORBs. This limits the types of clients that can be used.
Detection of Client Type • Allows a component to be deployed without regard for whether the client will want to use CORBA 2.2 or RMI/IIOP Interoperability. • Detects client’s interoperability requirements at run time. • Allows usage of a component by both types of client, simultaneously! As far as we are aware, this feature is unique to EAServer.
Tricky Cases • There are several cases where the correct: • Java RMI (EJB standard) semantics cannot be obtained using CORBA 2.2 Interoperability. • Null value propagation. • Inheritance with parameters. • Inheritance with exceptions.
Null Value Propagation • Actual parameter value passed at run-time is null, e.g. • Declared: void myMethod(String name); • Run-time: String name = null; comp.myMethod(name); • Component: if (name == null) • . . . • Solution – use RMI/IIOP interoperability.
Inheritance with Parameters • Actual parameter type passed at run-time inherits from declared parameter type, e.g. • Declared: void myMethod(java.util.Date date); • Run-time: java.sql.Date myDate = . . . ; comp.myMethod(myDate); • Component: if (date instanceof java.sql.Date) . . . • Solution – use RMI/IIOP interoperability.
Inheritance with Exceptions • Actual exception type thrown at run-time inherits from declared exception type, e.g. • Declared: void myMethod() throws java.sql.SQLException; • Run-time: throw new java.sql.DataTruncation(); • Client: if (ex instanceof DataTruncation) . . . • Solution – use RMI/IIOP interoperability.
IDL Entity Types • In the context of EJB interoperability, IDL entity typesare Java classes that were generated from CORBA IDL definitions (e.g. enum, struct and union definitions). • Examples: TabularResults.ResultSet, XDT.RowSet. • Carefully defined IDL entity types can be marshalled much more efficiently than typical serializable Java classes. • These must be supported as parameter types by all products that implement EJB 2.0 interoperability, i.e. using RMI/IIOP does not mean sacrificing efficiency.
Dispatcher (Server Kernel) • The dispatcher manages: • Client connections. • Component instances. • Method invocation. • Threads. • Transactions. • Security.
Object Reference / Component Instance • An object reference is a client handle for an abstract object. • A component instance is the implementation for an abstract object. • A stateless component can use different component instances to service multiple client requests for the same object reference. • A stateful component is tied to a particular component instance until the transaction ends (or the instance times out).
Container • An EAServer container is an internal object that represents the association between an object reference and an active component instance. • A container is required only for an invocation in progress, or a transaction in progress, or for a component that retains conversational state. (Helps with scalability). • Containers manage interactions between object references, component instances and the server’s security and transaction sub-systems.
Instance Pooling • Component instances can be costly to create (for COM, PB, and for other components where the constructor does expensive initialization). • Programmatic pooling is available for objects implementing the COM IObjectControl or EJB 0.4 ServerBean interface. • Declarative pooling is available via “Pooling” check-box in Component Properties. • Pooling is recommended where possible.
End-to-End Object View Client Server Container Hash Table Component Hash Table ObjectRef Container Object Stateful Component Instance Pool ObjectRef ObjectRef Container Object Pooled Object Client Container Object Stateless Component Instance Pool ObjectRef Container Shared Object Shared Component Pooled Object ObjectRef ObjectRef Container Pooled Object
True False True Active thread Sharing Blocked thread False Activated component instance Component Types and Threading Issues Concurrency
Component Types and Threading Issues • NOT supported in PowerBuilder VM • Setting .bind.thread to TRUE overrides this combination, effectively turning off Concurrency and forcing serialization of requests to the shared component Concurrency = TRUE and Sharing = TRUE
Concurrency Option • Disable this option where component code is not thread-safe (MT-safe), i.e. when it is not safe for multiple clients to call methods in parallel (even on separate instances). • Disable this option for shared components if the component writer did not make use of synchronization primitives, e.g. COM / PowerBuilder shared components. • EAServer uses a mutex (semaphore) to serialize access to components that do not permit concurrency.
Component Types and Threading Issues • What’s up with this new BindObject property? • Allows multiple client threads to execute in one instance (like a shared component) but also supports creation of multiple instances • Due to PowerBuilder thread-safety issuesnot a viable property for a componentimplemented in PowerBuilder
Thread Pooling • Service Thread - a thread that is associated with a running service component. • Listener Thread - a thread that accepts incoming connection requests. • Client Thread - a thread that is associated with an open client connection (e.g. IIOP client). • Bound Thread - a thread that is associated with a component instance. The Bind Thread option is required for components that attach data to the creating thread (e.g. COM, PB DataStore).
End-to-End Thread View Client Server Listener Thread Thread Service Thread Container Object run, start, or stop invoke method ObjectRef Client Thread Client Container Object Method Thread Pool Thread Client Thread Bound Thread Pooled Thread invoke method ObjectRef Container Object Method Pooled Thread
Marshalling • Marshalling is the process of converting method calls – in particular input and output parameter data - into raw binary data that can be passed over a network. • Except for EJB 2.0 ‘local’ interface calls, all component calls in EAServer involve parameter marshalling. • Marshalling is distinct from actual network I/O (e.g. TCP/IP socket read/write calls). • For inter-component calls within a server, network I/O is avoided.
Lightweight EJB Container • Improves Performance for EJB -> EJB Communications. • Default for Server. com.sybase.jaguar.server.lwc • Component level Property. com.sybase.jaguar.component.lwc • EAServer activates the lightweight container for EJB-to-EJB calls as long as all of the following are true: • The LWC is enabled for the server and the called (target) component. • The calling (source) component uses an EJB reference or EJB local reference to make the call. • The LWC is compatible with the transaction and security properties of the calling (source) and called (target) components. • The LWC cannot be forced to activate. • Significant performance improvement with "Required" or "Requires New". • Object references cannot be marshalled.
EJB CMP Cache • Drivers to improve overall performance of CMP EJBs • Allowing updates to be deferred to the end of each transaction and sent together as a command batch.. • Reducing network round trips between the database server and EAServer. • Supports automatic creation of semi-temporary stored procedures. • Sybase Driver : com.sybase.ejb.cmp.SybaseDriver • Oracle Driver: com.sybase.ejb.cmp.OracleDriver • Lots of new Parms.. Check the documentation
Stubs • A stub is a generated class that implements a CORBA IDL interface by delegation to a remote object. • Stubs appear to the client as ‘local’ objects. • Stubs contain object references. • Method calls on stubs are dispatched to the server identified in the object key - using parameter/request marshalling (and network I/O if the object is on a remote server).
Stub Architecture – C++ / COM / PB / … virtual CORBA_Double sqrt (CORBA_Double x) { CORBA_ULong _status; JagStream* _stream = new_JagStream(&_status, _jagObjectRef, 0, "sqrt"); CORBA_check(_status); JagStream_putDouble(_stream, (JagDouble*)&x); JagStream_getReply(_stream); // network I/O CORBA_Double _result; JagStream_getDouble(_stream, (JagDouble*)&_result); if (_stream->fail == JAG_CORBA_USER_EXCEPTION) { CORBA_Char* _type = ""; _stream->fail = 0; JagStream_getString(_stream, &_type, 0); JagORB_log("Math::DoubleMath::sqrt -- unknown user exception '%.100s'", _type); _stream->fail = JAG_CORBA_UNKNOWN; } CORBA_close(_stream); return _result; } JagStream run-time library libjcc.dll/.so
Stub Architecture - Java public double sqrt (double x) { com.sybase.CORBA._Request _request = __request("sqrt"); try { org.omg.CORBA.portable.OutputStream _output = _request.getOutputStream(); _output.write_double(x); _request.invoke(); // network I/O org.omg.CORBA.portable.InputStream _input = _request.getInputStream(); double _result; _result = _input.read_double(); return _result; } catch (com.sybase.CORBA.UserException _ue) { throw new org.omg.CORBA.UNKNOWN(_ue.type); } finally { _request.close(); } } _Request InputStream OutputStream classes com.sybase.CORBA.*
Code Set Conversion • For IIOP 1.0, all data is passed over the network in ISO 8859-1 transmission code set. • For IIOP 1.1 / 1.2, all data is passed over the network in UTF-8 or UTF-16 form. • Stubs and skeletons take care of converting between transmission code set and the code set required by the clients and components. • Flexible design ensures that multiple code sets can be used (at same time) by client & server.
Skeletons • A skeleton is a generated class or library that provides a bridge between the dispatcher and an implementation class. • Skeletons are required for Java and C++. Generic code is used for some component models (COM, PowerBuilder). • Skeletons tend to support more efficient marshalling than generic code.
Component Model Plug-in Architecture • Each component model (apart from C++) is implemented by an external library with three entry-points. • Load Component (new_JagComponent). • Create Instance (create). • Invoke Method (invoke).
Load Component Server Load Component delegates to external library (.dll / .so) new_JagComponent (JagChars* name, JagHashtable* props) (For example - libpbjag70x.so with server property com.sybase.jaguar.server.pb70.library=libpbjag70x.so) Load Component returns JagComponent - a “C” class struct JagComponent { JagComponentCreateFunc create; ... }
Create Instance struct JagComponent { JagComponentCreateFunc create; ... } JagObject* create (JagComponent* component); Create Instance returns JagObject - a “C” class struct JagObject { JagObjectInvokeFunc invoke; ... }
Invoke Method struct JagObject { JagObjectInvokeFunc invoke; ... } void invoke (JagObject* object, JagStream* stream, JagChars* method, int control) Invoke Method uses JagStream for parameter & exception marshalling invoke method on component instance (COM / Java / PowerBuilder object)