Skip to content

Commit

Permalink
Logging improvements and small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
codingchili committed Oct 11, 2017
1 parent 5d8c1f2 commit 87ad217
Show file tree
Hide file tree
Showing 28 changed files with 167 additions and 115 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'
apply plugin: 'idea'

project.version = "1.0.5"
project.version = "1.0.6-SNAPSHOT"
project.group = 'com.github.codingchili.chili-core'

subprojects {
Expand Down
5 changes: 2 additions & 3 deletions core/main/java/com/codingchili/core/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Launcher implements CoreService {
public Launcher(LaunchContext context) {
Future<Void> future = Future.future();

logger.log(CoreStrings.getStartupText(context.settings().getVersion()), Level.STARTUP);
logger.log(CoreStrings.getStartupText(), Level.STARTUP);

new LauncherCommandExecutor().execute(future, context.args());
future.setHandler(done -> {
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void start(LaunchContext context) {
}

void exit() {
logger.reset();
// empty for now: used in tests.
}

private void clusterIfEnabled(LauncherSettings settings) {
Expand Down Expand Up @@ -155,7 +155,6 @@ private void addShutdownHook() {
e.printStackTrace();
}
logger.log(ERRROR_LAUNCHER_SHUTDOWN, Level.SEVERE);
logger.reset();
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.ArrayList;
import java.util.List;

import static com.codingchili.core.files.Configurations.launcher;

/**
* @author Robin Duda
* <p>
Expand Down Expand Up @@ -332,10 +334,10 @@ public static String format(Path path) {
return format(path, "");
}

public static String getStartupText(String version) {
public static String getStartupText() {
return String.format("\n%56s\n%42s\n%38s %s %s %s\n",
"system: Starting launcher [" + version + "] ..",
"Robin Duda © 2017",
"system: Starting "+ launcher().getApplication() +" [" + launcher().getVersion() + "] ..",
launcher().getAuthor(),
System.getProperty("java.vm.name"),
System.getProperty("java.version"),
System.getProperty("os.name"),
Expand Down Expand Up @@ -392,7 +394,7 @@ public static String getErrorInvalidConfigurable(Class clazz) {
}

public static String getFileLoadDefaults(String path, Class<?> clazz) {
return "configuration '" + path + "' not found, using defaults from '" + clazz.getSimpleName() + "'.";
return "'" + path + "' not found: using '" + clazz.getSimpleName() + "'.";
}

public static String getNoSuchResource(String name) {
Expand Down Expand Up @@ -515,7 +517,7 @@ public static String getSecurityDependencyMissing(String target, String identifi
"' in service configuration for '" + target + "'.";
}

public static String timestamp(long ms) {
public static String consumeTimestamp(long ms) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(ms), ZoneOffset.UTC).toString().split("T")[1];
}

Expand Down Expand Up @@ -562,8 +564,8 @@ public static String getTimeOutEcxeption(String target, int timeout) {
return "Timed out after waiting for " + timeout + "(ms) for address: " + target;
}

public static String getNodeNotReachable(String target) {
return "The remote node '" + target + "' is currently not available.";
public static String getNodeNotReachable(String target, String route) {
return "The remote node '" + target + "' not available, requested handler '" + route + "'.";
}

public static String getNodeFailedToAcknowledge(String target, String route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* Contains the settings for the launcher.
*/
public class LauncherSettings extends BaseConfigurable {
private String application = "";
private String version = "CORE-1.0.5-PR";
private String application = "launcher";
private String version = "CORE-1.0.6-SNAPSHOT";
private String author = "Robin Duda \u00a9 2017";
private boolean clustered;
private HashMap<String, List<String>> blocks = defaultBlockConfiguration();
private HashMap<String, String> hosts = defaultHostConfiguration();
Expand All @@ -36,8 +37,9 @@ public String getVersion() {
/**
* @param version sets the launcher version.
*/
public void setVersion(String version) {
public LauncherSettings setVersion(String version) {
this.version = version;
return this;
}

/**
Expand All @@ -50,8 +52,9 @@ public HashMap<String, List<String>> getBlocks() {
/**
* @param blocks set the configured deployment blocks.
*/
public void setBlocks(HashMap<String, List<String>> blocks) {
public LauncherSettings setBlocks(HashMap<String, List<String>> blocks) {
this.blocks = blocks;
return this;
}

/**
Expand Down Expand Up @@ -87,20 +90,22 @@ public HashMap<String, String> getHosts() {
/**
* @param hosts sets the host to block mapping.
*/
public void setHosts(HashMap<String, String> hosts) {
public LauncherSettings setHosts(HashMap<String, String> hosts) {
this.hosts = hosts;
return this;
}

/**
* @param host the host that should be mapped to a service block
* @param block the block that the host should be mapped to
*/
public void addHost(String host, String block) {
public LauncherSettings addHost(String host, String block) {
if (blocks.containsKey(block)) {
this.hosts.put(block, host);
} else {
throw new IllegalArgumentException(getBlockNotConfigured(block));
}
return this;
}

/**
Expand All @@ -113,8 +118,9 @@ public String getApplication() {
/**
* @param application set the name of the application.
*/
public void setApplication(String application) {
public LauncherSettings setApplication(String application) {
this.application = application;
return this;
}

/**
Expand Down Expand Up @@ -178,4 +184,20 @@ public LauncherSettings setClustered(boolean clustering) {
this.clustered = clustering;
return this;
}

/**
* @return author string used in startup text.
*/
public String getAuthor() {
return author;
}

/**
* @param author set the author string visible in the startup text.
* @return the author of the application
*/
public LauncherSettings setAuthor(String author) {
this.author = author;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ private Future<String> deployN(String verticle) {

@Override
public Future<String> handler(Supplier<CoreHandler> handler) {
ListenerSettings settings = new ListenerSettings();
Future<String> future = Future.future();
deployN(() -> new ClusterListener()
.settings(ListenerSettings::new)
.settings(() -> settings)
.handler(handler.get()), future);
return future;
}
Expand Down
3 changes: 2 additions & 1 deletion core/main/java/com/codingchili/core/listener/BusRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ protected void onNodeNotReachable(Request request) {
request.error(new NodeNotReachableException(request));
logger.log(logger.event(LOG_NODE_UNREACHABLE, Level.SEVERE)
.put(PROTOCOL_TARGET, request.target())
.put(ID_MESSAGE, getNodeNotReachable(request.target())));
.put(PROTOCOL_ROUTE, request.route())
.put(ID_MESSAGE, getNodeNotReachable(request.target(), request.route())));
}

protected void onNodeTimeout(Request request) {
Expand Down
11 changes: 11 additions & 0 deletions core/main/java/com/codingchili/core/listener/ListenerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ public ListenerSettings setDefaultTarget(String defaultTarget) {
this.defaultTarget = defaultTarget;
return this;
}

private static ListenerSettings defaultSettings = new ListenerSettings();

/**
* @return static supplier of the default settings; used to avoid instantiating
* a new settings object on every read of setting properties in listeners
* where no settings has been configured.
*/
public static ListenerSettings getDefaultSettings() {
return defaultSettings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void submit(final Request request) {
handler.handle(request);
} catch (HandlerMissingException missing) {
request.error(missing);
logger.onHandlerMissing(request.route());
logger.onHandlerMissing(request.target(), request.route());
} catch (Throwable e) {
request.error(e);
logger.onError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* the requests to it.
*/
public class ClusterListener implements CoreListener, DeploymentAware {
private Supplier<ListenerSettings> settings;
private Supplier<ListenerSettings> settings = ListenerSettings::getDefaultSettings;
private CoreHandler handler;
private CoreContext core;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
* HTTP/REST transport listener.
*/
public class RestListener implements CoreListener {
private Supplier<ListenerSettings> settings = ListenerSettings::getDefaultSettings;
private RequestProcessor processor;
private CoreContext core;
private CoreHandler handler;
private Supplier<ListenerSettings> settings;
private Router router;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* TCP listener implementation.
*/
public class TcpListener implements CoreListener {
private Supplier<ListenerSettings> settings = ListenerSettings::getDefaultSettings;
private RequestProcessor processor;
private CoreContext core;
private CoreHandler handler;
private Supplier<ListenerSettings> settings;

@Override
public void init(CoreContext core) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
* UDP transport listener.
*/
public class UdpListener implements CoreListener, DeploymentAware {
private Supplier<ListenerSettings> settings = ListenerSettings::getDefaultSettings;
private RequestProcessor processor;
private CoreHandler handler;
private CoreContext core;
private Supplier<ListenerSettings> settings;

@Override
public void init(CoreContext core) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class UdpRequest implements Request {
private int size;
private DatagramPacket packet;
private CoreContext context;
private ListenerSettings listener;
private ListenerSettings settings;
private JsonObject data;

UdpRequest(CoreContext context, ListenerSettings listener, DatagramPacket packet) {
UdpRequest(CoreContext context, ListenerSettings settings, DatagramPacket packet) {
this.size = packet.data().length();
this.context = context;
this.listener = listener;
this.settings = settings;
this.packet = packet;
}

Expand All @@ -44,12 +44,12 @@ public JsonObject data() {

@Override
public int timeout() {
return listener.getTimeout();
return settings.getTimeout();
}

@Override
public int maxSize() {
return listener.getMaxRequestBytes();
return settings.getMaxRequestBytes();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* Websocket transport listener.
*/
public class WebsocketListener implements CoreListener {
private Supplier<ListenerSettings> settings = ListenerSettings::getDefaultSettings;
private RequestProcessor processor;
private CoreContext core;
private CoreHandler handler;
private Supplier<ListenerSettings> settings;

@Override
public void init(CoreContext core) {
Expand Down
Loading

0 comments on commit 87ad217

Please sign in to comment.