What does it mean by $scope=global in ATG..?

3.3k views Asked by At

According to the documentation,

Global: Component is shared among all users. Session: Separate instances of the component are provided to each user.

Is that means, for global component, there is only one instance for the whole nucleus system.. If this is true, how does it valid for components like ‘/atg/dynamo/transaction/TransactionManager’ and most of the droplets..? Because those components are used by several users at a single moment

Edited:

I understood the ‘TransactionManager’ behavior. According to the definition there should be single transaction manager, and he should keep transaction objects per each transaction. But my question is still valid for droplets like, foreach, switch, etc (most of them are globally scoped) If there is only one instance of corresponding class for the whole nucleus system, isn't it having bad effects on performance?

3

There are 3 answers

0
radimpe On BEST ANSWER

Historically there were three different types of scope available in ATG. This has now increased to 5, with the addition of Window (generally only used in the CSC application so try not to use it) and Prototype (added to support the use of Endeca Cartridge Handlers).

As you highlight from the documentation, global component is instantiated once and is shared by all users, while a session component is created once for a given session and is shared by all requests of that session. Similarly a request scoped component is freshly instantiated for each request that uses it.

From a performance point of view, resolving the path to an existing component (for example a globally scoped component like ForEach) takes a little time, but instantiating a new object (in other words a request scoped component) is comparatively more expensive.

So in the case of a ForEach droplet it gets instantiated once but in the service method it actually extracts the parameters from the request:

String elementName = pRequest.getParameter(ELEMENT_NAME);

This means that your globally scoped component is thread safe in that it only takes in parameter from the current request. So in general, if a component can be shared by multiple users, without worrying about synchronisation, it should be globally scoped versus session or request scoped. (The rule of thumb should be that if your droplet is request scoped, you are likely doing it wrong).

0
Shiva On

ATG Commerce has 4 different scopes of components

  1. Global: This is the default scope of the component, if scope isn’t defined. These components will be initialized once and will be there as a global object. It’s a best practice to have all the Droplets, Tools, Manager and other Configuration components as global
  2. Session: The scope and the values maintained will be unique for every session. The session scope components generally used are ShoppingCart (Order), Profile, SearchFormHandler etc..
  3. Request:The scope and the values maintained will be unique for every request. The request scope components generally used are FormHandlers to process individual requests.
  4. Window: The scope and the values maintained will be unique till the browser window is closed. The Window scope components
    generally used in CSC application for ShoppingCart component etc.. It’s good to use components with any scope based on business
    requirement but having it declared as Global and using it will be a benificial for improving the performance of the application. It’s a thumb rule have the business logic in Global scope components and refer it from lower scoped components if required. This will reduce the threads waiting to be Garbage collected.
0
Gustavo Recio On

If you are aware of Design Patterns, $scope=global is the equivalent of making an ATG component a singleton.