VMware {code} Community
mayur_virtualiz
Enthusiast
Enthusiast

Remove Global Refresh Event Handler

Hello,

In vSphere UI, we can add Global refresh event handler at our views which are registered in our plugin.xml by following way.

[EventHandler(name="{com.vmware.core.events.DataRefreshInvocationEvent.EVENT_ID}")]

public function onGlobalRefreshRequest(event:DataRefreshInvocationEvent):void

{

}

1. But is there any way to unregister Global refresh event handler?

2. Is there any way to listen global refresh event at module class, which is not registered at plugin.xml?

     The reason behind, why i want to unregister Global refresh event handler is, It never free's the memory, hence for example if we have portlet at VM Store and Data Center, the global refresh call get invoked at both places at the same time.

Thanks in advance,

Mayur

Reply
0 Kudos
12 Replies
laurentsd
VMware Employee
VMware Employee

The [EventHandler ...] notation allows to register event handler, but there is no public API to unregister.  The reason is that it is not necessary, within your event handler you should be able to decide what to do.  For instance the chassis sample uses this Global Refresh event handler code to request data only when the view is visible.

/**

  * Handles the global refresh event when the user clicks the Refresh button.

  */

  [EventHandler(name="{com.vmware.core.events.DataRefreshInvocationEvent.EVENT_ID}")]

  public function onGlobalRefreshRequest(event:DataRefreshInvocationEvent):void {

     // _contextObject should be null if the view is not visible

     if (_contextObject != null) {

        requestData();

     } else {

        clearData();

     }

  }

Views which are not longer visible may still be active for a while.

I don't understand your 2nd question, can you give provide more details?

mayur_virtualiz
Enthusiast
Enthusiast

Hello Laurentsd,

Sorry for late reply,

So about 2nd question, well what ever class names we write in plugin.xml all those classes and their mediators(if any) gets register or get enabled for handling global refresh event of the vmware.

Now, consider the class of which you don't have entry into plugin.xml but you want it to listen vmwares global refresh event.

So we can achieve it by dispatching "ObjectEvent.newAddition({YOUR_CLASSNAME})".

Regards.

Reply
0 Kudos
laurentsd
VMware Employee
VMware Employee

I still don't understand your use case (screen-shots would help).  Plugins insert views which are declared to the extension manager in plugin.xml.  The only other type of view a plugin can display are modal dialogs (popups) and those don't need to be notified of global refresh events since they are modal.

Let's say your plugin registers a view to extend Host > Monitor.  Your UI code controls the entire content of that view.  If you decide to popup other views within that UI, it is up to you to implement the logic of handling global refresh events.  Those events are available to the original view used to extend Host > Monitor.

Hope this helps.

Reply
0 Kudos
mayur_virtualiz
Enthusiast
Enthusiast

Hello Laurent,

You are correct about whatever view we register in plugin.xml they and their connecting classes gets power to handler GlobalRefreshEvent.

But my point was, Every plugin project (Flex plugin) has its main class in which we can register our "locales" and we get "webcontextpath". in chassis we have it with name "Chassisui.mxml".

That main class we don't register into plugin.xml and hence it fails to handler global refresh handler event.

That is why, we need to create on plain Action Script class which must get initialized in out main class and to enable that class to handle global refresh event we need to dispatch "ObjectEvent.newAddition({YOUR_CLASSNAME})".

Regards,

Mayur Mankar

Reply
0 Kudos
laurentsd
VMware Employee
VMware Employee

Why do you want that main class to handle GlobalRefresh?  Again, a global refresh event should only be handled by individual views.   A more detailed explanation of your use case and screen shots would help me understand what you are trying to do.

Reply
0 Kudos
Peter_Ivanov
VMware Employee
VMware Employee

I could image a use case with cache in the Flex and one would like to clear/invalidate on global refresh. Mayur, is this your case?

Reply
0 Kudos
Peter_Ivanov
VMware Employee
VMware Employee

2. Is there any way to listen global refresh event at module class, which is not registered at plugin.xml?

In the chassis-ui there is a class ChassisEventManager. It contains the following code in its constructor:

FlexGlobals.topLevelApplication.dispatchEvent(ObjectEvent.newAddition(this));

Please note that this is a singleton. You should be extra careful when registering directly event listeners because it is easy to cause leaks.

1. But is there any way to unregister Global refresh event handler?

You can use Object.newRemoval

Reply
0 Kudos
mayur_virtualiz
Enthusiast
Enthusiast

yes peter

Reply
0 Kudos
mayur_virtualiz
Enthusiast
Enthusiast

Thanks Peter,

I am aware of this "Object.newRemoval".

But I actually don't know when to use it.

1. I have registered my custom actionscript class into vmware environment, to provide singleTone "Global Refresh" event handler.

2. when ever "Global refresh" event get dispatched from VMware framework, that action script class listens it and dispatch my custom event now.

     So in this way, i can make my components/views to remove all registered events, to make it easier for garbage collector.

3. But I don't actually know when to use "Object.newRemoval"

Regards,

Mayur Mankar

Reply
0 Kudos
Peter_Ivanov
VMware Employee
VMware Employee

Hi Mayur,

The idea of Object.newAddition and Object.newRemoval is to register to the message bus, to dispatch some event (typically data request) and when you are done with your job (e.g. receive the response) to unregister from the message bus.

2. when ever "Global refresh" event get dispatched from VMware framework, that action script class listens it and dispatch my custom event now.

     So in this way, i can make my components/views to remove all registered events, to make it easier for garbage collector.

Why would you do that on refresh? You may never get this event; it is up to the end user to click that refresh button.

What if your views are visible at that time?

You should use weak references when registering listeners.

Another thing that you can use in your Mediator classes - when the view is removed from the stage, null value will be injected in the mediator.

If you look at the ChassisSummaryViewMediator (chassis-ui flex sample), it has setter called "view":

public function set view(value:ChassisSummaryView):void {

   _view = value;

}

This setter will be invoked with "null" value when the view is disposed.

So you can do something like this:

public function set view(value:ChassisSummaryView):void {

   if  (_view != null && _view != value} {

     // This means that the setter is invoked for second time.

     // Remove the listeners from _view here

     _view.removeEventLister...

   }

   _view = value;

   if (_view != null) {

       // add the event listeners here

   }    

}

This is how you should register/unregister your listeners.

Hope that helps!

Reply
0 Kudos
mayur_virtualiz
Enthusiast
Enthusiast

Thanks Peter_Ivanov

Sorry for late reply,

I am registering and removing events same as you said.

What my point was, I am not listening vmwares global refresh handler event at every mediator of my plugin.

I had created separate action script class, which handles global refresh event of vmware and then I am dispatching my own custom event.

Thanks for your help

Reply
0 Kudos
Peter_Ivanov
VMware Employee
VMware Employee

In this case you have no way to remove your event listener. The current architecture loads the plugins in the browser, but never unloads them (I am talking about the Flex code).

So once your class is created and registered to the message bus, there is no way and no need for you to unregister it. Please make sure that you don't perform some heavy processing or data retrieval if your views are not visible for the user.

Reply
0 Kudos