Author Message
DipeshGandhi2 [Avatar]

Joined: Nov 14, 2011
Messages: 35
Offline
Is it possible for CE to execute my code on service initialization or on service destruction?

Dipesh Gandhi Software Engineer, Avaya DevConnect
DipeshGandhi2 [Avatar]

Joined: Nov 14, 2011
Messages: 35
Offline
Yes, the Collaboration Environment provides an interface com.avaya.collaboration.service.ServiceLifeCycle which executes code on service initialization and destruction. In order to use the interface, you must take your java class and annotate it with TheServiceLifeCycle. Upon using the annotation, there will be two methods init() and destroy() that must be implemented. The init() method lets you define initialization code and destroy() method with destruction code. Keep in mind that ServiceLifeCycle is implemented by the SIP servlet container so you must have a valid sip.xml file ( created by CE archetype ) and a CallListener implemented inside your underlying war file.

Dipesh Gandhi Software Engineer, Avaya DevConnect
AnthonyCahill
Joined: Jan 24, 2014
Messages: 5
Offline
Hi,

I just created a new project (mvn archetype:generate) and added a class (Poller) annotated with @TheServiceLifeCycle and that implements the ServiceLifeCycle interface.


package com.foo;

import com.avaya.collaboration.service.ServiceLifeCycle;
import com.avaya.collaboration.service.TheServiceLifeCycle;
import com.avaya.collaboration.util.logger.Logger;

@TheServiceLifeCycle
public class Poller implements ServiceLifeCycle{
private static final Logger logger = Logger.getLogger(Poller.class);

@Override
public void init() {
logger.info(">>> Poller initialized");
}

@Override
public void destroy() {
logger.info(">>> Poller shutdown");
}
}


I installed loaded and installed the resulting svar and found the following in the log file (/var/log/Avaya/sm/asm.log):

2014-03-13 11:01:20,512 [DAOReplicationQueueServicer] platform.dao.ChannelDAO INFO - ChannelDAO initializing
2014-03-13 11:01:20,515 [DAOReplicationQueueServicer] platform.dao.ChannelDAO INFO - ChannelDAO initializing
2014-03-13 11:01:20,664 [DAOReplicationQueueServicer] platform.dao.ChannelDAO INFO - ChannelDAO initializing
2014-03-13 11:03:02,875 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - enter init
2014-03-13 11:03:02,888 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - CAR InputStream(/WEB-INF/classes/CARRule.xml) is java.io.BufferedInputStream@94021c7a
2014-03-13 11:03:03,663 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - Parsed rules for TestService-1.0.0.0.0 -
2014-03-13 11:03:03,720 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - CAR InputStream(/WEB-INF/classes/CARRule.xml) is java.io.BufferedInputStream@57323295
2014-03-13 11:03:03,720 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - initialized, registering to car with application name TestService-1.0.0.0.0
2014-03-13 11:03:03,720 [SoapConnectorThreadPool : 1] call.servlet.CarRegistrant INFO - Registering to CAR: TestService-1.0.0.0.0, java.io.BufferedInputStream@57323295
2014-03-13 11:03:03,721 [SoapConnectorThreadPool : 1] call.servlet.CfSipServlet INFO - TestService-1.0.0.0.0 - successfully registered with CAR
2014-03-13 11:03:03,766 [SoapConnectorThreadPool : 1] call.servlet.ListenersFinder INFO - Listener class "com.foo.Poller" found with annotation "TheServiceLifeCycle" and implementation of "ServiceLifeCycle"
2014-03-13 11:03:03,766 [SoapConnectorThreadPool : 1] call.servlet.ListenersFinder ERROR - No initial listener found. See documentation regarding the annotations "TheCallListener"


What's interesting is that I see 'Listener class "com.foo.Poller"...' in the log output but not my log message from the init method. Do I need to register the Poller class in one of the configuration files?

Any ideas?

Thanks,
ct
DipeshGandhi2 [Avatar]

Joined: Nov 14, 2011
Messages: 35
Offline
When you generate the Maven project via "mvn archetype:generate", did you select archetype, com.avaya.zephyr.sdk:service-archetype (Collaboration Environment Service Archetype)?

If not, please select Collaboration Environment Service archtype as it will generate the project with required configurations for the Call Listener. Specifically, the web.xml and sip.xml configuration files.

Once your project is created using archetype mentioned above, you will find MyCallListener class which is created for you automatically. Within this class, you will find that class uses @TheCallListener annotation and extends CallListenerAbstract.

The CE archetype provides a good starter template but if you need specific example then I would recommend reviewing HelloWorld sample service which is available within the SDK. If you have further queries please let me know.


Thanks,
Dipesh

Dipesh Gandhi Software Engineer, Avaya DevConnect
DipeshGandhi2 [Avatar]

Joined: Nov 14, 2011
Messages: 35
Offline
I created a test service in my lab with class that implements ServiceLifeCycle and I am able to see the log statement. Using latest CE 2.0 SP2. I'm attaching the test service for you and log output below:


2014-03-13 11:44:27,709 [SoapConnectorThreadPool : 1] call.servlet.ListenersFinder INFO - Listener class "com.avaya.test.TestService.Poller" found with annotation "TheServiceLifeCycle" and implementation of "ServiceLifeCycle"
2014-03-13 11:44:27,712 [SoapConnectorThreadPool : 1] call.servlet.ListenersFinder INFO - Listener class "com.avaya.test.TestService.MyCallListener" found with annotation "TheCallListener" and implementation of "CallListener"
2014-03-13 11:44:27,759 [SoapConnectorThreadPool : 1] test.TestService.Poller INFO - TestService-1.0.0.0.0 - >>> Poller initialized


Thanks,
Dipesh
Filename TestService.zip [Disk] Download

Dipesh Gandhi Software Engineer, Avaya DevConnect
AnthonyCahill
Joined: Jan 24, 2014
Messages: 5
Offline
Hi Dipesh,

It works. Thanks a million.

So in order for my ServiceLifeCycle implementation (Poller) to be invoked I must keep the skeleton MyCallListener (and sip.xml) even though I do no call processing. Correct?

ct
DipeshGandhi2 [Avatar]

Joined: Nov 14, 2011
Messages: 35
Offline
Glad to hear it works!

Yes, your statement is correct. For CE 2.0, the ServiceLifeCycle relies on SIP servlet which requires the CallListener and generated sip.xml from the CE archetype.

Dipesh Gandhi Software Engineer, Avaya DevConnect
AnthonyCahill
Joined: Jan 24, 2014
Messages: 5
Offline
Thanks Dipesh.
Go to:   
Mobile view