Skip to content

Commit

Permalink
[feat]添加了config,准备发布
Browse files Browse the repository at this point in the history
  • Loading branch information
MuLeiSY2021 committed Nov 20, 2023
1 parent c99d675 commit 9dcd216
Show file tree
Hide file tree
Showing 28 changed files with 340 additions and 119 deletions.
2 changes: 2 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions logs/report.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
INFO main org.riseger.main.init.MainBootstrap - Log initializer successfully
INFO main org.riseger.main.init.ConfigInitializer - Set working directory..
INFO main org.riseger.main.init.MainBootstrap - Log initializer successfully
INFO main org.riseger.main.init.ConfigInitializer - Set working directory..
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set port10086
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set blocking-log125
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set core-pool-size5
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set max-pool-size10
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set keep-alive-time60
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set default-memorysize1024
INFO main org.riseger.main.init.MainBootstrap - Config initializer successfully
INFO main org.riseger.main.init.MainBootstrap - Storage initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Cache initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Compiler initialized successfully
INFO main org.riseger.main.init.MainBootstrap - RequestHandler initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Entry initialized successfully
INFO entry-initializer org.riseger.main.entry.server.NettyServer - Netty server connected ,waiting for port 10086 requests
INFO main org.riseger.main.init.MainBootstrap - Log initializer successfully
INFO main org.riseger.main.init.ConfigInitializer - Set working directory..
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set port 10086
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set blocking-log 125
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set core-pool-size 5
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set max-pool-size 10
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set keep-alive-time 60
DEBUG main org.riseger.main.init.ConfigInitializer - Config Set default-memorysize 1024
INFO main org.riseger.main.init.MainBootstrap - Config initializer successfully
INFO main org.riseger.main.init.MainBootstrap - Storage initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Cache initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Compiler initialized successfully
INFO main org.riseger.main.init.MainBootstrap - RequestHandler initialized successfully
INFO main org.riseger.main.init.MainBootstrap - Entry initialized successfully
INFO entry-initializer org.riseger.main.entry.server.NettyServer - Netty server connected ,waiting for port 10086 requests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.example;
package org.riseger;

/**
* Unit test for simple App.
Expand Down
35 changes: 35 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,36 @@
</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.riseger.main.init.MainBootstrap</mainClass><!--这里改成自己的主类位置-->
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<packaging>pom</packaging>
Expand All @@ -33,6 +63,11 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.risegerdb.protocol</groupId>
<artifactId>Protocol</artifactId>
<version>0.1.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
6 changes: 4 additions & 2 deletions riseger_project/scripts/shell.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash

# 设置Java运行时环境变量,根据你的实际情况修改JAVA_HOME的路径
CRTDIR=$(pwd)/models/shellCli
CRTDIR=$(readlink -f "${BASH_SOURCE[0]}")/models/shellCli

cd $CRTDIR

# 设置JAR文件路径,根据你的实际情况修改
JAR_PATH=./models/shellCli/ShellClient.jar
JAR_PATH=./ShellClient.jar

# 设置Java虚拟机参数,根据需要修改
JAVA_OPTS="-Xmx512m -Xms256m"
Expand Down
3 changes: 2 additions & 1 deletion riseger_project/scripts/startup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

# 设置Java运行时环境变量,根据你的实际情况修改JAVA_HOME的路径
CRTDIR=$(pwd)
CRTDIR=$(readlink -f "${BASH_SOURCE[0]}")

cd $CRTDIR
# 设置JAR文件路径,根据你的实际情况修改
JAR_PATH=./RisegerDB.jar

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/riseger/ConfigConstant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.riseger;

public class ConfigConstant {

public static Integer PORT = 10086;

public static Integer NETTY_BLOCKING_LOG = 125;

public static int CORE_POOL_SIZE = 5; // 核心线程数

public static int MAX_POOL_SIZE = 10; // 最大线程数

public static long KEEP_ALIVE_TIME = 60; // 空闲线程存活时间(单位:秒)

public static Integer DEFAULT_MEMORYSIZE = 1024;
}
2 changes: 0 additions & 2 deletions src/main/java/org/riseger/main/Constant.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.riseger.main;

public class Constant {
public static final String VERSION = "1.0.0";

public static final String SUBMAP_PREFIX = "smp";

Expand All @@ -19,6 +18,5 @@ public class Constant {

public static final String DOT_PREFIX = ".";

public static final Integer DEFAULT_MEMORYSIZE = 1024;
public static final String MODEL_FILE_NAME = "model";
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.riseger.main.compiler.compoent;

import org.riseger.main.Constant;
import org.riseger.ConfigConstant;

import java.util.HashMap;
import java.util.Map;

public class SearchMemory {

final Object[] stackMemory = new Object[Constant.DEFAULT_MEMORYSIZE];
final Object[] stackMemory = new Object[ConfigConstant.DEFAULT_MEMORYSIZE];

final Map<Integer, Object> mapMemory = new HashMap<>();

Expand All @@ -21,8 +21,8 @@ public Object getVar() {
}

public void setVar(Object object) {
if (variableIndex == Constant.DEFAULT_MEMORYSIZE) {
throw new IndexOutOfBoundsException("Stack over flow size:" + Constant.DEFAULT_MEMORYSIZE * 8 + "bytes");
if (variableIndex == ConfigConstant.DEFAULT_MEMORYSIZE) {
throw new IndexOutOfBoundsException("Stack over flow size:" + ConfigConstant.DEFAULT_MEMORYSIZE * 8 + "bytes");
}
this.stackMemory[variableIndex++] = object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class ApiHandlerManager {
workFlowMap.put(RequestType.SHELL, new CommonWorkFlow());
}

private Compiler compiler;

public void setRequest(BasicRequest request, RequestType type) {
workFlowMap.get(type).push(request);
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/riseger/main/entry/server/NettyServer.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.riseger.main.entry.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.log4j.Logger;
import org.riseger.ConfigConstant;
import org.riseger.main.entry.handler.HandlerManager;

public class NettyServer implements Server, Runnable {
Expand All @@ -26,10 +28,13 @@ public void bootstrap() {
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new HandlerManager())
.option(ChannelOption.SO_BACKLOG, 128)
.option(ChannelOption.SO_BACKLOG, ConfigConstant.NETTY_BLOCKING_LOG)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
.childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture future = bootstrap.bind(10086).sync();
LOG.info("Netty server connected ,waiting for port 10086 requests");
ChannelFuture future = bootstrap.bind(ConfigConstant.PORT).sync();
LOG.info("Netty server connected ,waiting for port " + ConfigConstant.PORT + " requests");
future.channel().closeFuture().sync();
} catch (InterruptedException e) {
LOG.error(e);
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/org/riseger/main/init/CacheInitializer.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
package org.riseger.main.init;

import org.apache.log4j.Logger;
import org.riseger.main.cache.entity.component.Database_c;
import org.riseger.main.cache.manager.CacheMaster;
import org.riseger.main.cache.manager.DatabaseManager;

import java.util.List;

public class CacheInitializer implements Initializer {
public class CacheInitializer extends Initializer {
private static final Logger LOG = Logger.getLogger(CacheInitializer.class);

private final StorageInitializer storageInitializer;

public CacheInitializer(StorageInitializer storageInitializer) {
public CacheInitializer(String rootPath, StorageInitializer storageInitializer) {
super(rootPath);
this.storageInitializer = storageInitializer;
}

public void init() {
CacheMaster.setINSTANCE(new CacheMaster());
DatabaseManager dbm = CacheMaster.INSTANCE.getDatabaseManager();
List<Database_c> databases = storageInitializer.initDatabases();
if (databases != null) {
for (Database_c database : databases) {
dbm.addDatabase(database);
public boolean init() {
try {
CacheMaster.setINSTANCE(new CacheMaster());
DatabaseManager dbm = CacheMaster.INSTANCE.getDatabaseManager();
List<Database_c> databases = storageInitializer.initDatabases();
if (databases != null) {
for (Database_c database : databases) {
dbm.addDatabase(database);
}
}
return true;
} catch (Exception e) {
LOG.error("Failed to initialize cache", e);
return false;
}

}

}
73 changes: 40 additions & 33 deletions src/main/java/org/riseger/main/init/CompilerInitialize.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.riseger.main.init;

import org.apache.log4j.Logger;
import org.riseger.main.compiler.CompilerMaster;
import org.riseger.main.compiler.compoent.SessionAdaptor;
import org.riseger.main.compiler.lextcal.Keyword;
Expand All @@ -14,43 +15,49 @@
import java.io.File;
import java.io.FileNotFoundException;

public class CompilerInitialize implements Initializer {
private final String rootPath;
public class CompilerInitialize extends Initializer {
private static final Logger LOG = Logger.getLogger(CompilerInitialize.class);

public CompilerInitialize(String rootPath) {
this.rootPath = rootPath;
super(rootPath);
}

public void init() throws Exception {
//获取文法规则
String rule = Utils.getText(new File(rootPath + "/resources/rule/syntaxrule.rule"));
if (rule == null) {
throw new FileNotFoundException("Syntax rule");
public boolean init() {
try {
//获取文法规则
String rule = Utils.getText(new File(rootPath + "/resources/rule/syntaxrule.rule"));
if (rule == null) {
throw new FileNotFoundException("Syntax rule");
}

//文法规则解析
SyntaxRule syntaxRule = new SyntaxRule(rule);

//生成文法规则树
SyntaxForest syntaxForest = new SyntaxForest(syntaxRule);

//生成关键词树
MultiBranchesTree<Keyword> keywordsTree = new MultiBranchesTree<>();
//填充关键词
for (Keyword keyword : Keyword.getKeywords()) {
keywordsTree.insert(keyword);
}

//生成分词器
Tokenizer tokenizer = new Tokenizer(keywordsTree);

//生成词法解析器
Lexicator lexicator = new Lexicator(keywordsTree);

//生成语法解析器
Parser parser = new Parser(syntaxForest);

//
CompilerMaster.INSTANCE = new CompilerMaster(new SessionAdaptor(tokenizer, lexicator, parser));
} catch (Exception e) {
LOG.error("Failed to initialize Compiler", e);
return false;
}

//文法规则解析
SyntaxRule syntaxRule = new SyntaxRule(rule);

//生成文法规则树
SyntaxForest syntaxForest = new SyntaxForest(syntaxRule);

//生成关键词树
MultiBranchesTree<Keyword> keywordsTree = new MultiBranchesTree<>();
//填充关键词
for (Keyword keyword : Keyword.getKeywords()) {
keywordsTree.insert(keyword);
}

//生成分词器
Tokenizer tokenizer = new Tokenizer(keywordsTree);

//生成词法解析器
Lexicator lexicator = new Lexicator(keywordsTree);

//生成语法解析器
Parser parser = new Parser(syntaxForest);

//
CompilerMaster.INSTANCE = new CompilerMaster(new SessionAdaptor(tokenizer, lexicator, parser));
return true;
}
}
Loading

0 comments on commit 9dcd216

Please sign in to comment.