Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Unregister from EventBroker
Unregister from EventBroker [message #1051467] Sun, 28 April 2013 21:07 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
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 06:09 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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 07:21 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
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 09: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 09:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

> 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 23:52 Go to previous messageGo to next message
AIT YAHIA Idir is currently offline AIT YAHIA IdirFriend
Messages: 39
Registered: April 2013
Member
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 05:48 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
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 20:56 Go to previous message
AIT YAHIA Idir is currently offline AIT YAHIA IdirFriend
Messages: 39
Registered: April 2013
Member
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: Thu Apr 25 12:56:21 GMT 2024

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

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

Back to the top