Commit c5ef8843 authored by Julian Hochstetter's avatar Julian Hochstetter

Task #3851: initial netty-socket.io server

parent 82283cc1
......@@ -21,7 +21,7 @@
<url>http://maven.mni.thm.de/content/groups/public</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<id>sonatypesnapshots</id>
<name>Sonatype Snapshot Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
......@@ -138,6 +138,16 @@
<artifactId>spring-security-oauth-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.5.7.Final</version>
</dependency>
<dependency>
<groupId>com.corundumstudio.socketio</groupId>
<artifactId>netty-socketio</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -154,6 +164,17 @@
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.6.5.v20120716</version>
<!--
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webApp>
<contextPath>/</contextPath>
<baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">
<resourcesAsCSV>src/main/webapp,../arsnova-js/src/main/webapp,../arsnova-legacy-js/src/main/webapp,../dojo-war/src/main/webapp</resourcesAsCSV>
</baseResource>
</webApp>
</configuration>
-->
</plugin>
</plugins>
</build>
......
package de.thm.arsnova.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.listener.DataListener;
import com.corundumstudio.socketio.listener.DisconnectListener;
import de.thm.arsnova.services.ISessionService;
import de.thm.arsnova.socket.message.Authorize;
import de.thm.arsnova.socket.message.Feedback;
public class ARSnovaSocketIOServer {
@Autowired
private ISessionService sessionService;
private final Logger logger = LoggerFactory.getLogger(getClass());
private int portNumber;
private final Configuration config;
private SocketIOServer server;
public ARSnovaSocketIOServer() {
config = new Configuration();
}
public void startServer() throws Exception {
config.setPort(portNumber);
config.setHostname("localhost");
server = new SocketIOServer(config);
server.addEventListener("setFeedback", Feedback.class,
new DataListener<Feedback>() {
@Override
public void onData(SocketIOClient client, Feedback data) {
logger.info("setFeedback.onData: Client: {}, message: {}", new Object[] {client, data});
sessionService.postFeedback(data.getKeyword(), data.getValue());
server.getBroadcastOperations().sendEvent("updateFeedback", data);
}
});
server.addConnectListener(new ConnectListener() {
@Override
public void onConnect(SocketIOClient client) {
logger.info("addConnectListener.onConnect: Client: {}", new Object[] {client});
}
});
server.addDisconnectListener(new DisconnectListener() {
@Override
public void onDisconnect(SocketIOClient client) {
logger.info("addDisconnectListener.onDisconnect: Client: {}", new Object[] {client});
}
});
server.start();
}
public void stopServer() throws Exception {
logger.debug("In stopServer method of class: {}", getClass().getName());
for(SocketIOClient client : server.getAllClients()) {
client.disconnect();
}
server.stop();
}
public int getPortNumber() {
return portNumber;
}
@Required
public void setPortNumber(int portNumber) {
this.portNumber = portNumber;
}
}
\ No newline at end of file
package de.thm.arsnova.socket.message;
public class Authorize {
private String user;
private String socketid;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getSocketid() {
return socketid;
}
public void setSocketid(String socketid) {
this.socketid = socketid;
}
@Override
public String toString() {
return "user: " + user + ", socketid: " + socketid;
}
}
package de.thm.arsnova.socket.message;
public class Feedback {
private int value;
private String sessionkey;
public String getSessionkey() {
return sessionkey;
}
public void setSessionkey(String keyword) {
this.sessionkey = keyword;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
@Override
public String toString() {
return "Feedback, sessionkey: " + sessionkey + ", value: " + value;
}
}
\ No newline at end of file
......@@ -23,4 +23,8 @@
<context:component-scan base-package="de.thm.arsnova" />
<context:annotation-config />
<bean id="socketServer" class="de.thm.arsnova.socket.ARSnovaSocketIOServer" init-method="startServer" destroy-method="stopServer">
<property name="portNumber" value="18018"></property>
</bean>
</beans>
......@@ -31,7 +31,7 @@
<servlet-name>api</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment