It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

EventListener multiple firing Edited

Hi!

I use EventListerer and I have multiple fires for issueCreated event. Other events (e.g. issueDeleted) fires one time.

My code:

import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.JiraListener;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.issue.IssueEventListener;
import com.atlassian.jira.issue.Issue;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

@Scanned
public class TestListener extends AbstractIssueEventListener implements InitializingBean, DisposableBean, IssueEventListener, JiraListener {
private static final Logger log = LoggerFactory.getLogger(TestListener.class);

@ComponentImport
private final EventPublisher eventPublisher;

public TestListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}

@Override
public void issueCreated(IssueEvent issueEvent) {
Issue issue = issueEvent.getIssue();
System.out.println("Issue " + issue.getKey() + " was created");
}

@Override
public void issueDeleted(IssueEvent issueEvent) {
Issue issue = issueEvent.getIssue();
System.out.println("Issue " + issue.getKey() + " was deleted");
}

@Override
public void destroy() throws Exception {
// unregister ourselves with the EventPublisher
eventPublisher.unregister(this);
}

@Override
public void afterPropertiesSet() throws Exception {
// register ourselves with the EventPublisher
eventPublisher.register(this);
}
}

I also have tried to write this without extending AbstractIssueEventListener but I had the same result.

Have you any ideas about this?

P.S.

I have modified my code. I've added static variable that counts fires. Now my issueCreated looks like this:

Override
public void issueCreated(IssueEvent issueEvent) {
Issue issue = issueEvent.getIssue();
System.out.println("Issue " + issue.getKey() + " was created: " + ++cnt);
System.out.println("--------");
}

And logs looks like this:

[INFO] [talledLocalContainer] Issue TEST-64 was created
[INFO] [talledLocalContainer] Issue TEST-64 was created: 2
[INFO] [talledLocalContainer] --------
[INFO] [talledLocalContainer] Issue TEST-64 was created

I think this is a bug...

2 answers

It is likely that you have an old version of the listener registered in your JIRA. Make sure you implement the "destroy" method to make sure the listener is unregistered on removal of the plugin.

As for the old listener that is still running, you might have to delete it from DB or code. I haven't come across that scenario, so it is just a guess :)

0 votes
Gilles G I'm New Here 3 hours ago

my code on confluence 5.9.14 :

(be careful , do not register this class with @Named because it will be fired twice )

public class MyEventListener implements InitializingBean, DisposableBean {


@ConfluenceImport
private final EventPublisher eventPublisher;

@ConfluenceImport
private final SpaceManager spaceManager;

@Inject
public MyEventListener (final EventPublisher eventPublisher, final SpaceManager spaceManager) {
super();
this.eventPublisher = eventPublisher;
this.spaceManager = spaceManager;
}

/* _____ LIFECYCLE _____ */
@Override
public void afterPropertiesSet() throws Exception
{
eventPublisher.register(this);
}

@Override
public void destroy() throws Exception
{
eventPublisher.unregister(this);
}

@EventListener
public void onEvent(ConfluenceEvent event) {

if (event.getSource() instanceof MyListenedAction) {
final MyListenedAction action = (MyListenedAction) event.getSource();
doSomething(action );
}
}


}

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Calling all Jira Cloud users! Give us feedback on our exploration of a new navigation.

Hi everyone! My name’s Matt and I’m a product manager at Atlassian. I work in the navigation & findability space for all our Jira Cloud products. We’ve been working on trying to improve the exp...

1,038 views 16 12
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you