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

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

573 views 25 15
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