Skip to content

Commit

Permalink
move to netty2go, initial js generation
Browse files Browse the repository at this point in the history
  • Loading branch information
RuedigerMoeller committed May 27, 2014
1 parent b472013 commit 35953fa
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 350 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,4 @@ target/
.gradle/
*.iml
*.bin
tempgen/
6 changes: 6 additions & 0 deletions minbin-generate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<version>2.00</version>
</dependency>

<dependency>
<groupId>de.ruedigermoeller</groupId>
<artifactId>temp-late</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
Expand Down
12 changes: 12 additions & 0 deletions minbin-generate/src/main/java/minbin/gen/GenContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package minbin.gen;

import de.ruedigermoeller.serialization.FSTClazzInfo;

/**
* Created by ruedi on 27.05.2014.
*/
public class GenContext {

public FSTClazzInfo clazz;

}
9 changes: 8 additions & 1 deletion minbin-generate/src/main/java/minbin/gen/MBGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import de.rm.testserver.protocol.BasicValues;
import de.rm.testserver.protocol.Meta;
import de.ruedigermoeller.serialization.FSTConfiguration;
import de.ruedigermoeller.template.TemplateExecutor;

import java.util.List;

Expand All @@ -12,8 +16,11 @@ public class MBGen {


private void generate() {
FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
GenContext ctx = new GenContext();
ctx.clazz = conf.getClassInfo(BasicValues.class);
if ( lang == Lang.javascript ) {

TemplateExecutor.Run("./src/main/resources/js/js.jsp",ctx);
}

}
Expand Down
29 changes: 29 additions & 0 deletions minbin-generate/src/main/resources/js/js.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%
import java.util.*;
import java.io.*;
import de.ruedigermoeller.template.*;
// add imports you need during generation =>
import minbin.gen.*;
import de.ruedigermoeller.serialization.*;
// this header is always required to make it work. Cut & Paste this as template
public class CLAZZNAME implements IContextReceiver
{
public void receiveContext(Object o, PrintStream out) throws Exception
{
// asign your context
GenContext CTX = (GenContext)o;
FSTClazzInfo CLZ = CTX.clazz;
FSTClazzInfo.FSTFieldInfo fi[] = CLZ.getFieldInfo();
%>
function J<%+CLZ.getClazz().getSimpleName()%>(map) {
<% for (int i = 0; i < fi.length; i++ ) {
%> this.__<%+fi[i].getField().getName()%> = ;
<% } /*for*/
%>}
<%
// this footer is always required (to match opening braces in header
}
}
%>
6 changes: 3 additions & 3 deletions testshell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.19.Final</version>
<groupId>de.ruedigermoeller</groupId>
<artifactId>netty2go</artifactId>
<version>1.01</version>
</dependency>

<!-- test dependencies -->
Expand Down
64 changes: 64 additions & 0 deletions testshell/src/main/java/de/rm/testserver/TestServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.rm.testserver;

import de.rm.testserver.protocol.BasicValues;
import de.rm.testserver.protocol.MirrorRequest;
import de.rm.testserver.protocol.Person;
import de.rm.testserver.protocol.TestRequest;
import de.ruedigermoeller.serialization.FSTConfiguration;
import io.netty.channel.ChannelHandlerContext;
import org.nustaq.netty2go.NettyWSHttpServer;
import org.nustaq.webserver.WebSocketHttpServer;

import java.io.File;
import java.io.Serializable;

/**
* Created by ruedi on 27.05.14.
*/
public class TestServer extends WebSocketHttpServer {

FSTConfiguration conf = FSTConfiguration.createCrossPlatformConfiguration();
static String ClassMap[][] = new String[][] {
{ "person", Person.class.getName() },
{ "basicVals", BasicValues.class.getName() },
{ "mirror", MirrorRequest.class.getName() },
{ "testReq", TestRequest.class.getName() },
};


public TestServer(File contentRoot) {
super(contentRoot);
conf.registerCrossPlatformClassMapping(ClassMap);
}

@Override
public void onOpen(ChannelHandlerContext ctx) {
sendWSBinaryMessage( ctx, conf.asByteArray(new BasicValues()) );
}

@Override
public void onBinaryMessage(ChannelHandlerContext ctx, byte[] buffer) {
Object msg = null;
try {
msg = conf.asObject(buffer);
} catch (Throwable ex) {
ex.printStackTrace();
}
if (msg instanceof MirrorRequest) {
sendWSBinaryMessage(ctx, conf.asByteArray((Serializable) msg));
} else {
byte error[] = conf.asByteArray("Error");
sendWSBinaryMessage(ctx,error);
}
}

public static void main(String[] args) throws Exception {
int port;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
} else {
port = 8887;
}
new NettyWSHttpServer(port, new TestServer(new File(".") )).run();
}
}
Loading

0 comments on commit 35953fa

Please sign in to comment.