Open topic with navigation

TIBCO® Enterprise Administrator 2.4.2

# 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);
            }

        }

    }

    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);
            }

        }

    }

    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);
            }

        }

    }

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Enterprise Administrator

Copyright © 1996-2025. Cloud Software Group, Inc. All Rights Reserved.