2016-06-17 4 views
0

Liferay 6.2 GA6でDLFileEntry用のカスタムモデルリスナーを作成しました。ただし、DLFileEntryに変更が加えられていない場合でも、onAfterUpdateメソッドは繰り返し呼び出されます。Liferayモデルリスナー - 更新後のハンドラーループ

私は状況を説明してみましょう:

  1. ファイルエントリはonAfterUpdateメソッドがトリガーされるのLiferay
  2. におけるコンテンツ管理で変更される(これはOKです)
  3. onAfterUpdate方法が再度起動され、もう一度 - このエントリーに更新がない場合でも、

私は(予想外の)アップデートイベントha ppenes。 onAfterUpdateは私がportal.properties docs pageでbufferend増分についてdocumenantationを読んだBufferedIncrementRunnableクラス

java.lang.Exception: Stack trace 
     at java.lang.Thread.dumpStack(Thread.java:1365) 
     at eu.package.hook.model.listener.DLFileEntryModelListener.onAfterUpdate(DLFileEntryModelListener.java:63) 
     at eu.package.hook.model.listener.DLFileEntryModelListener.onAfterUpdate(DLFileEntryModelListener.java:32) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67) 
     at com.sun.proxy.$Proxy865.onAfterUpdate(Unknown Source) 
     at com.liferay.portal.service.persistence.impl.BasePersistenceImpl.update(BasePersistenceImpl.java:340) 
     at com.liferay.portlet.documentlibrary.service.impl.DLFileEntryLocalServiceImpl.incrementViewCounter(DLFileEntryLocalServiceImpl.java:1450) 
     at sun.reflect.GeneratedMethodAccessor2034.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
     at java.lang.reflect.Method.invoke(Method.java:606) 
     at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115) 
     at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62) 
     at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51) 
     at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111) 
     at com.liferay.portal.increment.BufferedIncreasableEntry.proceed(BufferedIncreasableEntry.java:48) 
     at com.liferay.portal.increment.BufferedIncrementRunnable.run(BufferedIncrementRunnable.java:65) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:745) 

によってトリガーされるincrementViewCounter(..)方法、によってトリガーされるように見えます。この機能を無効にすることはお勧めしません。

モデルリスナーメソッドのDLFileEntryオブジェクトに関連する変更が加えられているかどうかをチェックすることも考えました。 incrementViewCounterメソッドによってトリガーされたときに、onAfterUpdateメソッドをバイパスするように設定できる構成があるかどうかを確認したかっただけです。

何か助けていただければ幸いです。

アップデート:更新方法の後に

:ここ

private void createMessage(DLFileEntry model, String create) { 
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); 
    jsonObject.put("action", create); 
    jsonObject.put("id", model.getFileEntryId()); 
    MessageBusUtil.sendMessage(SUPIN_MESSAGE_LISTENER_DESTINATION, jsonObject); 
} 


@Override 
public void onAfterUpdate(DLFileEntry model) throws ModelListenerException { 
    if (LOG.isTraceEnabled()) { 
     URL[] urls = ((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs(); 
     LOG.trace("Current thread classpath is: " + StringUtils.join(urls, ",")); 
    } 
    LogMF.info(LOG, "File entry on update event - id {0}" , new Object[]{model.getFileEntryId()}); 
    Thread.dumpStack(); 
    createMessage(model, UPDATE); 

} 

は更新アクションの後に実行メッセージリスナ(メッセージ・バス)である:

private void createOrUpdate(DLFileEntry model, String createOrUpdate) { 
    try { 
     initPermissionChecker(model); 

     LOG.info("Document " + model.getFileEntryId() + " " + createOrUpdate + "d in Liferay. Creating entry in Safe."); 
     long documentInSafe; 
     if (UPDATE.equalsIgnoreCase(createOrUpdate)) { 
      documentInSafe = (long) model.getExpandoBridge().getAttribute(EXPANDO_SAFE_DOCUMENT_ID); 
      if (documentInSafe > 0) { 
       safeClient.updateDocumentInSafe(model); 
      } else { 
       documentInSafe = safeClient.createDocumentInSafe(model); 
      } 
     } else { 
      documentInSafe = safeClient.createDocumentInSafe(model); 
     } 
     LOG.info("Document " + createOrUpdate +"d successfully with id " + documentInSafe); 
     saveSafeIDToExpando(model, documentInSafe); 
    } catch (Exception e) { 
     LOG.error("Unable to safe ID of document in Safe", e); 
    } 
} 

private void saveSafeIDToExpando(DLFileEntry model, long documentInSafe) throws SystemException { 
    try { 
     ExpandoTable table = ExpandoTableLocalServiceUtil.getDefaultTable(model.getCompanyId(), DLFileEntry.class.getName()); 
     ExpandoColumn column = ExpandoColumnLocalServiceUtil.getColumn(table.getTableId(), EXPANDO_SAFE_DOCUMENT_ID); 
     ExpandoValueLocalServiceUtil.addValue(model.getCompanyId(), table.getTableId(), column.getColumnId(), model.getClassPK(), String.valueOf(documentInSafe)); 
     LOG.info("ID of document in Safe updated in expando attribute"); 
    } catch (PortalException e) { 
     LOG.error("Unable to save Safe document ID in expando." , e); 
     ; 
    } 
} 

private void initPermissionChecker(DLFileEntry model) throws Exception { 
    User safeAdminUser = UserLocalServiceUtil.getUserByScreenName(model.getCompanyId(), SAFE_ADMIN_SCREEN_NAME); 
    PermissionChecker permissionChecher = PermissionCheckerFactoryUtil.create(safeAdminUser); 
    PermissionThreadLocal.setPermissionChecker(permissionChecher); 
    PrincipalThreadLocal.setName(safeAdminUser.getUserId()); 
    CompanyThreadLocal.setCompanyId(model.getCompanyId()); 
    LOG.info("Permission checker successfully initialized."); 
} 
+1

カスタムonAfterUpdateメソッドのコードは表示できますか? –

+0

@DanieleBaggio - 返信いただきありがとうございます。私は自分の投稿にカスタムコードを追加しました。 onAfterUpdateを繰り返しトリガーするExpandoValueServiceが疑われましたが、これはそうではありません(私はそれをテストしました)。 – shimon001

答えて

0

私がお勧めこれがあなたのケースを解決するかどうかはわかりません。

あなた自身のメソッドの本体をonAfterUpdateに変更しました。

TransactionCommitCallbackRegistryUtilを使用すると、後続のcreateMessageロジックからモデル更新要求を切り離すことができます。

public void onAfterUpdate(DLFileEntry model) throws ModelListenerException { 

    TransactionCommitCallbackRegistryUtil.registerCallback(new Callable() { 

     @Override 
     public Void call() throws Exception { 
       createMessage(model, UPDATE); 
    } 
} 
+0

提案していただきありがとうございますが、これは役に立ちませんでした。 onAfterUpdateが何度もトリガされます:( – shimon001

関連する問題