Skip to content

Commit

Permalink
[Java/ClockStream] Add README File explain the main purpose of ClockS…
Browse files Browse the repository at this point in the history
…tream and how to launch project
  • Loading branch information
rcherrueau committed Apr 3, 2012
1 parent 31a3a8c commit 7fc24f3
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 6 deletions.
13 changes: 13 additions & 0 deletions java/clock-stream/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
== About ==
Simple app stream clock time using websocket.

== How To ==
git clone https://code.google.com/p/rol3x-place/java/clock-stream/
mvn jetty:run

With your browser open http://localhost:8080/clock-webapp/clock_client.html
Open console to view console.log
Enjoy :)

Ronan-Alexandre Cherrueau

5 changes: 4 additions & 1 deletion opengl/shader/mesh_deformers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#define AMPLITUDE 0.5
#define FREQUENCY 6.0
float freq = 1.;

void init()
{
Expand Down Expand Up @@ -59,9 +60,11 @@ void display()
draw_cartesian_coordinates();

glColor3f(0.7, 0.7, 1.);
use_mesh_deformers_shader(AMPLITUDE, FREQUENCY);
use_mesh_deformers_shader(AMPLITUDE, freq);
draw_square(10., 4., 500);

freq += .005;

glutSwapBuffers();
glutPostRedisplay();
}
Expand Down
159 changes: 159 additions & 0 deletions scala/clock-stream/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
<artifactId>jetty-websocket</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -125,6 +135,155 @@
</execution>
</executions>
</plugin>
<!--
Build and Sign Jar
$ mvn jar:jar
The Maven JAR plugin packages the compiled classes and resources into a
JAR file and sets the Main-Class and Class-Path parameters in the
MANIFEST.MF file. In this case, the class path entries are all preceded by
lib/. This will let the dependency JAR files be packaged under a lib
subdirectory later
-->
<!--
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fr.rol3x.websocket.JettyLauncher</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
-->

<!--
The dependency plugin provides the capability to manipulate artifacts. It
can copy and/or unpack artifacts from local or remote repositories to a
specified location.
The Maven Dependency plugin copies the Maven dependencies into the a
directory under the build path. This will allow inclusion of dependent
JAR files in the final package.
-->
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<archive>
<manifest>
<mainClass>fr.rol3x.websocket.JettyLauncher</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
-->
<!--
The Assembly Plugin for Maven is primarily intended to allow users to
aggregate the project output along with its dependencies, modules, site
documentation, and other files into a single distributable archive.
The Maven Assembly plugin performs the final packaging as specified by the
package.xml descriptor :
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>package</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>target</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>target/lib</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
The package.xml descriptor generates a .tar.gz file containing the project
JAR file as well as the dependency JAR files under a lib subdirectory.
Self contained JAR, according to
http://earldouglas.com/a-self-contained-runnable-web-application/
Now a package can be created by running:
$ mvn package
This package can be extracted anywhere, and the web application run with:
$ java -jar selfcontained.jar
-->
<!--
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>fr.rol3x.websocket.JettyLauncher</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fr.rol3x.websocket.JettyLauncher</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package fr.rol3x.websocket

import org.eclipse.jetty.websocket.WebSocketServlet
import javax.servlet.http.HttpServletRequest
import utils.ClockStreamSocket

/**
* Websocket servlet offers service that stream current time.
*
* @author Ronan-Alexandre Cherrueau
*/

class ClockStreamServlet extends WebSocketServlet {
override def doWebSocketConnect(request: HttpServletRequest,
protocol: Nothing) = return ClockStreamSocket
protocol: String) = ClockStreamSocket
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@ package fr.rol3x.websocket.utils

import org.eclipse.jetty.websocket.WebSocket
import org.eclipse.jetty.websocket.WebSocket.Connection
import actors.Actor

/**
* Websocket streams current time.
*
* @author Ronan-Alexandre Cherrueau
*/
object ClockStreamSocket extends WebSocket {
private var connections = List[Connection]
private var connections = List[Connection]()
private val timer = new TimeActor(1000, new Actor {
def act {
loop {
react {
case WakeUp =>
val timeJSon = """{"hour":"%s", "minute":"%s", "second":"%s"}"""
.format(CurrentTime.getHour, CurrentTime.getMinute,
CurrentTime.getSecond);
connections.foreach{
c: Connection => if (c.isOpen) c sendMessage timeJSon
}
}
}
}
})

timer.start

override def onOpen(connection: Connection) = {
println("CONNECT [" + connection + "]")
Expand All @@ -20,3 +38,20 @@ object ClockStreamSocket extends WebSocket {
println("DISCONNECT [" + closeCode + ":" + message + "]")
}
}

case object WakeUp
case object Stop

class TimeActor(val timeout: Long, val timerTask: Actor)
extends Actor {
timerTask.start

def act {
loop {
reactWithin(timeout) {
case x =>
timerTask ! WakeUp
}
}
}
}
11 changes: 10 additions & 1 deletion scala/clock-stream/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>ClockStream</servlet-name>
<servlet-class>fr.rol3x.websocket.ClockStreamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ClockStream</servlet-name>
<url-pattern>/clock-stream/*</url-pattern>
</servlet-mapping>
</web-app>
52 changes: 51 additions & 1 deletion scala/clock-stream/src/main/webapp/clock_client.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Clock Stream WebSocket</title>
<script language="javascript" type="text/javascript">
var wsUri = "ws://localhost:8080/clock-webapp/clock-stream";

function init() {
if (!("WebSocket" in window)) {
console.error("Websockets NOT supported");
return ;
}

websocket = new WebSocket(wsUri);

websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}

function onOpen(evt) {
console.log("CONNECTED");
}

function onClose(evt) {
console.log("DISCONNECTED");
}

function onMessage(evt) {
console.log(evt.data);
time = JSON.parse(evt.data);

// Place current time
document.getElementById("hour").innerHTML = time.hour;
document.getElementById("minute").innerHTML = time.minute;
document.getElementById("second").innerHTML = time.second;
}

function onError(evt) {
console.error(evt.data);
}

window.addEventListener("load", init, false);
</script>
</head>

<body>
<h2>Hello World!</h2>
<h2>Clock Stream WebSocket</h2>
<div id="time">
<span id="hour"></span>:<span id="minute"></span>:<span id="second"></span>
</div>
</body>
</html>

0 comments on commit 7fc24f3

Please sign in to comment.