Notify Agents about Session Timeouts

TIBCO Enterprise Administrator can notify agents about HTTP session timeouts when a session expires or when a user logs out. To receive session timeout notifications, an agent must implement the TeaSessionListener interface.

The agent must implement the TeaSessionListener, add the listener, and pass the session ID to a TeaOperation.

TeaSessionListener

public interface TeaSessionListener
extends EventListener{
void onSessionDestroyed(TeaSessionEvent event);
}
You can access the session id using an instance of TeaSessionEvent.

Sample code that Implements TeaSessionListener

package com.tibco.tea.agent;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;

import com.tibco.tea.agent.annotations.TeaOperation;
import com.tibco.tea.agent.annotations.TeaParam;
import com.tibco.tea.agent.api.BaseTeaObject;
import com.tibco.tea.agent.api.TopLevelTeaObject;
import com.tibco.tea.agent.server.TeaAgentServer;
import com.tibco.tea.agent.api.TeaSession;
import com.tibco.tea.agent.api.*;
     

public class HelloWorldAgent implements TopLevelTeaObject{
    private static final String NAME = "hw";
    private static final String DESC = "Hello World";
    
    @Override
    public String getDescription() {
        return DESC;
    }
    
    @Override
    public String getName() {
        return NAME;
    }
    
    @Override
    public Collection<BaseTeaObject> getMembers() {
        return Collections.EMPTY_LIST;
    }
    
    @Override
    public String getTypeDescription() {
        return "Top level type for HelloWorld";
    }
    
    @Override
    public String getTypeName() {
        return "HelloWorldTopLevelType";
    }

    @TeaOperation(name = NAME, description = "Send greetings")
    public String helloworld(
            @TeaParam(name = "greetings", description = "Greeting parameter")
            final String greetings, final TeaSession session) throws IOException {
	  									System.out.println("Input====="+greetings);
            System.out.println("Session Id ====="+session.id());
        				return "Hello " + greetings;
    }
    
    public static void main(final String[] args) throws Exception {
        TeaAgentServer server = new TeaAgentServer("HelloWorldAgent", "1.1","Hello World Agent", "localhost", 1234,
                                   "/helloworldagent", true);
        server.setAgentId("test");
        server.registerInstance(new HelloWorldAgent());
        server.addEventListener(new HelloSessionListener());
        server.start();
        server.autoRegisterAgent("http://localhost:8777/tea");
        System.out.println("Agent Started at with changes: http://localhost:1234/helloworldagent");

    }
      
    public static class HelloSessionListener implements TeaSessionListener {
        
        public void onSessionDestroyed(final TeaSessionEvent event) {
            String id = event.getTeaSession().id();
            System.out.println("Session destroyed " + id);
        }
                                    
    }

}