mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
fix bean creation cycle problem
This commit is contained in:
parent
e1d369c744
commit
92269b2cfa
|
@ -5,6 +5,8 @@ import com.ctrip.zeus.service.report.ReportService;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -17,21 +19,31 @@ import javax.annotation.Resource;
|
||||||
@Component
|
@Component
|
||||||
public class ReportAspect implements Ordered {
|
public class ReportAspect implements Ordered {
|
||||||
|
|
||||||
|
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ReportService reportService;
|
private ReportService reportService;
|
||||||
|
|
||||||
@Around("execution(* com.ctrip.zeus.service.model.GroupRepository.*(..))")
|
@Around("execution(* com.ctrip.zeus.service.model.GroupRepository.*(..))")
|
||||||
public Object injectReportAction(ProceedingJoinPoint point) throws Throwable {
|
public Object injectReportAction(ProceedingJoinPoint point) throws Throwable {
|
||||||
String methodName = point.getSignature().getName();
|
String methodName = point.getSignature().getName();
|
||||||
|
boolean isNew;
|
||||||
switch (methodName) {
|
switch (methodName) {
|
||||||
case "add":
|
case "add":
|
||||||
|
isNew = true;
|
||||||
|
break;
|
||||||
case "update":
|
case "update":
|
||||||
|
isNew = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return point.proceed();
|
return point.proceed();
|
||||||
}
|
}
|
||||||
Object obj = point.proceed();
|
Object obj = point.proceed();
|
||||||
reportService.reportGroup((Group)obj);
|
try {
|
||||||
|
reportService.reportGroup((Group) obj, isNew);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("Fail to report group to queue.", ex);
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,5 @@ import com.ctrip.zeus.model.entity.Group;
|
||||||
*/
|
*/
|
||||||
public interface ReportService {
|
public interface ReportService {
|
||||||
|
|
||||||
void reportGroup(Group group) throws Exception;
|
void reportGroup(Group group, boolean isNew) throws Exception;
|
||||||
|
|
||||||
void sync() throws Exception;
|
|
||||||
|
|
||||||
boolean needSync() throws Exception;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.ctrip.zeus.service.report;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhoumy on 2015/7/10.
|
||||||
|
*/
|
||||||
|
public interface ReportSyncService {
|
||||||
|
|
||||||
|
void sync() throws Exception;
|
||||||
|
|
||||||
|
boolean needSync() throws Exception;
|
||||||
|
}
|
|
@ -10,17 +10,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component("mockReportService")
|
@Component("mockReportService")
|
||||||
public class MockReportService implements ReportService {
|
public class MockReportService implements ReportService {
|
||||||
@Override
|
@Override
|
||||||
public void reportGroup(Group group) throws Exception {
|
public void reportGroup(Group group, boolean isNew) throws Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sync() throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean needSync() throws Exception {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ctrip.zeus.service.report.impl;
|
||||||
|
|
||||||
|
import com.ctrip.zeus.service.report.ReportSyncService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by zhoumy on 2015/7/10.
|
||||||
|
*/
|
||||||
|
public class MockReportSyncService implements ReportSyncService {
|
||||||
|
@Override
|
||||||
|
public void sync() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean needSync() throws Exception {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,11 +3,12 @@
|
||||||
<entity name="report" table="report" alias="l" do-class="ReportDo">
|
<entity name="report" table="report" alias="l" do-class="ReportDo">
|
||||||
<query-defs>
|
<query-defs>
|
||||||
<query name="find-by-group" type="SELECT">
|
<query name="find-by-group" type="SELECT">
|
||||||
|
<param name="group-id"/>
|
||||||
<statement>
|
<statement>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
SELECT <FIELDS/>
|
SELECT <FIELDS/>
|
||||||
FROM <TABLE/>
|
FROM <TABLE/>
|
||||||
WHERE <FIELD name='group-id'/> = <FIELD name='group-id'/>
|
WHERE <FIELD name='group-id'/> = ${group-id}
|
||||||
]]>
|
]]>
|
||||||
</statement>
|
</statement>
|
||||||
</query>
|
</query>
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
SELECT <FIELDS/>
|
SELECT <FIELDS/>
|
||||||
FROM <TABLE/>
|
FROM <TABLE/>
|
||||||
WHERE <FIELD name='current-version'/> > <FIELD name='reported-version'/>
|
WHERE current_version > reported_version
|
||||||
]]>
|
]]>
|
||||||
</statement>
|
</statement>
|
||||||
</query>
|
</query>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<model model-package="com.ctrip.zeus.report" />
|
<model model-package="com.ctrip.zeus.report" enable-sax-parser="true" enable-json-parser="true"
|
||||||
|
enable-json-builder="true"/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue