Skip to content

Commit

Permalink
- simplified the meta data logging of events and connections
Browse files Browse the repository at this point in the history
 - improved log payload and messages
 - added channel clients update (every 5 secs)
  • Loading branch information
matsfunk committed May 11, 2019
1 parent 9c7c0a3 commit 8c7f826
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
Binary file modified server/dist/OOCSI_server.jar
Binary file not shown.
78 changes: 50 additions & 28 deletions server/src/nl/tue/id/oocsi/server/OOCSIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class OOCSIServer extends Server {

// constants
public static final String VERSION = "1.13";
public static final String VERSION = "1.14";

// defaults for different services
private static int maxClients = 100;
Expand All @@ -35,6 +35,7 @@ public class OOCSIServer extends Server {
public static String[] users = null;

// default channels
public static final String SERVER = "SERVER";
public static final String OOCSI_EVENTS = "OOCSI_events";
public static final String OOCSI_CONNECTIONS = "OOCSI_connections";
public static final String OOCSI_CHANNELS = "OOCSI_channels";
Expand Down Expand Up @@ -132,8 +133,8 @@ private void init() throws IOException {

// add OOCSI channels that will deliver meta-data to potentially
// connected clients
addChannel(new Channel(OOCSIServer.OOCSI_CONNECTIONS, PresenceTracker.nullListener));
addChannel(new Channel(OOCSIServer.OOCSI_EVENTS, PresenceTracker.nullListener));
addChannel(new Channel(OOCSI_CONNECTIONS, PresenceTracker.nullListener));
addChannel(new Channel(OOCSI_EVENTS, PresenceTracker.nullListener));

// output status message
OOCSIServer.log("Started OOCSI server v" + OOCSIServer.VERSION + " for max. " + maxClients + " parallel clients"
Expand All @@ -149,7 +150,7 @@ private void init() throws IOException {
start(new AbstractService[] { tcp, osc });

// start timer for posting channel and client information to the respective channels
Executors.newSingleThreadScheduledExecutor().schedule(new StatusTimeTask(), 5, TimeUnit.SECONDS);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new StatusTimeTask(), 5, 5, TimeUnit.SECONDS);
}

/**
Expand Down Expand Up @@ -279,26 +280,32 @@ protected void internalLog(String message) {
* @param data
* @param timestamp
*/
public static void logEvent(String sender, String recipient, Map<String, Object> data, Date timestamp) {
public static void logEvent(String sender, String channel, String recipient, Map<String, Object> data,
Date timestamp) {

if (!OOCSIServer.OOCSI_EVENTS.equals(sender) && !OOCSIServer.OOCSI_EVENTS.equals(recipient)
&& !OOCSIServer.OOCSI_METRICS.equals(recipient) && !OOCSIServer.OOCSI_CONNECTIONS.equals(recipient)) {

// log metrics
messageCount++;
messageTotal++;
if (SERVER.equals(sender) || OOCSI_EVENTS.equals(sender) || OOCSI_EVENTS.equals(recipient)
|| OOCSI_METRICS.equals(recipient) || OOCSI_CONNECTIONS.equals(recipient)) {
return;
}

if (isLogging) {
log(OOCSI_EVENTS + " " + sender + "->" + recipient);
// log metrics
messageCount++;
messageTotal++;

Channel logChannel = server.getChannel(OOCSI_EVENTS);
if (logChannel != null) {
Message message = new Message(sender, OOCSI_EVENTS, timestamp, data);
message.addData("sender", sender);
message.addData("recipient", recipient);
if (isLogging) {
if (channel.length() == 0) {
log(OOCSI_EVENTS + " " + sender + " --> " + recipient);
} else {
log(OOCSI_EVENTS + " " + sender + " --( " + channel + " )--> " + recipient);
}

logChannel.send(message);
}
Channel logChannel = server.getChannel(OOCSI_EVENTS);
if (logChannel != null) {
Message message = new Message(SERVER, OOCSI_EVENTS, timestamp, data);
message.addData("PUB", sender);
message.addData("CHANNEL", channel);
message.addData("SUB", recipient);
logChannel.send(message);
}
}
}
Expand All @@ -309,15 +316,20 @@ public static void logEvent(String sender, String recipient, Map<String, Object>
* @param message
*/
public static void logConnection(String client, String channel, String operation, Date timestamp) {
if (isLogging && !OOCSIServer.OOCSI_EVENTS.equals(channel) && !OOCSIServer.OOCSI_CONNECTIONS.equals(channel)) {

if (OOCSI_EVENTS.equals(channel) || OOCSI_CONNECTIONS.equals(channel)) {
return;
}

if (isLogging) {
log(OOCSI_CONNECTIONS + " " + client + "->" + channel + " (" + operation + ")");

Message message = new Message(client, OOCSI_CONNECTIONS, timestamp);
message.addData("client", client);
message.addData("channel", channel);
message.addData("operation", operation);
Channel logChannel = server.getChannel(OOCSI_CONNECTIONS);
if (logChannel != null) {
Message message = new Message(SERVER, OOCSI_CONNECTIONS, timestamp);
message.addData("CLIENT", client);
message.addData("CHANNEL", channel);
message.addData("OP", operation);
logChannel.send(message);
}
}
Expand Down Expand Up @@ -357,23 +369,33 @@ public void run() {
// check if we have a subscriber for public channel information
Channel channels = server.getChannel(OOCSI_CHANNELS);
if (channels != null) {
Message message = new Message("SERVER", OOCSI_CHANNELS);
Message message = new Message(SERVER, OOCSI_CHANNELS);
message.addData("channels", server.getChannelList());
channels.send(message);
}

// check if we have a subscriber for public client information
Channel clients = server.getChannel(OOCSI_CLIENTS);
if (clients != null) {
Message message = new Message("SERVER", OOCSI_CLIENTS);
Message message = new Message(SERVER, OOCSI_CLIENTS);
message.addData("clients", server.getClientList());
clients.send(message);
}

// check first-level channels for channel subscribers
for (Channel channel : server.getChannels()) {
Channel channelSubscription = server.getChannel(channel.getName() + "/?");
if (channelSubscription != null) {
Message message = new Message(SERVER, channelSubscription.getName());
message.addData("channels", channel.getChannelList());
channelSubscription.send(message);
}
}

// check if we have a subscriber for public client information
Channel metrics = server.getChannel(OOCSI_METRICS);
if (metrics != null) {
Message message = new Message("SERVER", OOCSI_METRICS);
Message message = new Message(SERVER, OOCSI_METRICS);

// millis since startup
message.addData("uptime", System.currentTimeMillis() - serverStart);
Expand Down
13 changes: 4 additions & 9 deletions server/src/nl/tue/id/oocsi/server/model/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String toString() {
* @return
*/
public boolean isPrivate() {
return token.contains(":");
return token.contains(":") || token.contains("/?");
}

/**
Expand Down Expand Up @@ -82,10 +82,6 @@ public boolean accept(String channelToken) {
* @param message
*/
public void send(Message message) {
if (!message.sender.equals("SERVER") && !message.recipient.equals("OOCSI_events")) {
OOCSIServer.logEvent(message.sender, message.recipient, message.data, message.timestamp);
}

for (Channel subChannel : subChannels.values()) {
// no echo in channels; use ECHO channel for that
if (message.sender.equals(subChannel.getName())) {
Expand All @@ -95,12 +91,11 @@ public void send(Message message) {
// send event
subChannel.send(message);

// log event
// log event unless channel is private
if (!subChannel.isPrivate()) {
if (!message.recipient.equals(subChannel.getName())) {
if (!message.sender.equals("SERVER") && !message.recipient.equals("OOCSI_events")) {
OOCSIServer.logEvent(message.recipient, subChannel.getName(), message.data, message.timestamp);
}
OOCSIServer.logEvent(message.sender, message.recipient, subChannel.getName(), message.data,
message.timestamp);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/nl/tue/id/oocsi/server/model/FunctionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.udojava.evalex.Expression;
import com.udojava.evalex.Expression.LazyNumber;

import nl.tue.id.oocsi.server.OOCSIServer;
import nl.tue.id.oocsi.server.protocol.Message;

public class FunctionClient extends Client {
Expand Down Expand Up @@ -102,6 +103,11 @@ public void send(Message message) {

message.recipient += "[" + functionString + "]";
delegate.send(message);

// log this if recipient is this client exactly
if (message.recipient.equals(getName())) {
OOCSIServer.logEvent(message.sender, "", message.recipient, message.data, message.timestamp);
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions server/src/nl/tue/id/oocsi/server/services/SocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void send(Message message) {
} else if (type == ClientType.JSON) {
send(serializeJSON(message.data, message.recipient, message.timestamp.getTime(), message.sender));
}

// log this if recipient is this client exactly
if (message.recipient.equals(getName())) {
OOCSIServer.logEvent(message.sender, "", message.recipient, message.data, message.timestamp);
}
}

/**
Expand Down

0 comments on commit 8c7f826

Please sign in to comment.