Thursday, 14 May 2015

Object Creation in ATG Commerce

          After my yesterday's blog on Object Creation I was wondering how objects gets created in ATG Commerce. So here are my findings.
       
         I will be glad if anyone contribute or correct me in this Blog :).

Nucleus : (The Engine)

        ATG Commerce is a collection of Java Classes which creates an Environment called NUCLEUS which is the heart of ATG and responsible for everything happens in ATG Commerce.

        Nucleus understands the memory usage and optimization and creates objects ONLY when required/necessary. Just like the "main" method in our simple java classes, nucleus needs a "kick start" for classes which are to be initialized.

How Nucleus creates Object

        When you start up an application, Nucleus reads the configuration path, (a location where we keep our configuration files, which is generally the "config" folder of our ATG module). Within one of those directories is a file called Nucleus.properties (present in the config path of some out-of-the-box ATG module) that contains the name of the first component to create. The out-of-the-box Nucleus.properties looks like

$class=atg.nucleus.Nucleus
initialServiceName=
/Initial

       The initialServiceName property instructs Nucleus to configure and start up its initial service using Initial.properties (which is another configuration file, present in some out-of-the-box module's config path). The initial.properties looks like

$class=atg.nucleus.InitialService
initialServices=\
    /atg/Initial,\
    VMSystem,\
    /atg/dynamo/StartServers


        InitialService extends GenericService class which has a method called doStartService() Which act as the main() method of normal java class.

java.lang.Object
extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
extended by atg.nucleus.GenericService
extended by atg.nucleus.InitialService

         From here Internally it calls the the java.lang.Class.forName(String className) method returns the Class object associated with the class or interface with the given string name. And I concluded to this assumption because I seen the below error in my log and also we always put the full class name in the .property file of the component, which can be used to create the object of that class.

Class cls = Class.forName("java.lang.ClassLoader");

at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169) 


     We also can override the doStartService(), which can be used to create the object or start the component.

public void doStartService() throws ServiceException {
// our custom code

// which we want to execute at startup time
super
.doStartService();
}






     

No comments:

Post a Comment

  SyntaxError : (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape Solution:...