-
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.
- Loading branch information
coder4
committed
Aug 31, 2017
1 parent
28db729
commit ee996ef
Showing
3 changed files
with
68 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/coder4/sbmvt/thrift/server/ThriftServerConfiguration.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,65 @@ | ||
/** | ||
* @(#)ThriftServerRunnable.java, Jul 31, 2017. | ||
* <p> | ||
* Copyright 2017 coder4.com. All rights reserved. | ||
* CODER4.COM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. | ||
*/ | ||
package com.coder4.sbmvt.thrift.server; | ||
|
||
import com.netflix.discovery.EurekaClient; | ||
import org.apache.thrift.TProcessor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author coder4 | ||
*/ | ||
@Configuration | ||
@ConditionalOnBean(value = {TProcessor.class, EurekaClient.class}) | ||
public class ThriftServerConfiguration implements InitializingBean, DisposableBean { | ||
|
||
private Logger LOG = LoggerFactory.getLogger(ThriftServerConfiguration.class); | ||
|
||
@Autowired | ||
private TProcessor processor; | ||
|
||
@Autowired | ||
private EurekaClient eurekaClient; | ||
|
||
private ThriftServerRunnable thriftServer; | ||
|
||
private Thread thread; | ||
|
||
@Override | ||
public void destroy() throws Exception { | ||
// Unregister from eureka server & Sleep for 6 seconds | ||
// current has bug, have to try catch | ||
// https://github.com/spring-cloud/spring-cloud-netflix/issues/2099 | ||
try { | ||
LOG.info("ThriftServerConfiguration destroy, shutdown eureka client."); | ||
eurekaClient.shutdown(); | ||
} catch (Exception e) { | ||
LOG.error("eurekaClient shutdown exception", e); | ||
} | ||
|
||
Thread.sleep(TimeUnit.SECONDS.toMillis(6)); | ||
LOG.info("ThriftServerConfiguration destroy, shutdown rpc server."); | ||
thriftServer.stop(); | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
|
||
thriftServer = new ThriftServerRunnable(processor); | ||
|
||
thread = new Thread(thriftServer); | ||
thread.start(); | ||
} | ||
} |
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 @@ | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.coder4.sbmvt.thrift.server.ThriftServerConfiguration |