Skip to content

Commit

Permalink
File module abstract interface. Docean lookup supports configuration…
Browse files Browse the repository at this point in the history
… items.(close #721) (#722)
  • Loading branch information
caochengxiang committed Sep 20, 2023
2 parents 0c781b6 + ea2fe57 commit 5e5c1d8
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public boolean start(Ioc ioc) {
if (!disable) {
new Thread(() -> Safe.run(() -> {
DoceanHttpServer server = new DoceanHttpServer(HttpServerConfig.builder()
.cookie(cookie)
.port(Integer.valueOf(config.get("docean_http_server_port", "8080")))
.websocket(false)
.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.xiaomi.mione.plugin.dao;

/**
* @author [email protected]
* @date 2023/9/20 14:57
*/
public class Run {


public static void main(String[] args) {
System.out.println("run");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.xiaomi.youpin.docean.plugin.test;

import com.google.common.collect.Maps;
import com.xiaomi.youpin.docean.Aop;
import com.xiaomi.youpin.docean.Ioc;
import com.xiaomi.youpin.docean.plugin.test.lookup.LookupService;
import org.junit.Test;

import java.util.stream.IntStream;

/**
* @author [email protected]
* @date 2023/9/20 13:55
*/
public class IocTest {


@Test
public void testLookup() {
Aop.ins().init(Maps.newLinkedHashMap());
Ioc.ins().init("com.xiaomi.youpin.docean.plugin.test.lookup", "com.xiaomi.youpin.docean.plugin.config");
LookupService ds = Ioc.ins().getBean(LookupService.class);
IntStream.range(0, 5).forEach(i -> {
com.xiaomi.youpin.docean.plugin.test.bo.Test dv = ds.g();
dv.setId(123);
System.out.println(dv.getId());
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.xiaomi.youpin.docean.plugin.test.lookup;

import com.xiaomi.youpin.docean.anno.Lookup;
import com.xiaomi.youpin.docean.anno.Service;
import com.xiaomi.youpin.docean.plugin.test.bo.Test;

/**
* @author [email protected]
* @date 2023/9/20 13:56
*/
@Service
public class LookupService {

@Lookup
public Test getTest() {
return null;
}


public Test g() {
return getTest();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Lookup {

String value() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package com.xiaomi.youpin.docean.interceptor;

import com.xiaomi.youpin.docean.Ioc;
import com.xiaomi.youpin.docean.anno.Lookup;
import com.xiaomi.youpin.docean.aop.AopContext;
import com.xiaomi.youpin.docean.aop.EnhanceInterceptor;
import com.xiaomi.youpin.docean.common.ReflectUtils;
import com.xiaomi.youpin.docean.common.StringUtils;

import java.lang.reflect.Method;

Expand All @@ -31,6 +34,15 @@ public class LookupInterceptor extends EnhanceInterceptor {
@Override
public Object after(AopContext context, Method method, Object res) {
Class<?> returnType = method.getReturnType();
Lookup lookUp = method.getAnnotation(Lookup.class);
String lookUpvalue = lookUp.value();
if (StringUtils.isNotEmpty(lookUpvalue)) {
if (lookUpvalue.startsWith("$")) {
String value = Ioc.ins().getBean(lookUpvalue);
lookUpvalue = value;
}
returnType = ReflectUtils.classForName(lookUpvalue);
}
return Ioc.ins().createBean(returnType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.IntStream;

/**
* @author [email protected]
Expand Down Expand Up @@ -153,6 +154,20 @@ public void testIoc44() {
}


@Test
public void testLookup() {
Aop.ins().init(Maps.newLinkedHashMap());
Ioc.ins().init("com.xiaomi.youpin.docean.test","com.xiaomi.youpin.docean.plugin.config");
DemoService ds = Ioc.ins().getBean(DemoService.class);
IntStream.range(0, 5).forEach(i -> {
DemoVo dv = ds.demoVo();
System.out.println(dv.getId());
dv.setId(System.currentTimeMillis()+"");
System.out.println(ds.demoVo());
});
}


@Test
public void testIoc() {
LinkedHashMap<Class, EnhanceInterceptor> m = Maps.newLinkedHashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public String vo() {
return demoVo().toString();
}

@Lookup
// @Lookup("com.xiaomi.youpin.docean.test.demo.DemoVo")
@Lookup("$demoVo")
public DemoVo demoVo() {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions jcommon/docean/src/test/resources/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ http_port=9999
cglib=true
download_file_path=/tmp/v

demoVo=com.xiaomi.youpin.docean.test.demo.DemoVo



19 changes: 19 additions & 0 deletions jcommon/file/src/main/java/com/xiaomi/mone/file/ILogFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.xiaomi.mone.file;

import java.io.IOException;

/**
* @author [email protected]
* @date 2023/9/20 10:39
*/
public interface ILogFile {

void readLine() throws IOException;

void setStop(boolean stop);

void setReOpen(boolean reOpen);

void initLogFile(String file, ReadListener listener, long pointer, long lineNumber);

}
17 changes: 15 additions & 2 deletions jcommon/file/src/main/java/com/xiaomi/mone/file/LogFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* @author [email protected]
*/
@Slf4j
public class LogFile {
public class LogFile implements ILogFile{

@Getter
private final String file;
private String file;

private MoneRandomAccessFile raf;

Expand Down Expand Up @@ -50,6 +50,10 @@ public class LogFile {

private static final int LINE_MAX_LENGTH = 50000;

public LogFile() {

}

public LogFile(String file, ReadListener listener) {
this.file = file;
this.md5 = md5(file);
Expand Down Expand Up @@ -156,6 +160,15 @@ public void readLine() throws IOException {
}
}

@Override
public void initLogFile(String file, ReadListener listener, long pointer, long lineNumber) {
this.file = file;
this.md5 = md5(file);
this.listener = listener;
this.pointer = pointer;
this.lineNumber = lineNumber;
}

private String lineCutOff(String line) {
if (null != line) {
//todo 大行文件先临时截断
Expand Down

0 comments on commit 5e5c1d8

Please sign in to comment.