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 votes

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
Community showcase
Posted Thursday in Jira

Continuous visibility with the new Jira Software Cloud and Bitbucket Cloud integration

Hey Atlassian community, I am a PM on the Bitbucket Cloud team and I am excited to share that we just released an improvement to the Jira Software and Bitbucket Cloud integration. With the newly im...

108 views 0 4
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