Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Monitor task executed multiple times

When I deploy the task to the server, the pagechange function is executed three times (I think there may be a time limit, otherwise it will be executed more times).

public class PageChangesListener  implements  InitializingBean, DisposableBean {

@Inject
private SubmitKnowledgeDaoImpl submitKnowledgeDao;

@Inject
private SubmittedPageIdDaoImpl submittedPageIdDao;


@ConfluenceImport
private EventPublisher eventPublisher;

private final static Logger logger = LoggerFactory.getLogger("atlassian.plugin");

@Inject
public PageChangesListener(final EventPublisher eventPublisher) {

this.eventPublisher = eventPublisher;
}

@Override
public void afterPropertiesSet() {
this.eventPublisher.register(this);
}

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

@EventListener
public void pageChange(PageUpdateEvent pageUpdateEvent) {
logger.info("发生页面修改事件");
long pageId = pageUpdateEvent.getPage().getId();
String title = pageUpdateEvent.getPage().getTitle();
String author = pageUpdateEvent.getPage().getCreator().getName();
Integer cid = null;
String content = pageUpdateEvent.getContent().getBodyAsString();
SubmitToKnowledgeDatabaseBean submitToKnowledgeDatabaseBean = new SubmitToKnowledgeDatabaseBean();
submitToKnowledgeDatabaseBean.setCid(cid);
submitToKnowledgeDatabaseBean.setPageId(pageId);
submitToKnowledgeDatabaseBean.setContent(content);
submitToKnowledgeDatabaseBean.setTitle(title);
submitToKnowledgeDatabaseBean.setAuthorName(author);
try {

Long timeStamp = System.currentTimeMillis() / 1000;
Integer authorId = submitKnowledgeDao.getAuthorIdByName(submitToKnowledgeDatabaseBean.getAuthorName());


if (submittedPageIdDao.pageHasSubmittedToKnowledge(submitToKnowledgeDatabaseBean.getPageId())) {
logger.info("本页面已经提交过知识库,准备更新知识库");
//已经提交过

Long did = submittedPageIdDao.getCidOfPage(submitToKnowledgeDatabaseBean.getPageId());
submitToKnowledgeDatabaseBean.setCid(submitKnowledgeDao.getCidByDid(did));


logger.info(did + "");

boolean tag = submitKnowledgeDao.updatePageContent(did, submitToKnowledgeDatabaseBean.getCid()
, submitToKnowledgeDatabaseBean.getTitle(), submitToKnowledgeDatabaseBean.getContent(), timeStamp);
if (tag) {
tag = submitKnowledgeDao.updateLink(submitToKnowledgeDatabaseBean.getCid(), did);
if (tag) {
tag = submitKnowledgeDao.updateWIKIEditions(did, submitToKnowledgeDatabaseBean.getCid()
, submitToKnowledgeDatabaseBean.getAuthorName(), authorId, timeStamp,
"", submitToKnowledgeDatabaseBean.getTitle(), submitToKnowledgeDatabaseBean.getContent());
logger.info("成功更新知识库");

}
}
}
} catch (Exception e) {
logger.info(e.getMessage());
e.printStackTrace();
}
}
}

And throw such an exception


java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at com.fr.plugin.confluence.listener.page.impl.PageUpdateListener.getLastPageBean(PageUpdateListener.java:31)
at com.fr.plugin.confluence.bean.compare.ComparedPageBean.<init>(ComparedPageBean.java:29)
at com.fr.plugin.confluence.listener.PageEventListener.handleEvent(PageEventListener.java:35)
at com.atlassian.event.legacy.LegacyListenerHandler$LegacyListenerInvoker.invoke(LegacyListenerHandler.java:51)
at com.atlassian.confluence.event.ConfluenceListenerHandlersConfiguration$TimedListenerInvoker.invoke(ConfluenceListenerHandlersConfiguration.java:96)
at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.lambda$run$0(ConfluenceEventDispatcher.java:93)
at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$doInRequestContext$0(VCacheRequestContextOperations.java:50)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:84)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:68)
at com.atlassian.confluence.vcache.VCacheRequestContextOperations.doInRequestContext(VCacheRequestContextOperations.java:49)
at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.run(ConfluenceEventDispatcher.java:93)
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:85)
at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:227)
at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:112)
at com.atlassian.confluence.event.TimingEventPublisher.publish(TimingEventPublisher.java:76)
at com.atlassian.confluence.pages.DefaultPageManager.publishUpdateEvent(DefaultPageManager.java:1703)
at com.atlassian.confluence.core.DefaultContentEntityManager.saveContentEntity(DefaultContentEntityManager.java:167)
at com.atlassian.confluence.pages.DefaultPageManager.saveContentEntity(DefaultPageManager.java:1410)
at sun.reflect.GeneratedMethodAccessor3757.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at com.atlassian.spring.interceptors.SpringProfilingInterceptor.invoke(SpringProfilingInterceptor.java:16)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at com.atlassian.confluence.util.profiling.ConfluenceMonitoringMethodInterceptor.invoke(ConfluenceMonitoringMethodInterceptor.java:36)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy148.saveContentEntity(Unknown Source)
at com.atlassian.confluence.links.DefaultRelatedContentRefactorer.persistBodyModificationToContent(DefaultRelatedContentRefactorer.java:254)
at com.atlassian.confluence.links.DefaultRelatedContentRefactorer.updateReferences(DefaultRelatedContentRefactorer.java:248)
at com.atlassian.confluence.links.DefaultRelatedContentRefactorer.updateReferrers(DefaultRelatedContentRefactorer.java:114)
at com.atlassian.confluence.links.DefaultRelatedContentRefactorer.updateReferrers(DefaultRelatedContentRefactorer.java:43)
at com.atlassian.confluence.links.RelatedContentRefactoringListener.handleEvent(RelatedContentRefactoringListener.java:62)
at sun.reflect.GeneratedMethodAccessor3310.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:42)
at com.atlassian.confluence.event.ConfluenceListenerHandlersConfiguration$TimedListenerInvoker.invoke(ConfluenceListenerHandlersConfiguration.java:96)
at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.lambda$run$0(ConfluenceEventDispatcher.java:93)
at com.atlassian.confluence.vcache.VCacheRequestContextOperations.lambda$doInRequestContext$0(VCacheRequestContextOperations.java:50)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContextInternal(VCacheRequestContextManager.java:84)
at com.atlassian.confluence.impl.vcache.VCacheRequestContextManager.doInRequestContext(VCacheRequestContextManager.java:68)
at com.atlassian.confluence.vcache.VCacheRequestContextOperations.doInRequestContext(VCacheRequestContextOperations.java:49)
at com.atlassian.confluence.event.ConfluenceEventDispatcher$VCacheRequestContextRunnableFactory$1.run(ConfluenceEventDispatcher.java:93)
at com.atlassian.event.internal.AsynchronousAbleEventDispatcher.dispatch(AsynchronousAbleEventDispatcher.java:85)
at com.atlassian.event.internal.EventPublisherImpl.invokeListeners(EventPublisherImpl.java:227)
at com.atlassian.event.internal.EventPublisherImpl.publish(EventPublisherImpl.java:112)
at com.atlassian.confluence.event.TimingEventPublisher.publish(TimingEventPublisher.java:76)
at com.atlassian.confluence.pages.DefaultPageManager.publishUpdateEvent(DefaultPageManager.java:1703)
at com.atlassian.confluence.core.DefaultContentEntityManager.saveContentEntity(DefaultContentEntityManager.java:186)
at com.atlassian.confluence.pages.DefaultPageManager.saveContentEntity(DefaultPageManager.java:1457)

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

412 views 16 13
Read article

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