Skip to content

Commit

Permalink
adjust code style
Browse files Browse the repository at this point in the history
  • Loading branch information
thelight1 committed Oct 12, 2019
1 parent ca0ffaf commit 76301dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@
@RestController
public class LeafController {
private Logger logger = LoggerFactory.getLogger(LeafController.class);

@Autowired
SegmentService segmentService;
private SegmentService segmentService;
@Autowired
SnowflakeService snowflakeService;
private SnowflakeService snowflakeService;

@RequestMapping(value = "/api/segment/get/{key}")
public String getSegmentID(@PathVariable("key") String key) {
public String getSegmentId(@PathVariable("key") String key) {
return get(key, segmentService.getId(key));
}

@RequestMapping(value = "/api/snowflake/get/{key}")
public String getSnowflakeID(@PathVariable("key") String key) {
public String getSnowflakeId(@PathVariable("key") String key) {
return get(key, snowflakeService.getId(key));

}

private String get(@PathVariable("key") String key, Result id) {
Result result;
if (key == null || key.isEmpty()) {
throw new NoKeyException();
}

result = id;
if (result.getStatus().equals(Status.EXCEPTION)) {
throw new LeafServerException(result.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
@Controller
public class LeafMonitorController {
private Logger logger = LoggerFactory.getLogger(LeafMonitorController.class);

@Autowired
SegmentService segmentService;
private SegmentService segmentService;

@RequestMapping(value = "cache")
public String getCache(Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
@Service("SegmentService")
public class SegmentService {
private Logger logger = LoggerFactory.getLogger(SegmentService.class);
IDGen idGen;
DruidDataSource dataSource;

private IDGen idGen;
private DruidDataSource dataSource;

public SegmentService() throws SQLException, InitException {
Properties properties = PropertyFactory.getProperties();
boolean flag = Boolean.parseBoolean(properties.getProperty(Constants.LEAF_SEGMENT_ENABLE, "true"));
if (flag) {


// Config dataSource
dataSource = new DruidDataSource();
dataSource.setUrl(properties.getProperty(Constants.LEAF_JDBC_URL));
Expand All @@ -51,9 +51,11 @@ public SegmentService() throws SQLException, InitException {
logger.info("Zero ID Gen Service Init Successfully");
}
}

public Result getId(String key) {
return idGen.get(key);
}

public SegmentIDGenImpl getIdGen() {
if (idGen instanceof SegmentIDGenImpl) {
return (SegmentIDGenImpl) idGen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
@Service("SnowflakeService")
public class SnowflakeService {
private Logger logger = LoggerFactory.getLogger(SnowflakeService.class);
IDGen idGen;

private IDGen idGen;

public SnowflakeService() throws InitException {
Properties properties = PropertyFactory.getProperties();
boolean flag = Boolean.parseBoolean(properties.getProperty(Constants.LEAF_SNOWFLAKE_ENABLE, "true"));
Expand All @@ -34,6 +36,7 @@ public SnowflakeService() throws InitException {
logger.info("Zero ID Gen Service Init Successfully");
}
}

public Result getId(String key) {
return idGen.get(key);
}
Expand Down

0 comments on commit 76301dc

Please sign in to comment.