Skip to content

Commit

Permalink
Unyadic bodar#1
Browse files Browse the repository at this point in the history
  • Loading branch information
dan committed Feb 9, 2017
1 parent 9a19683 commit 89b1ee7
Show file tree
Hide file tree
Showing 136 changed files with 9 additions and 8,987 deletions.
176 changes: 0 additions & 176 deletions src/com/googlecode/utterlyidle/ApplicationBuilder.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/com/googlecode/utterlyidle/ServerActivator.java

This file was deleted.

35 changes: 9 additions & 26 deletions src/com/googlecode/utterlyidle/ServerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Uri;
import com.googlecode.utterlyidle.httpserver.RestServer;
import com.googlecode.utterlyidle.ssl.SSL;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -30,26 +29,23 @@ public class ServerConfiguration {
public static final String DEFAULT_THREAD_NUMBER = "50";
public static final String DEFAULT_BIND_ADDRESS = "0.0.0.0";
public static final String DEFAULT_PORT = "0";
public static final String DEFAULT_CLASS = RestServer.class.getCanonicalName();

private final BasePath basePath;
private final int maxThreadNumber;
private final InetAddress bindAddress;
private final int port;
private final Class<? extends Server> serverClass;
private final Option<SSLContext> sslContext;

public ServerConfiguration(BasePath basePath, int maxThreadNumber, InetAddress bindAddress, int port, Class<? extends Server> serverClass, final Option<SSLContext> sslContext) {
public ServerConfiguration(BasePath basePath, int maxThreadNumber, InetAddress bindAddress, int port, final Option<SSLContext> sslContext) {
this.basePath = basePath;
this.maxThreadNumber = maxThreadNumber;
this.bindAddress = bindAddress;
this.port = port;
this.serverClass = serverClass;
this.sslContext = sslContext;
}

public ServerConfiguration() {
this(new BasePath(DEFAULT_BASE_PATH), Integer.parseInt(DEFAULT_THREAD_NUMBER), toInetAddress(DEFAULT_BIND_ADDRESS), Integer.parseInt(DEFAULT_PORT), toServer(DEFAULT_CLASS), none(SSLContext.class));
this(new BasePath(DEFAULT_BASE_PATH), Integer.parseInt(DEFAULT_THREAD_NUMBER), toInetAddress(DEFAULT_BIND_ADDRESS), Integer.parseInt(DEFAULT_PORT), none(SSLContext.class));
}

public ServerConfiguration(Properties properties) {
Expand All @@ -58,7 +54,6 @@ public ServerConfiguration(Properties properties) {
valueOf(properties.getProperty(MAX_THREAD_NUM, DEFAULT_THREAD_NUMBER)),
toInetAddress(properties.getProperty(SERVER_BIND_ADDRESS, DEFAULT_BIND_ADDRESS)),
valueOf(properties.getProperty(SERVER_PORT, DEFAULT_PORT)),
toServer(properties.getProperty(SERVER_CLASS, DEFAULT_CLASS)),
toSSLContext(properties.getProperty(SERVER_PROTOCOL, DEFAULT_PROTOCOL)));
}

Expand All @@ -71,55 +66,51 @@ public BasePath basePath() {
}

public ServerConfiguration basePath(BasePath basePath) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, sslContext);
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, sslContext);
}

public int maxThreadNumber() {
return maxThreadNumber;
}

public ServerConfiguration maxThreadNumber(int maxThreadNumber) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, sslContext);
}

public Class<? extends Server> serverClass() {
return serverClass;
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, sslContext);
}

public ServerConfiguration serverClass(Class<? extends Server> serverClass) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, sslContext);
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, sslContext);
}

public InetAddress bindAddress() {
return bindAddress;
}

public ServerConfiguration bindAddress(InetAddress bindAddress) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, sslContext);
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, sslContext);
}

public int port() {
return port;
}

public ServerConfiguration port(int bindPort) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, bindPort, serverClass, sslContext);
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, bindPort, sslContext);
}

public String protocol() {
return sslContext.isDefined() ? Protocol.HTTPS : Protocol.HTTP;
}

public ServerConfiguration protocol(final String protocol) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, toSSLContext(protocol));
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, toSSLContext(protocol));
}

public Option<SSLContext> sslContext() {
return sslContext;
}

public ServerConfiguration sslContext(final SSLContext sslContext) {
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, serverClass, some(sslContext));
return new ServerConfiguration(basePath, maxThreadNumber, bindAddress, port, some(sslContext));
}

private static Option<SSLContext> toSSLContext(String protocol){
Expand All @@ -135,14 +126,6 @@ private static InetAddress toInetAddress(final String address) {
}
}

private static Class<? extends Server> toServer(String className) {
try {
return cast(Class.forName(className));
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public Uri toUrl() {
return uri(format("%s://localhost:%s%s", protocol(), port(), basePath()));
}
Expand Down
Loading

0 comments on commit 89b1ee7

Please sign in to comment.