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...

1 answer

0 vote

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 :)

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,296 views 14 20
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot