-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from overture-stack/develop
Merges develop into master for new stable.
- Loading branch information
Showing
81 changed files
with
3,534 additions
and
3,529 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package bio.overture.ego.grpc; | ||
|
||
import bio.overture.ego.grpc.interceptor.AuthInterceptor; | ||
import bio.overture.ego.grpc.service.UserServiceGrpcImpl; | ||
import io.grpc.Server; | ||
import io.grpc.ServerBuilder; | ||
import io.grpc.ServerInterceptors; | ||
import java.util.Optional; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
@Profile("grpc") | ||
public class GrpcServer implements CommandLineRunner, DisposableBean { | ||
|
||
@Value("${grpc.port}") | ||
private int port; | ||
|
||
private Server server; | ||
|
||
private final AuthInterceptor authInterceptor; | ||
private final UserServiceGrpcImpl userServiceImpl; | ||
|
||
@Autowired | ||
public GrpcServer( | ||
@NonNull AuthInterceptor authInterceptor, @NonNull UserServiceGrpcImpl userServiceImpl) { | ||
|
||
this.authInterceptor = authInterceptor; | ||
|
||
this.userServiceImpl = userServiceImpl; | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
|
||
val userService = ServerInterceptors.intercept(userServiceImpl, authInterceptor); | ||
|
||
server = ServerBuilder.forPort(port).addService(userService).build().start(); | ||
|
||
log.info("gRPC Server started, listening on " + port); | ||
startDaemonAwaitThread(); | ||
} | ||
|
||
private void startDaemonAwaitThread() { | ||
Thread awaitThread = | ||
new Thread( | ||
() -> { | ||
try { | ||
this.server.awaitTermination(); | ||
} catch (InterruptedException e) { | ||
log.error("gRPC server stopped.", e); | ||
} | ||
}); | ||
awaitThread.start(); | ||
} | ||
|
||
@Override | ||
public final void destroy() throws Exception { | ||
log.info("Shutting down gRPC server ..."); | ||
Optional.ofNullable(server).ifPresent(Server::shutdown); | ||
log.info("gRPC server stopped."); | ||
} | ||
} |
Oops, something went wrong.