Content Management and Capture

Content Management and Capture

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
Expand all | Collapse all

Synchronized block in ICN PluginService

  • 1.  Synchronized block in ICN PluginService

    Posted Thu June 22, 2023 10:36 AM

    Hi everyone,I would like to ask you about best practices for using getSynchObject in custom PluginService.I read "Customizing and Extending IBM Content Navigator" redbook and filenet api for class PluginServiceCallbacks, but I still have several questions:- Do I need to use synchronized block everytime I read data from objectStore?- Do I need to use synchronized block everytime I write data to objectStore?- It is needed to use synchronized block only if I am using one of these methods?
    getCMDatastore
    getODServer
    getP8Connection
    getCMISSession
    retrieveDocumentContent
    retrieveJSONAnnotations
    getCMDocumentDDO
    getODDocument
    addODNote
    getCMAnnotationsXDO
    getCMBookmarksXDO
    getODNotes- Do I need to use synchronized block in case I get objectstore object the way below?

    public void execute(PluginServiceCallbacks callbacks, HttpServletRequest request, HttpServletResponse response)
     throws Exception {
     String repositoryId = request.getParameter("repositoryId");
     ObjectStore objectStore = callbacks.getP8ObjectStore(repositoryId);
     }


    - Why do you need to use synchronized block in chapter 5.3.1 "Sample code of custom repository search service" for p8 calls? 

    Thank you.



    ------------------------------
    Gabriela Maráková
    ------------------------------


  • 2.  RE: Synchronized block in ICN PluginService

    Posted Fri June 23, 2023 12:51 PM

    As per the documentation here, some of these methods would need to used with a synchronized block -> https://www.ibm.com/docs/en/content-navigator/3.0.12?topic=comibmecmextension-pluginservicecallbacks. Please review and let us know your comments. We will provide additional comments.



    ------------------------------
    Nanda Pilaka
    IBM Content Navigator Support
    ------------------------------



  • 3.  RE: Synchronized block in ICN PluginService

    Posted Sun June 25, 2023 10:46 PM

    I'd think the getP8ObjectStore also need to in the synchronized block. Actually, the synchronized block is for the repository APIs. ICN just package them into the plugin callback to return the objects of them. When using the repository APIs directly, we usually need to add synchronized block for one whole action. Using them in ICN is similar. I'd recommend to use synchronized block before get the repository connection, including get any objects of it, and the block ends after all repository API calls are done.



    ------------------------------
    JIE ZHANG
    ------------------------------



  • 4.  RE: Synchronized block in ICN PluginService

    Posted Mon June 26, 2023 02:45 AM
    Edited by Gabriela Maráková Mon June 26, 2023 02:46 AM

    Nanda, I checked linked provided by you and getP8ObjectStore is not mentioned as needed to be used with synchronized block. However in redbook* getP8ObjectStore is in synchronized block (and in comment bellow Jie Zhang suggested it should be, too).

    So is it mistake in redbook* or in https://www.ibm.com/docs/en/content-navigator/3.0.12?topic=comibmecmextension-pluginservicecallbacks ?

    * redbook title: Customizing and Extending IBM Content Navigator,  chapter 5.3.1



    ------------------------------
    Gabriela Maráková
    ------------------------------



  • 5.  RE: Synchronized block in ICN PluginService

    Posted Mon June 26, 2023 07:37 PM

    Hi,

    The documentation is fairly vague. Even the use of it in the examples is fairly obtuse.  Without a complete definition it means everyone does this over and over with trial and error, wasting development time and generating solutions that can cause issues as the documentation isn't clear, complete and concise.

    It doesn't indicate WHY you need to use a synchronised block, WHAT happens if you do and WHAT happens if you don't.  The original question asked for that level of information which isn't in any response I've seen so far and isn't in the documentation either.  Is it possible to get those three things in this thread, and perhaps backfilled into the documentation?



    ------------------------------
    David Alfredson
    ------------------------------



  • 6.  RE: Synchronized block in ICN PluginService

    Posted Wed June 28, 2023 01:05 AM

    Actually, it is because those APIs return objects of the repositories API, or a wrap of them. Followed processing code will be repositories API callings. It belongs to the repositories API programming area in a multi-thread environment, like FileNet P8 CPE API. When you get a connection or an object store object, which should have a connection inside, or it cannot do the real actions against CPE server, if in a multi-thread environment,  and you don't want the object be touched by other threads, synchronized block should be used. 



    ------------------------------
    JIE ZHANG
    ------------------------------



  • 7.  RE: Synchronized block in ICN PluginService

    Posted Thu June 29, 2023 10:43 AM

    Hello Calvin

    I understand the reason why the p8 connection should be used only by one thread, but I will try to rephrase the original question: 

    will callbacks.getP8ObjectStore or callbacks.getP8Connection return always the same and only ObjectStore/Connection (for specified repositoryId)? Or is there any connection pooling? If yes, where can it be configured (e.g. size of the pool)?

    Because if there's no connection pooling, it has very limited throughput. All requests from users that are served by multiple threads (configured in WAS) will wait for one p8 connection. And the only 2 options to scale the system up are:

    a) install another ICN instance/server - so it is limiting horizontal scaling a lot (it creates lot of overhead).

    b) define multiple repositories in ICN for the same p8 objectstore and implement own connection/repository pooling (e.g. for each usecase/feature use different repository). Most of the features has option to not include other repositories - so user will not get confused, but Home feature includes all repositories for the desktop and it can be confusing for the end user - why he have more repositories there and which one to select). -  so here I would suggest either to have option to define "hidden" repository for desktop or allow hiding repository for Home feature.

    ...but ideally if callback.getP8* operation provides pooled connection and the pool can be configured.



    ------------------------------
    Marcel Kostal
    ------------------------------



  • 8.  RE: Synchronized block in ICN PluginService

    Posted Fri June 30, 2023 01:09 AM

    Hi Marcel,

    The callbacks.getP8ObjectStore or callbacks.getP8Connection return always the same and only ObjectStore/Connection (for specified repositoryId) for one user session. So it is not like the database connection pool mechanism. And P8 needs the push subject and pop subject in the correct sequence, or there may be unauthenticated error returned by CPE server. Actually I'd think that may be more key to have the synchronized block for P8 actions.



    ------------------------------
    JIE ZHANG
    ------------------------------



  • 9.  RE: Synchronized block in ICN PluginService

    Posted Fri June 30, 2023 05:52 AM

    Hi Calvin

    Are you saying that callbacks.getP8Connection returns different connection for different user session? So if there are two users logged in and both executes pluginService at the same time each thread (user) will receive his own connection to p8?  ..... because the API documentation just says: "Returns a connection to the IBM FileNet P8 domain for the given repository."  (so I'm missing there:  .... and for user session)

    But if it works as you wrote than it's good (not an architecture bottleneck)... but I would suggest to update it in documentation ;-)

    Thanks.



    ------------------------------
    Marcel Kostal
    ------------------------------



  • 10.  RE: Synchronized block in ICN PluginService

    Posted Tue July 04, 2023 03:09 AM

    Hi Marcel,

    Yeah, you are right, the two users will have their own connection of P8. We use

    Factory.Connection.getConnection(ceURI);//CPE API

    for each user logon.

    And I agree, the document can be update for this part. 

    Thanks,

    Jie



    ------------------------------
    JIE ZHANG
    ------------------------------



  • 11.  RE: Synchronized block in ICN PluginService

    Posted Fri June 30, 2023 01:11 AM

    And for more P8 API usage tips, we may need to be answered by P8 developers.



    ------------------------------
    JIE ZHANG
    ------------------------------