Back
Next
Now before we start.. we must know that this is a very very important topic in ATG, and must be understood very very carefully..
Nucleus is the heart of ATG, around which everything revolves.
Now, in the previous article we understood what components are, and how we create them. But we never understood how to we "execute" or run those components.
Let us, for a moment forget about components and come to basic Java.
The question is, how do we execute a java program..??
We open a notepad, write the following code.
Now what exactly did we do here??
We created a class Person, added two variables, name and age to it. Then we created a main() method. Inside the main method we created an object of "Person" class, set the variables, and we printed them on the standard console (your computer screen).
(Disclaimer: If you did not understand the above code.. you may want to spend some money on basic Java tutions..)
Now, post writing the code, we compile this file (Person.java), generally using the command
javac Person.java
Next, we see that the byte code for this class is generated, and a file "Person.class" is created. Next, we execute this byte code using the "java" keyword.
java Person
Now, the output on our screen is something like:-
Name is : Stephen
Age is : 22
Now, when we executed the byte code, the code written in the "main()" method was executed. Therefore, whenever we create a simple java class, whatever we write in the main method gets executed. This method is like the "kick start" of your java program.
Now, the way how ATG framework functions is somewhat tricky. In our java class, we manually created an object of "Person" class (see first line in the main method of above program).
In ATG we have something called as nucleus, which does the job of creating objects on a "on-demand" basis. Depending on how you configure your component (we will discuss about this in component scopes), Nucleus services creates objects on need basis and provides a reference for us to use.
Nucleus, being the heart of ATG 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.
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
Now, in the previous chapter, we created a component, with its configuration file at location:-
<ATG_MODULE>/config/atg/persons/Person.properties
which, as per Nucleus, is at the location:-
/atg/persons/Person.properties
For nucleus, to start our component at startup time (when ATG server starts), we add our component to initialServices.
For this, we need to create a configuration file Initial.properties anywhere in our config-path. Next we write the following as its contents:-
We will discuss more about configuration file stuff and how they append later on.
Therefore, adding a component to initialServices, makes sure your component starts-up at the start-up time. (This is the ATG's kick start of the component).
There are other ways to start-up an ATG component, and we will discuss them as we go.
In the previous chapter we created a java class Person.java. Let us modify the contents of that class to:-
Please note that we generally extend the class GenericService in our application. This class has a method doStartService(), which we can override in our components. This is like the "main" method of our component. Whatever we write in this method, will be executed, when this components starts up.
Back
Next
Next
Now before we start.. we must know that this is a very very important topic in ATG, and must be understood very very carefully..
Nucleus is the heart of ATG, around which everything revolves.
Now, in the previous article we understood what components are, and how we create them. But we never understood how to we "execute" or run those components.
Let us, for a moment forget about components and come to basic Java.
The question is, how do we execute a java program..??
We open a notepad, write the following code.
public class Person{ String name; int age; public static void main(String[] args) { Person person = new Person(); person.name = "Stephen"; person.age = 22; System.out.println("Name is : "+person.name); System.out.println("Age is : "+person.age); } }
Now what exactly did we do here??
We created a class Person, added two variables, name and age to it. Then we created a main() method. Inside the main method we created an object of "Person" class, set the variables, and we printed them on the standard console (your computer screen).
(Disclaimer: If you did not understand the above code.. you may want to spend some money on basic Java tutions..)
Now, post writing the code, we compile this file (Person.java), generally using the command
javac Person.java
Next, we see that the byte code for this class is generated, and a file "Person.class" is created. Next, we execute this byte code using the "java" keyword.
java Person
Now, the output on our screen is something like:-
Name is : Stephen
Age is : 22
Now, when we executed the byte code, the code written in the "main()" method was executed. Therefore, whenever we create a simple java class, whatever we write in the main method gets executed. This method is like the "kick start" of your java program.
Now, the way how ATG framework functions is somewhat tricky. In our java class, we manually created an object of "Person" class (see first line in the main method of above program).
In ATG we have something called as nucleus, which does the job of creating objects on a "on-demand" basis. Depending on how you configure your component (we will discuss about this in component scopes), Nucleus services creates objects on need basis and provides a reference for us to use.
Nucleus, being the heart of ATG 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.
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
Now, in the previous chapter, we created a component, with its configuration file at location:-
<ATG_MODULE>/config/atg/persons/Person.properties
which, as per Nucleus, is at the location:-
/atg/persons/Person.properties
For nucleus, to start our component at startup time (when ATG server starts), we add our component to initialServices.
For this, we need to create a configuration file Initial.properties anywhere in our config-path. Next we write the following as its contents:-
initialServices+=/atg/persons/Person
Now, nucleus combines this configuration file with out-of-the-box Initial.properties and appends the contents. Therefore, it automatically picks up the class mentioned in OOTB configuration file and appends our component (Person) to the initialServices. (see the "+=" sign above). Please note that if we do-not use the "+=" sign in our custom Initial.properties, and simply use "=" sign, the value of initialServices variable will be completely overridden by our configuration file.We will discuss more about configuration file stuff and how they append later on.
Therefore, adding a component to initialServices, makes sure your component starts-up at the start-up time. (This is the ATG's kick start of the component).
There are other ways to start-up an ATG component, and we will discuss them as we go.
In the previous chapter we created a java class Person.java. Let us modify the contents of that class to:-
package com.mypackage; public class Person{ String name; int age; public Person() { System.out.println("Constructing Person"); } public String getName() {return name;} public void setName(String name) { System.out.println("Setting name"); this.name=name; } public int getAge() {return age;} public void setAge(int age) { System.out.println("Setting age"); this.age=age; } }We just added some console printing statements to our constructor and the setter methods. When we re-assemble our atg application, and start our nucleus server (with our modified java class and the entry of our component in initialServices), we should see these console logging statements on our console at the startup time, so see the Nucleus initializing our very own custom component.
Please note that we generally extend the class GenericService in our application. This class has a method doStartService(), which we can override in our components. This is like the "main" method of our component. Whatever we write in this method, will be executed, when this components starts up.
public void doStartService() throws ServiceException { // our custom code // which we want to execute at startup time super.doStartService(); }So, to conclude, nucleus is basically an OOTB component, which does the task of managing which component is required to start, and starts that up. Please note that the method depicted above is not the only way nucleus components are initialized. There are many other ways the components are initialized (by Nucleus, of course), and we would be discussing them as we go-on. Now that we know how nucleus functions, let us discuss some more stuff on components and configuration files as we are much more clearer on concepts now..
Back
Next
Hi Monis,
ReplyDeleteCan we have a component with parameterized constructor?
Please give the reason for both if answer is yes or not
I have already answered this question in my last comment here:-
Deletehttp://learnoracleatg.blogspot.in/2014/10/art104-atg-components.html?showComment=1431491416382#c1250258118915776160
From the explanation given above :
ReplyDeleteWhen you start up an application, Nucleus reads the configuration path (from confgi path).
My Question is how does the Nucleus itself starts first? From NucleusServlet are we calling the Nucleus.properties which in turn invokes the Nucleus or is there any thing else going here?
Something like that. Nucleus starts up, reads "Initial.properties" from the config path, and starts running all the components. All the dependent components are also started on need-basis.
ReplyDeletehi,
ReplyDeleteThanks for writing such a awesome blog,It would be really great if you can help me with this..
setting name like statements are not printing up in logs when I start the server,its get printed in logs when I search component named person from dyn/admin.even after making Initial.properites in config.Explain a little please ,why it is not getting printed in logs when server start ups?
If the statements are getting printed when you search via dyn/admin, this means that the component is configured properly.
DeleteAlso, there seems to be some problem with Intial.properties. You could check the following things:-
1. The config path where you have overridden Initial.properties is correct (/atg/dynamo/Initial.properties)
2. In the Initial.properties, you define initialServices property. Check if you have written the property name correctly (properties are case sensitive)
3. Check your custom component's config path present in the initialServices property.
Do you can make some video about it?
ReplyDeleteIs it possible to get the ATG jars over net?
ReplyDeleteI am very new to ATG. I want to learn and practice ATG.
Please help me over this.