Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » Unregister from EventBroker
Unregister from EventBroker [message #1051467] Sun, 28 April 2013 17:07 Go to next message
Eclipse UserFriend
Can I unregister some method, which is annotated with:
@Inject
public void handleEvent(@UIEventTopic(EVENT_TOPIC_ID) final Object object
Re: Unregister from EventBroker [message #1051704 is a reply to message #1051467] Mon, 29 April 2013 02:09 Go to previous messageGo to next message
Eclipse UserFriend
You can't do that with injection if you need to dynamically deregister
you need to make use of the IEventBroker directly.

Tom

On 28.04.13 23:07, Alex Kipling wrote:
> Can I unregister some method, which is annotated with:
>
> @Inject
> public void handleEvent(@UIEventTopic(EVENT_TOPIC_ID) final Object object
>
Re: Unregister from EventBroker [message #1051746 is a reply to message #1051704] Mon, 29 April 2013 03:21 Go to previous messageGo to next message
Eclipse UserFriend
Do I understand correctly, that it is not possible to deregister methods, which I registered using injections?
Is it right, that I only can deregister, if I obtained an EventHandler object during subscribtion?
//can deregister
EventHandler eventHandler = new EventHandler() {
    @Override
    public void handleEvent(Event event) {
        System.out.println("LifeCycleManager: UILifeCycle.PERSPECTIVE_SAVED");
    }
};
broker.subscribe(UIEvents.UILifeCycle.PERSPECTIVE_SAVED,eventHandler);
broker.unsubscribe(eventHandler);



//can not deregister? 
@Inject
public void handleEvent(@UIEventTopic(EVENT_TOPIC_ID) final Object object){
  ...
}
//can I retrieve the EventHandler for the method [b]handleEvent[/b] in ordr to unsubscribe it?



Or is it somehow possible to obtain the EventHandler for the @Inject annotated handleEvent method ,
for passing it to the broker.unsubscribe(eventHandler); ?
Re: Unregister from EventBroker [message #1051825 is a reply to message #1051746] Mon, 29 April 2013 05:04 Go to previous messageGo to next message
Eclipse UserFriend
You can not deregister 'manually' if you use DI subscribing (of course it will be disposed when your subscriber is disposed). You can deregister if you use direct subscribing.
Re: Unregister from EventBroker [message #1051826 is a reply to message #1051746] Mon, 29 April 2013 05:00 Go to previous messageGo to next message
Eclipse UserFriend
[...]

> Or is it somehow possible to obtain the EventHandler for the @Inject
> annotated handleEvent method , for passing it to the
> broker.unsubscribe(eventHandler); ?

Correct with DI you can not unsubscribe.

Tom
Re: Unregister from EventBroker [message #1075719 is a reply to message #1051467] Mon, 29 July 2013 19:52 Go to previous messageGo to next message
Eclipse UserFriend
hello

this topic is still relevant, is that it is always impossible to unsubscribe from event registered with dependency injection
Re: Unregister from EventBroker [message #1075813 is a reply to message #1075719] Tue, 30 July 2013 01:48 Go to previous messageGo to next message
Eclipse UserFriend
In theory, the following should have worked, but the handleEvent method is still called even if the closure was uninjected:

	@PostConstruct
	public void initEventsListener(final IEclipseContext ec) {
		Object closure = new Object() {
			int i = 0;

			@Inject
			public void handleEvent(@UIEventTopic("*") final Object object) {
				System.out.println(object);
				if (i++ > 3) {
					ContextInjectionFactory.uninject(this, ec);
				}
			}
		};
		ContextInjectionFactory.inject(closure, ec);
	}


AIT YAHIA Idir wrote on Tue, 30 July 2013 01:52
hello

this topic is still relevant, is that it is always impossible to unsubscribe from event registered with dependency injection

Re: Unregister from EventBroker [message #1076163 is a reply to message #1075813] Tue, 30 July 2013 16:56 Go to previous message
Eclipse UserFriend
thank you for your reply, I will try to make this work, I goes to write a tutorial about the event system in Eclipse 4 and it would be interesting to keep informing readers on this topic
Previous Topic:Open dynamically a part
Next Topic:Separate Styling for different Windows
Goto Forum:
  


Current Time: Fri Jul 04 05:45:58 EDT 2025

Powered by FUDForum. Page generated in 0.04538 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top