init
This commit is contained in:
@@ -27,9 +27,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@@ -42,10 +42,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@@ -17,7 +17,7 @@ public class ServerStarter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
long datacenterId = Constants.DATACENTER_ID;
|
||||
long machineId = Constants.MACHINES_SIGN;
|
||||
long machineId = Constants.MACHINES_ID;
|
||||
|
||||
if (args != null && args.length == 2) {
|
||||
datacenterId = Long.valueOf(args[0]);
|
||||
@@ -25,7 +25,7 @@ public class ServerStarter {
|
||||
}
|
||||
|
||||
datacenterId = "".equals(Constants.getEnv("DATACENTER_ID")) ? datacenterId : Long.valueOf(Constants.getEnv("DATACENTER_ID"));
|
||||
machineId = "".equals(Constants.getEnv("MACHINES_SIGN")) ? machineId : Long.valueOf(Constants.getEnv("MACHINES_SIGN"));
|
||||
machineId = "".equals(Constants.getEnv("MACHINES_ID")) ? machineId : Long.valueOf(Constants.getEnv("MACHINES_ID"));
|
||||
logger.info("SnowFlake datacenterId is: {}, machineId is: {}", datacenterId, machineId);
|
||||
|
||||
final SnowFlake snowFlake = new SnowFlake(datacenterId, machineId);
|
||||
|
@@ -25,7 +25,7 @@ public class HttpServer extends BaseServer {
|
||||
|
||||
public HttpServer(SnowFlake snowFlake) {
|
||||
this.snowFlake = snowFlake;
|
||||
this.port = Constants.HTTP_PORT;
|
||||
this.port = "".equals(Constants.getEnv("HTTP_PORT")) ? Constants.HTTP_PORT : Integer.valueOf(Constants.getEnv("HTTP_PORT"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -39,25 +39,25 @@ public class HttpServerHandler extends SimpleChannelInboundHandler<FullHttpReque
|
||||
String uri = getUriNoSprit(request);
|
||||
logger.info("request uri is: {}", uri);
|
||||
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
|
||||
if (Constants.HTTP_REQUEST.equals(uri)) {
|
||||
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
long id = snowFlake.nextId();
|
||||
logger.info("HttpServerHandler id is: {}", id);
|
||||
response.content().writeBytes(("" + id).getBytes());
|
||||
} catch (Exception e) {
|
||||
semaphore.release();
|
||||
logger.error("HttpServerHandler error", e);
|
||||
}
|
||||
} else {
|
||||
String info = String.format("HttpServerHandler tryAcquire semaphore timeout, %dms, waiting thread " + "nums: %d availablePermit: %d",
|
||||
Constants.ACQUIRE_TIMEOUTMILLIS, this.semaphore.getQueueLength(), this.semaphore.availablePermits());
|
||||
logger.warn(info);
|
||||
throw new Exception(info);
|
||||
// if (Constants.HTTP_REQUEST.equals(uri)) {
|
||||
if (semaphore.tryAcquire(Constants.ACQUIRE_TIMEOUTMILLIS, TimeUnit.MILLISECONDS)) {
|
||||
try {
|
||||
long id = snowFlake.nextId();
|
||||
logger.info("HttpServerHandler id is: {}", id);
|
||||
response.content().writeBytes(("" + id).getBytes());
|
||||
} catch (Exception e) {
|
||||
semaphore.release();
|
||||
logger.error("HttpServerHandler error", e);
|
||||
}
|
||||
} else {
|
||||
response.content().writeBytes(("Unsupported uri: " + uri).getBytes());
|
||||
String info = String.format("HttpServerHandler tryAcquire semaphore timeout, %dms, waiting thread " + "nums: %d availablePermit: %d",
|
||||
Constants.ACQUIRE_TIMEOUTMILLIS, this.semaphore.getQueueLength(), this.semaphore.availablePermits());
|
||||
logger.warn(info);
|
||||
throw new Exception(info);
|
||||
}
|
||||
// } else {
|
||||
// response.content().writeBytes(("Unsupported uri: " + uri).getBytes());
|
||||
// }
|
||||
|
||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ public class SdkServer extends BaseServer {
|
||||
|
||||
public SdkServer(SnowFlake snowFlake) {
|
||||
this.snowFlake = snowFlake;
|
||||
this.port = Constants.SDKS_PORT;
|
||||
this.port = "".equals(Constants.getEnv("SDKS_PORT")) ? Constants.SDKS_PORT : Integer.valueOf(Constants.getEnv("SDKS_PORT"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Tue Aug 14 15:16:53 CST 2018
|
||||
#Tue Aug 14 18:32:03 CST 2018
|
||||
version=1.0-SNAPSHOT
|
||||
groupId=cn.ceres.did
|
||||
artifactId=did-server
|
||||
|
Reference in New Issue
Block a user