-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): optimize api service startup
- Loading branch information
1 parent
f16c3f8
commit c0d240c
Showing
44 changed files
with
1,168 additions
and
1,331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
common/src/main/java/org/tron/core/exception/ServiceStartException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.tron.core.exception; | ||
|
||
public class ServiceStartException extends TronRuntimeException { | ||
|
||
public ServiceStartException(String message) { | ||
super(message); | ||
} | ||
|
||
public ServiceStartException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ServiceStartException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
framework/src/main/java/org/tron/common/application/AbstractService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.tron.common.application; | ||
|
||
import com.google.common.base.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.tron.core.config.args.Args; | ||
|
||
|
||
@Slf4j(topic = "service") | ||
public abstract class AbstractService implements Service { | ||
|
||
protected int port; | ||
@Getter | ||
protected boolean enable; | ||
@Getter | ||
protected final String name = this.getClass().getSimpleName(); | ||
|
||
|
||
@Override | ||
public CompletableFuture<Boolean> start() { | ||
logger.info("{} starting on {}", name, port); | ||
final CompletableFuture<Boolean> resultFuture = new CompletableFuture<>(); | ||
try { | ||
innerStart(); | ||
resultFuture.complete(true); | ||
logger.info("{} started, listening on {}", name, port); | ||
} catch (Exception e) { | ||
resultFuture.completeExceptionally(e); | ||
} | ||
return resultFuture; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Boolean> stop() { | ||
logger.info("{} shutdown...", name); | ||
final CompletableFuture<Boolean> resultFuture = new CompletableFuture<>(); | ||
try { | ||
innerStop(); | ||
resultFuture.complete(true); | ||
logger.info("{} shutdown complete", name); | ||
} catch (Exception e) { | ||
resultFuture.completeExceptionally(e); | ||
} | ||
return resultFuture; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
AbstractService that = (AbstractService) o; | ||
return port == that.port; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(name, port); | ||
} | ||
|
||
public abstract void innerStart() throws Exception; | ||
|
||
public abstract void innerStop() throws Exception; | ||
|
||
protected boolean isFullNode() { | ||
return !Args.getInstance().isSolidityNode(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.