atmosphere
  1. atmosphere
  2. ATMOSPHERE-123

Listener for BroadcasterLifeCyclePolicy

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.7.2
    • Fix Version/s: 0.7.2
    • Component/s: None
    • Labels:
      None

      Description

      Enable user to do post-destroy or post-timeout resource cleanup for a Broadcaster. I'm proposing something like

      public interface BroadcasterLifeCyclePolicyListener

      { void onEmpty(); void onIdle(); void onDestroy(); }

      This will get registered with the Builder: new BroadcasterLifeCyclePolicy.Builder().policy(ATMOSPHERE_RESOURCE_POLICY.EMPTY_DESTROY).listener(MyBroadcasterLifeCyclePolicyListener).build();

      In the above case, both onEmpty and onDestroy will get called when no AtmosphereResources are attached to the Broadcaster. If EMPTY would have been used, only onEmpty would have been triggered. Similar behaviour happens to IDLE and IDLE_DESTROY.

        Activity

        Hide
        fmoga added a comment -

        What do you think about this new feature? I would use it to unregister broadcasters when they timeout. Seems useful for resource cleanup outside of Atmosphere internals.

        Show
        fmoga added a comment - What do you think about this new feature? I would use it to unregister broadcasters when they timeout. Seems useful for resource cleanup outside of Atmosphere internals.
        Hide
        jfarcand added a comment -

        Salut, I like the idea. Working on it today or early next week. Will try to include it in 0.7.2.

        Show
        jfarcand added a comment - Salut, I like the idea. Working on it today or early next week. Will try to include it in 0.7.2.
        Show
        jfarcand added a comment - Added support https://github.com/Atmosphere/atmosphere/commit/9757bc2adfb6f5798ae13f47613925ffd77a7667
        Hide
        fmoga added a comment -

        Tried the new support but callbacks don't get invoked. Might be due to http://java.net/jira/browse/ATMOSPHERE-120 .

        Show
        fmoga added a comment - Tried the new support but callbacks don't get invoked. Might be due to http://java.net/jira/browse/ATMOSPHERE-120 .
        Hide
        jfarcand added a comment -

        The following code snipped works fine for me with Atmosphere 0.8

        		System.out.println("Client subscribed.");
        		Broadcaster broadcaster = new JerseyBroadcaster();
        		BroadcasterLifeCyclePolicy policy = new BroadcasterLifeCyclePolicy.Builder()
        				.policy( BroadcasterLifeCyclePolicy.ATMOSPHERE_RESOURCE_POLICY.EMPTY_DESTROY).build();
        		broadcaster.setBroadcasterLifeCyclePolicy(policy);
        
                broadcaster.addBroadcasterLifeCyclePolicyListener( new BroadcasterLifeCyclePolicyListener()
                {
                    public void onEmpty()
                    {
                       System.out.println("onEmpty");
                    }
        
                    public void onIdle()
                    {
                        System.out.println("onIdle");
                    }
        
                    public void onDestroy()
                    {
                        System.out.println("onDestroy");
                    }
                } );
        
        		return new SuspendResponse.SuspendResponseBuilder<String>()
        				.broadcaster(broadcaster).outputComments(true)
                        .resumeOnBroadcast( true )
        				.addListener(new EventsLogger()).build();
        

        Can you described what you are doing? Sorry for the trouble!

        Show
        jfarcand added a comment - The following code snipped works fine for me with Atmosphere 0.8 System.out.println("Client subscribed."); Broadcaster broadcaster = new JerseyBroadcaster(); BroadcasterLifeCyclePolicy policy = new BroadcasterLifeCyclePolicy.Builder() .policy( BroadcasterLifeCyclePolicy.ATMOSPHERE_RESOURCE_POLICY.EMPTY_DESTROY).build(); broadcaster.setBroadcasterLifeCyclePolicy(policy); broadcaster.addBroadcasterLifeCyclePolicyListener( new BroadcasterLifeCyclePolicyListener() { public void onEmpty() { System.out.println("onEmpty"); } public void onIdle() { System.out.println("onIdle"); } public void onDestroy() { System.out.println("onDestroy"); } } ); return new SuspendResponse.SuspendResponseBuilder<String>() .broadcaster(broadcaster).outputComments(true) .resumeOnBroadcast( true ) .addListener(new EventsLogger()).build(); Can you described what you are doing? Sorry for the trouble!
        Hide
        fmoga added a comment -

        From what I see, you're using the sample from ATMOSPHERE-120. The above change doesn't show onEmpty in my logs when a browser client disconnects (using Tomcat 7.0.14).

        Can you package and attach the source of your sample or a war file?

        Thanks

        Show
        fmoga added a comment - From what I see, you're using the sample from ATMOSPHERE-120 . The above change doesn't show onEmpty in my logs when a browser client disconnects (using Tomcat 7.0.14). Can you package and attach the source of your sample or a war file? Thanks
        Hide
        fmoga added a comment -

        It now works with the latest 0.8-SNAPSHOT from the maven repo. Great stuff! Thanks.

        Show
        fmoga added a comment - It now works with the latest 0.8-SNAPSHOT from the maven repo. Great stuff! Thanks.

          People

          • Assignee:
            Unassigned
            Reporter:
            fmoga
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: