spring core proxy : log trace v1 - interface proxy
This commit is contained in:
@@ -2,11 +2,16 @@ package com.example.proxy;
|
||||
|
||||
import com.example.proxy.config.AppV1Config;
|
||||
import com.example.proxy.config.AppV2Config;
|
||||
import com.example.proxy.config.v1_proxy.InterfaceProxyConfig;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import com.example.proxy.trace.logtrace.ThreadLocalLogTrace;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Import({AppV1Config.class, AppV2Config.class})
|
||||
//@Import({AppV1Config.class, AppV2Config.class})
|
||||
@Import(InterfaceProxyConfig.class)
|
||||
@SpringBootApplication(scanBasePackages = "com.example.proxy.app")
|
||||
public class ProxyApplication {
|
||||
|
||||
@@ -14,4 +19,8 @@ public class ProxyApplication {
|
||||
SpringApplication.run(ProxyApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LogTrace logTrace() {
|
||||
return new ThreadLocalLogTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.example.proxy.config.v1_proxy;
|
||||
|
||||
import com.example.proxy.app.v1.*;
|
||||
import com.example.proxy.config.v1_proxy.interface_proxy.OrderControllerInterfaceProxy;
|
||||
import com.example.proxy.config.v1_proxy.interface_proxy.OrderRepositoryInterfaceProxy;
|
||||
import com.example.proxy.config.v1_proxy.interface_proxy.OrderServiceInterfaceProxy;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class InterfaceProxyConfig {
|
||||
@Bean
|
||||
public OrderControllerV1 orderController(LogTrace logTrace) {
|
||||
OrderControllerV1Impl controllerImpl = new OrderControllerV1Impl(orderService(logTrace));
|
||||
return new OrderControllerInterfaceProxy(controllerImpl, logTrace);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OrderServiceV1 orderService(LogTrace logTrace) {
|
||||
OrderServiceV1Impl serviceImpl = new OrderServiceV1Impl(orderRepository(logTrace));
|
||||
return new OrderServiceInterfaceProxy(serviceImpl, logTrace);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OrderRepositoryV1 orderRepository(LogTrace logTrace) {
|
||||
OrderRepositoryV1Impl repositoryImpl = new OrderRepositoryV1Impl();
|
||||
return new OrderRepositoryInterfaceProxy(repositoryImpl, logTrace);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.proxy.config.v1_proxy.interface_proxy;
|
||||
|
||||
import com.example.proxy.app.v1.OrderControllerV1;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class OrderControllerInterfaceProxy implements OrderControllerV1 {
|
||||
|
||||
private final OrderControllerV1 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
@Override
|
||||
public String request(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderController.request()");
|
||||
String result = target.request(itemId);
|
||||
logTrace.end(status);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noLog() {
|
||||
return target.noLog();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.example.proxy.config.v1_proxy.interface_proxy;
|
||||
|
||||
import com.example.proxy.app.v1.OrderRepositoryV1;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class OrderRepositoryInterfaceProxy implements OrderRepositoryV1 {
|
||||
|
||||
private final OrderRepositoryV1 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
@Override
|
||||
public void save(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderRepository.request()");
|
||||
target.save(itemId);
|
||||
logTrace.end(status);
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.example.proxy.config.v1_proxy.interface_proxy;
|
||||
|
||||
import com.example.proxy.app.v1.OrderServiceV1;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class OrderServiceInterfaceProxy implements OrderServiceV1 {
|
||||
|
||||
private final OrderServiceV1 target;
|
||||
private final LogTrace logTrace;
|
||||
|
||||
@Override
|
||||
public void orderItem(String itemId) {
|
||||
TraceStatus status = null;
|
||||
try {
|
||||
status = logTrace.begin("OrderService.orderItem()");
|
||||
target.orderItem(itemId);
|
||||
logTrace.end(status);
|
||||
} catch (Exception e) {
|
||||
logTrace.exception(status, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package hello.proxy.trace;
|
||||
package com.example.proxy.trace;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hello.proxy.trace;
|
||||
package com.example.proxy.trace;
|
||||
|
||||
public class TraceStatus {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package hello.proxy.trace.callback;
|
||||
package com.example.proxy.trace.callback;
|
||||
|
||||
public interface TraceCallback<T> {
|
||||
T call();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package hello.proxy.trace.callback;
|
||||
package com.example.proxy.trace.callback;
|
||||
|
||||
import hello.proxy.trace.TraceStatus;
|
||||
import hello.proxy.trace.logtrace.LogTrace;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
|
||||
public class TraceTemplate {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package hello.proxy.trace.logtrace;
|
||||
package com.example.proxy.trace.logtrace;
|
||||
|
||||
import hello.proxy.trace.TraceId;
|
||||
import hello.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.TraceId;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package hello.proxy.trace.logtrace;
|
||||
package com.example.proxy.trace.logtrace;
|
||||
|
||||
import hello.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
|
||||
public interface LogTrace {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package hello.proxy.trace.logtrace;
|
||||
package com.example.proxy.trace.logtrace;
|
||||
|
||||
import hello.proxy.trace.TraceId;
|
||||
import hello.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.TraceId;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package hello.proxy.trace.template;
|
||||
package com.example.proxy.trace.template;
|
||||
|
||||
import hello.proxy.trace.TraceStatus;
|
||||
import hello.proxy.trace.logtrace.LogTrace;
|
||||
import com.example.proxy.trace.TraceStatus;
|
||||
import com.example.proxy.trace.logtrace.LogTrace;
|
||||
|
||||
public abstract class AbstractTemplate<T> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user