Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
MP Metrics, FaultTolerance, FallBack, and Open Tracing Configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jjvilleg committed Oct 24, 2018
1 parent 9dde89d commit 9678fb7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/bin
/build
/local.properties
/room-wlpcfg/lib/
*~

2 changes: 1 addition & 1 deletion room-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
providedCompile 'javax.enterprise:cdi-api:1.2'
providedCompile 'javax.enterprise.concurrent:javax.enterprise.concurrent-api:1.0'
compile 'org.mongodb:mongo-java-driver:2.12.3'

compile group: 'org.eclipse.microprofile', name: 'microprofile', version: '1.3'
compile 'com.github.gameontext:signed:v1.0.3'

// kafka client =)
Expand Down
72 changes: 72 additions & 0 deletions room-app/src/main/java/net/wasdev/gameon/room/RoomWS.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
import javax.websocket.MessageHandler;
import javax.websocket.Session;

import org.eclipse.microprofile.opentracing.Traced;
import org.eclipse.microprofile.metrics.annotation.Metered;
import org.eclipse.microprofile.metrics.annotation.Timed;
import org.eclipse.microprofile.metrics.annotation.Counted;

import net.wasdev.gameon.room.engine.Room;

/**
* WebSocket endpoint for player's interacting with the room
*/
public class RoomWS extends Endpoint {

private final Room room;
private final LifecycleManager.SessionRoomResponseProcessor srrp;
private Map<Session, MessageHandler.Whole<String>> handlersBySession = new ConcurrentHashMap<Session, MessageHandler.Whole<String>>();
Expand Down Expand Up @@ -66,6 +72,17 @@ public void onMessage(String message) {
}

@Override
@Traced
@Timed(name = "websocket_onOpen_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "websocket_onOpen_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "websocket_onOpen_meter",
reusable = true,
tags = "label=websocket")
public void onOpen(final Session session, EndpointConfig ec) {
Log.log(Level.FINE,this, "onOpen called against room " + this.room.getRoomId());

Expand Down Expand Up @@ -123,6 +140,17 @@ private void debugDumpSessionInfo() {
}

@Override
@Traced
@Timed(name = "websocket_onClose_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "websocket_onClose_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "websocket_onClose_meter",
reusable = true,
tags = "label=websocket")
public void onClose(Session session, CloseReason reason) {
// (lifecycle) Called when the connection is closed, treat this as the
// player has left the room
Expand Down Expand Up @@ -150,6 +178,17 @@ public void onClose(Session session, CloseReason reason) {
}
}

@Traced
@Timed(name = "receiveMessage_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "receiveMessage_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "receiveMessage_meter",
reusable = true,
tags = "label=websocket")
public void receiveMessage(String message, Session session) throws IOException {
Log.log(Level.FINE, this, "ROOMX: [{0}:{1}] sess[{2}:{3}] : {4}", this.hashCode(),this.room.getRoomId(),session.hashCode(),session.getId(),message);
String[] contents = Message.splitRouting(message);
Expand Down Expand Up @@ -190,6 +229,17 @@ private void processCommand(String json) throws IOException {
}

// add a new player to the room
@Traced
@Timed(name = "addNewPlayer_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "addNewPlayer_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "addNewPlayer_meter",
reusable = true,
tags = "label=websocket")
private void addNewPlayer(Session session, String json) throws IOException {

JsonObject msg = Json.createReader(new StringReader(json)).readObject();
Expand All @@ -202,6 +252,17 @@ private void addNewPlayer(Session session, String json) throws IOException {
room.command(userid, "look");
}

@Traced
@Timed(name = "removePlayer_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "removePlayer_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "removePlayer_meter",
reusable = true,
tags = "label=websocket")
private void removePlayer(Session session, String json) throws IOException {
JsonObject msg = Json.createReader(new StringReader(json)).readObject();
String userid = Message.getValue(msg.get(Constants.USERID));
Expand All @@ -210,6 +271,17 @@ private void removePlayer(Session session, String json) throws IOException {
}

@Override
@Traced
@Timed(name = "websocket_onError_timer",
reusable = true,
tags = "label=websocket")
@Counted(name = "websocket_onError_count",
monotonic = true,
reusable = true,
tags = "label=websocket")
@Metered(name = "websocket_onError_meter",
reusable = true,
tags = "label=websocket")
public void onError(Session session, Throwable thr) {
// (lifecycle) Called if/when an error occurs and the connection is
// disrupted
Expand Down
1 change: 1 addition & 0 deletions room-wlpcfg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ENV SERVERDIRNAME room

COPY ./startup.sh /opt/startup.sh
ADD ./servers/gameon-room /opt/ol/wlp/usr/servers/defaultServer/
COPY ./lib/features/ /opt/ol/wlp/usr/

CMD ["/opt/startup.sh"]

Expand Down
23 changes: 20 additions & 3 deletions room-wlpcfg/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
apply plugin: 'eclipse'

buildscript {
repositories {
mavenCentral()
}
}

plugins {
id "de.undercouch.download" version "3.4.3"
}

apply plugin: 'eclipse'

task copyWAR(type: Copy) {
from '../room-app/build/libs/room-app-1.0.war'
into 'servers/gameon-room/apps/'
rename("room-app-1.0.war", "room-app.war")
}

task build(dependsOn: ['copyWAR']){
task downloadFile(type: Download) {
src 'https://github.com/WASdev/sample.opentracing.zipkintracer/releases/download/1.1/liberty-opentracing-zipkintracer-1.1-sample.zip'
dest "lib/features/liberty-opentracing-zipkintracer-1.1-sample.zip"
}

task unzipFile(type: Copy) {
dependsOn 'downloadFile'
def zipFile = file("lib/features/liberty-opentracing-zipkintracer-1.1-sample.zip")
def outputDir = file("lib/features/")
from zipTree(zipFile)
into outputDir
}

task build(dependsOn: ['copyWAR', 'unzipFile']){
}

task clean {
Expand Down
7 changes: 6 additions & 1 deletion room-wlpcfg/servers/gameon-room/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
<feature>ssl-1.0</feature>
<feature>concurrent-1.0</feature>
<feature>appSecurity-2.0</feature>
<feature>microprofile-1.3</feature>
<feature>usr:opentracingZipkin-0.30</feature>
</featureManager>

<opentracingZipkin host="zipkin"/>

<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
Expand Down Expand Up @@ -51,7 +54,9 @@
<!-- The JVM can get confused about available CPU in virtualized envs -->
<executor coreThreads="5" />

<webApplication id="room-app" location="room-app.war" name="room-app"/>
<webApplication id="room-app" location="room-app.war" name="room-app">
<classloader apiTypeVisibility="api,ibm-api,spec,stable,third-party"/>
</webApplication>

<jndiEntry jndiName="developmentMode" value="${env.GAMEON_MODE}"/>
<jndiEntry jndiName="targetPlatform" value="${env.TARGET_PLATFORM}"/>
Expand Down

0 comments on commit 9678fb7

Please sign in to comment.