forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:tronprotocol/java-tron into fix_…
…msg_process
- Loading branch information
Showing
67 changed files
with
1,328 additions
and
487 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
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
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
81 changes: 81 additions & 0 deletions
81
framework/src/main/java/org/tron/common/application/HttpService.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,81 @@ | ||
/* | ||
* java-tron is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* java-tron is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.tron.common.application; | ||
|
||
import com.google.common.base.Objects; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.eclipse.jetty.server.Server; | ||
|
||
@Slf4j(topic = "rpc") | ||
public abstract class HttpService implements Service { | ||
|
||
protected Server apiServer; | ||
protected int port; | ||
|
||
@Override | ||
public void blockUntilShutdown() { | ||
if (apiServer != null) { | ||
try { | ||
apiServer.join(); | ||
} catch (InterruptedException e) { | ||
logger.warn("{}", e.getMessage()); | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (apiServer != null) { | ||
try { | ||
apiServer.start(); | ||
logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port); | ||
} catch (Exception e) { | ||
logger.error("{}", this.getClass().getSimpleName(), e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (apiServer != null) { | ||
logger.info("{} shutdown...", this.getClass().getSimpleName()); | ||
try { | ||
apiServer.stop(); | ||
} catch (Exception e) { | ||
logger.warn("{}", this.getClass().getSimpleName(), e); | ||
} | ||
logger.info("{} shutdown complete", this.getClass().getSimpleName()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
HttpService that = (HttpService) o; | ||
return port == that.port; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(getClass().getSimpleName(), port); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
framework/src/main/java/org/tron/common/application/RpcService.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,85 @@ | ||
/* | ||
* java-tron is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* java-tron is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.tron.common.application; | ||
|
||
import com.google.common.base.Objects; | ||
import io.grpc.Server; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j(topic = "rpc") | ||
public abstract class RpcService implements Service { | ||
|
||
protected Server apiServer; | ||
protected int port; | ||
|
||
@Override | ||
public void blockUntilShutdown() { | ||
if (apiServer != null) { | ||
try { | ||
apiServer.awaitTermination(); | ||
} catch (InterruptedException e) { | ||
logger.warn("{}", e.getMessage()); | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (apiServer != null) { | ||
try { | ||
apiServer.start(); | ||
logger.info("{} started, listening on {}", this.getClass().getSimpleName(), port); | ||
} catch (IOException e) { | ||
logger.error("{}", this.getClass().getSimpleName(), e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (apiServer != null) { | ||
logger.info("{} shutdown...", this.getClass().getSimpleName()); | ||
try { | ||
apiServer.shutdown().awaitTermination(5, TimeUnit.SECONDS); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
logger.warn("{}", this.getClass().getSimpleName(), e); | ||
} | ||
logger.info("{} shutdown complete", this.getClass().getSimpleName()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
RpcService that = (RpcService) o; | ||
return port == that.port; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(getClass().getSimpleName(), port); | ||
} | ||
|
||
} |
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.