D I S T R I B U T E D A P P L I C A T I O N SEAServer Component Development ProcessPART 3A tutorialWRITTEN BYTIMOTHY BECKIn Part I of this series (PBDJ,Vol. 9, issue 2), I provided the necessary backgroundinformation for building EAServer components. I also introducedthe development workflow – a set of steps for building an applicationusing EAServer components. Using the workflow, you can create a Webbasedor a client/server application.Part 2 (PBDJ, Vol. 9, issue 3) focusedon developing EAServer components.Using the workflow from Part I as aguide, I showed you how to build objectsthat would become components, fromcreating a directory structure that supportsyour development to writing thecode. Finally, there was a developmentchecklist to ensure the objects werecomplete.Part 3 completes the componentdevelopment process. Here you’ll takethe final step in developing an EAServercomponent: deploying the component.Once again, pull out the developmentworkflow and keep it handy.Deploying Components to EAServerWhen a completed object is deployedit becomes a component. When developinga window or a Web page, severalcomponents may be involved, either bybeing called directly or through intercomponentcalls. Once the object isready to be deployed, start by deployingthe component to EAServer on the localmachine.In PowerBuilder, deployment occursusing a project. This project containsseveral important pieces of informationthat EAServer uses to manage the componentand handle its interaction withother components. It’s important tounderstand each property and itspotential impact on a component.PACKAGE NAMEA package is a collection of similarcomponents. Since EAServer is casesensitiveand you access components bypackage name, it’s important that thisname is spelled correctly and in theproper case.COMPONENT NAMEThis is the visible name of your component.In PowerBuilder, your objectname may be “n_cst_vendor”, but to therest of the world this component shouldbe called “Vendor”. Again, you’ll accesscomponents by name so it’s importantthat they’re spelled correctly and in theproper case.COMPONENT TYPE (STANDARD, SHARED, SERVICE)The overwhelming majority of yourcomponents will be standard, that is,they have no special attributes. The restwill be shared or service components.• Standard components are the workerbees of EAServer. They can be writtenin any language, they may supporttransaction management, and multipleinstances may be in memory at anygiven time. They can be pooled, i.e., aninstance, once created, is kept in memoryso other clients can reuse it.• Shared components are those sharedby all clients. There’s never more thana single instance of a shared component.It’s not thread-safe, so multipleinstances can’t run concurrently.Shared components are used forcaching relatively static data or makinginformation available that allclients can use.• Service components perform backgroundprocessing. EAServer runsthem when the server first starts up.They may run “forever,” or performsome task and stop. Service componentsare standard components with aspecial purpose. They’re referenced inthe EAServer server property“com.sybase.jaguar.server.services”, soEAServer knows to run them at startup.They contain three extra methods(subroutines – functions with noreturn value) that EAServer calls:–Start: Initializes the service component.Typically, you’ll set a Booleaninstance variable to “true” here.–Run: Does the actual work. Typically,this function is in a perpetual loopwhile the instance variable set inStart is true. You can use the“JagSleep” external function to putyour service component to sleep fora short time before processingagain.–Stop: Stops the component fromrunning. This method typically setsthe Boolean instance variable tofalse, causing the Run method tocomplete execution.TRANSACTION SUPPORT (NOT SUPPORTED, SUPPORTS,REQUIRES, REQUIRES NEW)Transaction support, along with stateprimitives, controls how EAServer handlesdatabase transactions. For transactionsupport to work, there are tworequirements:1. You must use a connection cache.2. You must set the “UseContextObject”dbparm value to true (UseContextObject=’Yes’).For several components to participatein a transaction, you must use a “transactioncoordinator” – a component that,through intercomponent calls (Create-Instance), calls the other componentsinvolved in a transaction. In addition,you must set the Transaction Supportproperty to one of the following:• Not Supported: The component won’tparticipate in a transaction. It’ll commitor roll back its changes independentof any other component.• Supports: Participates in the callers’transaction only if a transaction isrunning. If not, this component willact as if transaction support is set to“not supported.”• Requires: Creates a new transaction ifone isn’t already running. If there isone, it will participate in the callers’transaction.• Requires New: Always creates a newtransaction regardless of any currenttransactions. In effect, it allows you tonest transactions.20 PBDJ volume9 issue4www.SYS-CON.COM/pbdj/
CONCURRENCYThis property indicates that the componentis thread-safe, meaning multipleinstances can run in memory simultaneously.Shared components are notthread-safe, neither are PowerBuildercomponents with instance DataStores (aDataStore has embedded operating systemfunctionality that prevents it frombeing thread-safe and surviving whenmultiple instances are running at onetime). Setting this attribute to trueimproves performance for those componentsthat are thread-safe.AUTOMATIC DEMARCATION/DEACTIVATION (CHECKEDFOR STATELESS COMPONENTS)Stateless components automaticallydeactivate after every method call. If possible,all components should be statelesssince it increases reusability and decreasesthe load on server resources. Anotherconsideration here is that stateful componentsare bound to the client until they’redeactivated, creating a potential memoryleak.SUPPORT INSTANCE POOLINGInstance pooling allows componentsto be reused without being reinstantiated,thus improving performance. From adeveloper’s perspective, instance-pooledcomponents must be initialized in theactivate event and code cleaned up inthe deactivate event.COMPONENT TIMEOUTSet this property for stateful componentsto the number of secondsbetween method calls. Setting this propertyprevents a component from beingleft orphaned in memory.During the deploy process, severalerrors can occur. Generally, these are theresult of some setting in the deploy projectitself. For example, errors about therepository not being available can occurbecause you don’t have access to themachine or, more likely, because theserver name or port number are typedincorrectly. In addition, to redeploy servicecomponents, you may need toremove the component name fromthe list of services on EAServer(com.sybase.jaguar.server.services) andshut down and restart EAServer. If thereis a permissions error, check theusername and password provided forEAServer. Also, make sure it’s actuallyrunning on the server.Testing components locally is animportant part of the overall process. Itensures that a component performs asexpected when there are no other possibleavenues of interference. Test thecomponent in the environment youexpect to deploy to production. To isolatespecific functionality, you mightcreate a window or Web page to testwith, but once the testing is complete,remember to test the component in thedesired natural environment. It’s sometimeshelpful to test components beforedeploying them to EAServer by callingthe desired method from the open eventof the application object:n_cst_objectlnv_objectlnv_object = create n_cst_objectlnv_object.event activate()lnv_object.mymethod()Once the desired outcome has beenattained, create test scripts so theexpected results are clearly documented.In this process, make sure each stepis clearly laid out and nothing is left tochance.Once you’re satisfied that the componentswork as designed, deploy them tothe test box. Here the components mustnow commingle with other, perhapsunrelated, components.Any Web pages that call the componentsshould also be deployed at thistime. (Windows clients don’t need to bedeployed since they’ll ultimately resideon the client machine.) Any relatedpieces must be documented anddeployed at this time.Using the test scripts developed earlier,test the module again. Each pageshould be thoroughly covered and everyresult clearly documented. If the modulefails any test, the failure should beisolated, resolved, and the entire moduleretested first locally, then on the testbox.At this point, the module should beready for the unexpected: user acceptancetesting. Users can find ways ofbreaking an application that a developernever considered. Given this, it’s importantthat the users have as much time ashumanly possible.In addition, it’s important to continuetesting the application once it’sactually deployed to staging. Onceeveryone is satisfied that everythingworks as intended and desired, it’spassed all the tests, it looks good, andeverything is consistent and well documented,the module can be deployed toproduction. The whole cycle can thenstart over with changes, upgrades, ornew modules.ConclusionWhen building n-tier applications,carefully consider the application flow.Decide what business logic anddata-access logic will be deployed tothe application server and which languagesthese components will be writtenin. Examine each of these applicationpieces for reusability. Eachreusable piece of the application, aswell as business rules and data accesslogic, will become an object to bedeployed to EAServer. Make sure theseobjects are broken out into the smallestpossible pieces to ensure maximumreusability.Follow the development workflowprocess to ensure that the applicationdevelopment is complete and the entireapplication is completely documented.Make sure the users are involved in theprocess from the beginning. Storyboardthe application so the flow is clear andthe developers and the users understandthe process. Create functionalspecs and the user interface, then createthe objects that will be EAServer components.Follow this six-step process to createEAServer components:1. Define the EAServer component in aserver library.2. Deploy the component to EAServer.3. Generate a proxy in the client application.4. Connect the client to EAServer.5. Initialize the proxy.6. Invoke the desired methods.When creating a component, start byinheriting from n_cst_jaguar in the server.pbllibrary. Use the component developmentchecklist to ensure nothing isleft out when developing a component.Before deploying the component toEAServer, verify the project properties toensure they are correct. Finally, test, test,and test again. ▼tpbeck@intelliserve.comAUTHOR BIOTimothy P. Beck ismanaging partner andfounder of IntelliServe LLC,a Sybase ConsultingPartner, an iAnywhereSystems Integrator, and aSybase Education Agent.He has been working withPowerBuilder since 1991,and has been a certifiedinstructor of PowerSoft(later, Sybase) technologyfor more than eight years.www.SYS-CON.COM/pbdj/PBDJ volume9 issue421