Hello GuruRamesh,
if the above code lines have the desired effect to change the signal color to green/yellow/red, then you will need to execute the right code line when your application runs in the corresponding signal state. Where you implement the code or how you trigger it, its depending on your application case.
Best regards
Paul Banach