完成DataFile功能
This commit is contained in:
parent
8d63c0e5f2
commit
24e9af5152
|
|
@ -67,6 +67,11 @@
|
|||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>data-carrier</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
@ -159,5 +164,14 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-wu-sheng-DataCarrier</id>
|
||||
<name>bintray</name>
|
||||
<url>http://dl.bintray.com/wu-sheng/DataCarrier</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -10,4 +10,9 @@ public class Config {
|
|||
|
||||
public static String DATA_FILE_INDEX_FILE_NAME = "data_file.index";
|
||||
}
|
||||
|
||||
|
||||
public static class DataFile {
|
||||
public static String BASE_PATH = "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/1.
|
||||
*/
|
||||
public class DataOperator {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.storage.data;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/4.
|
||||
*/
|
||||
public interface SpanData {
|
||||
long getTimestamp();
|
||||
|
||||
byte[] convertToByte();
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.a.eye.skywalking.storage.data;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/4.
|
||||
*/
|
||||
public class SpanDataBuilder {
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.a.eye.skywalking.storage.data;
|
||||
|
||||
import com.a.eye.datacarrier.consumer.IConsumer;
|
||||
import com.a.eye.skywalking.storage.data.file.DataFileWriter;
|
||||
import com.a.eye.skywalking.storage.data.index.IndexMetaInfo;
|
||||
import com.a.eye.skywalking.storage.data.index.IndexOperator;
|
||||
import com.a.eye.skywalking.storage.data.index.IndexOperatorFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SpanDataWriterConsumer implements IConsumer<SpanData> {
|
||||
|
||||
private DataFileWriter writer;
|
||||
|
||||
@Override
|
||||
public void consume(List<SpanData> list) {
|
||||
for (SpanData data : list) {
|
||||
IndexOperator operator = IndexOperatorFactory.get(data.getTimestamp());
|
||||
IndexMetaInfo metaInfo = writer.write(data.convertToByte());
|
||||
operator.update(metaInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(List<SpanData> list, Throwable throwable) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.storage.data.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/4.
|
||||
*/
|
||||
public class DataFileNotFoundException extends Exception {
|
||||
public DataFileNotFoundException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.storage.data.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/4.
|
||||
*/
|
||||
public class FileReaderCreateFailedException extends Throwable {
|
||||
public FileReaderCreateFailedException(String message, Exception e) {
|
||||
super(message, e);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.a.eye.skywalking.storage.data.file;
|
||||
|
||||
public class DataFile {
|
||||
|
||||
private static final long MAX_LENGTH = 3 * 1024 * 1024 * 1024;
|
||||
|
||||
private String name;
|
||||
private long currentLength;
|
||||
|
||||
public boolean overLimitLength() {
|
||||
return currentLength > MAX_LENGTH;
|
||||
}
|
||||
|
||||
|
||||
public long writeAndFlush(byte[] data) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data.file;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
public class DataFileOperator {
|
||||
|
||||
public int write(){
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object read(Object dataIndex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.a.eye.skywalking.storage.data.file;
|
||||
|
||||
import com.a.eye.skywalking.storage.data.exception.DataFileNotFoundException;
|
||||
import com.a.eye.skywalking.storage.data.exception.FileReaderCreateFailedException;
|
||||
import com.a.eye.skywalking.storage.data.index.IndexMetaInfo;
|
||||
|
||||
public class DataFileOperatorFactory {
|
||||
|
||||
public static DataFileReader newReader(IndexMetaInfo indexMetaInfo) throws FileReaderCreateFailedException {
|
||||
try {
|
||||
return new DataFileReader(indexMetaInfo);
|
||||
} catch (DataFileNotFoundException e) {
|
||||
throw new FileReaderCreateFailedException("Cannot create DataFileReader.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static DataFileWriter newWriter() {
|
||||
return new DataFileWriter();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,45 @@
|
|||
package com.a.eye.skywalking.storage.data.file;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
import com.a.eye.skywalking.storage.config.Config;
|
||||
import com.a.eye.skywalking.storage.data.exception.DataFileNotFoundException;
|
||||
import com.a.eye.skywalking.storage.data.index.IndexMetaInfo;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DataFileReader {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(DataFileReader.class);
|
||||
|
||||
private long offset;
|
||||
private int length;
|
||||
private String fileName;
|
||||
private FileInputStream reader;
|
||||
|
||||
public DataFileReader(IndexMetaInfo indexMetaInfo) throws DataFileNotFoundException {
|
||||
try {
|
||||
reader = new FileInputStream(new File(Config.DataFile.BASE_PATH, indexMetaInfo.getFileName()));
|
||||
this.offset = indexMetaInfo.getOffset();
|
||||
this.length = indexMetaInfo.getLength();
|
||||
this.fileName = indexMetaInfo.getFileName();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new DataFileNotFoundException(indexMetaInfo.getFileName() + " not found.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] read() {
|
||||
try {
|
||||
reader.getChannel().position(this.offset);
|
||||
byte[] dataByte = new byte[length];
|
||||
reader.read(dataByte, 0, length);
|
||||
return dataByte;
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to read file:{} position:{} length:{}", fileName, offset, length);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,27 @@
|
|||
package com.a.eye.skywalking.storage.data.file;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
import com.a.eye.skywalking.storage.data.index.IndexMetaInfo;
|
||||
|
||||
public class DataFileWriter {
|
||||
|
||||
private DataFile dataFile;
|
||||
|
||||
public DataFileWriter() {
|
||||
|
||||
}
|
||||
|
||||
public IndexMetaInfo write(byte[] data) {
|
||||
if (dataFile.overLimitLength()) {
|
||||
convertDataFile();
|
||||
}
|
||||
|
||||
long offset = dataFile.writeAndFlush(data);
|
||||
return new IndexMetaInfo(dataFile.getName(), offset, data.length);
|
||||
}
|
||||
|
||||
private void convertDataFile() {
|
||||
dataFile.close();
|
||||
dataFile = new DataFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
public class DataIndexFile {
|
||||
|
||||
public void read(String traceId) {
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
public class DataIndexFileOperator {
|
||||
|
||||
public Object read(String traceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(Object o, int offset) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
public class DataIndexFileReader {
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/10/31.
|
||||
*/
|
||||
public class DataIndexFileWriter {
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/3.
|
||||
*/
|
||||
public class IndexMetaInfo {
|
||||
|
||||
private String fileName;
|
||||
|
||||
private long offset;
|
||||
|
||||
private int length;
|
||||
|
||||
public IndexMetaInfo(String name, long offset, int length) {
|
||||
this.fileName = name;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public long getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/3.
|
||||
*/
|
||||
public class IndexOperator {
|
||||
|
||||
public List<IndexMetaInfo> find(String traceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(IndexMetaInfo meta) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.a.eye.skywalking.storage.data.index;
|
||||
|
||||
public class IndexOperatorFactory {
|
||||
|
||||
public static IndexOperator get(long timestamp) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue