Permalink
Browse files

Code generator fix, renamed Netty transport, refactoring

  • Loading branch information...
1 parent dce7e13 commit 803907f43b4ccc68a8eb36d8b66cc32e864cbd28 Cyprien Noel committed Jan 7, 2013
Showing with 80 additions and 59 deletions.
  1. +2 −2 objectfabric.examples/java/src/main/java/part01/HelloWord.java
  2. +2 −2 objectfabric.examples/java/src/main/java/part02/RealTime.java
  3. +5 −5 objectfabric.examples/java/src/main/java/part03/Offline.java
  4. +3 −3 objectfabric.examples/java/src/main/java/part04/SchemesClient.java
  5. +2 −2 objectfabric.examples/java/src/main/java/part05/ObjectModel.java
  6. +2 −2 objectfabric.examples/java/src/main/java/part06/Locations.java
  7. +2 −2 objectfabric.examples/java/src/main/java/sample_chat/ChatClient.java
  8. +2 −2 objectfabric.examples/java/src/main/java/sample_images/Images.java
  9. +2 −2 objectfabric.examples/java/src/main/java/sample_quotes/QuotesClient.java
  10. +2 −2 objectfabric.examples/java/src/main/java/site_demo/Array.java
  11. +4 −1 objectfabric.examples/js/src/main/js/clients/sample_chat.html
  12. 0 objectfabric.examples/js/src/main/js/{readme → readme.txt}
  13. +4 −0 objectfabric/api/src/main/io/org/objectfabric/Memory.java
  14. +1 −1 objectfabric/api/src/main/misc/org/objectfabric/Debug.java
  15. +3 −3 objectfabric/extensions/netty/src/main/java/org/objectfabric/{NettyURIHandler.java → Netty.java}
  16. +2 −2 objectfabric/extensions/netty/src/main/java/org/objectfabric/NettyRemote.java
  17. +8 −2 objectfabric/jvm/src/main/generator/org/objectfabric/FileGeneratorClass.java
  18. +10 −3 objectfabric/jvm/src/main/generator/org/objectfabric/FileGeneratorValueSet.java
  19. +20 −17 objectfabric/jvm/src/main/generator/org/objectfabric/GeneratorBase.java
  20. +1 −1 objectfabric/jvm/src/main/generator/org/objectfabric/TypeDef.java
  21. +3 −5 objectfabric/jvm/src/test/java/org/objectfabric/Concurrent.java
@@ -14,7 +14,7 @@
import org.junit.Assert;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Workspace;
/**
@@ -33,7 +33,7 @@ public static void main(String[] args) {
/*
* Add a network transport to access remote resources.
*/
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
/*
* Get resource from server. (Server 'launchfirst.ExamplesServer' must be running)
@@ -18,7 +18,7 @@
import org.objectfabric.AbstractKeyListener;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.TMap;
import org.objectfabric.Workspace;
@@ -31,7 +31,7 @@
public static void main(String[] args) throws Exception {
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
/*
* Get map from server.
@@ -18,7 +18,7 @@
import org.junit.Assert;
import org.objectfabric.ClientURIHandler;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Remote;
import org.objectfabric.Remote.Status;
import org.objectfabric.Resource;
@@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception {
*/
{
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
/*
* Register the cache and get the resource.
@@ -64,7 +64,7 @@ public static void main(String[] args) throws Exception {
*/
{
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
workspace.addCache(cache);
/*
@@ -94,7 +94,7 @@ public static void main(String[] args) throws Exception {
*/
{
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
workspace.addCache(cache);
ClientURIHandler.enableNetwork();
@@ -117,7 +117,7 @@ public static void main(String[] args) throws Exception {
cache = new SQLite(file, true);
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
Map map = (Map) workspace.open("ws://localhost:8888/map").get();
Assert.assertEquals("value", map.get("example key"));
Assert.assertEquals("blah", map.get("offline update"));
@@ -21,11 +21,11 @@
import org.junit.Assert;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Workspace;
/**
- * URI schemes supported by {@link NettyURIHandler}, the default transport on the JVM.
+ * URI schemes supported by {@link Netty}, the default transport on the JVM.
*/
public class SchemesClient {
@@ -66,7 +66,7 @@ public static void main(String[] args) throws Exception {
* Self-signed certificate used by this test for SSL connections would not be accepted
* by Java's default trusted CA, so use a SSLContext that accepts any certificate.
*/
- public static class TestURIHandler extends NettyURIHandler {
+ public static class TestURIHandler extends Netty {
@Override
protected SSLContext createSSLContext() throws Exception {
@@ -20,7 +20,7 @@
import org.objectfabric.Generator;
import org.objectfabric.Immutable;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Resource;
import org.objectfabric.TArrayInteger;
import org.objectfabric.TMap;
@@ -50,7 +50,7 @@
public static void main(String[] args) throws Exception {
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
String uri = "ws://localhost:8888";
/*
@@ -28,7 +28,7 @@
import org.objectfabric.Location;
import org.objectfabric.Memory;
import org.objectfabric.NettySession;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Origin;
import org.objectfabric.Remote;
import org.objectfabric.Resource;
@@ -142,7 +142,7 @@ public ChannelPipeline getPipeline() throws Exception {
* Connect a client.
*/
workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
/*
* Client side, resolving a URI returns a resource whose location is the network.
@@ -17,7 +17,7 @@
import org.objectfabric.AbstractKeyListener;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Resource;
import org.objectfabric.TSet;
import org.objectfabric.Workspace;
@@ -36,7 +36,7 @@ public static void main(String[] args) throws Exception {
Workspace w = new JVMWorkspace();
// Enables network connections
- w.addURIHandler(new NettyURIHandler());
+ w.addURIHandler(new Netty());
// Get a room
Resource resource = w.open("ws://localhost:8888/room1");
@@ -34,7 +34,7 @@
import org.objectfabric.AsyncCallback;
import org.objectfabric.IndexListener;
import org.objectfabric.KeyListener;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Remote;
import org.objectfabric.Resource;
import org.objectfabric.SQLite;
@@ -73,7 +73,7 @@ public void run(String[] args) throws Exception {
workspace.addCache(new SQLite("temp/" + args[0], true));
}
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
workspace.openAsync("ws://localhost:8888/images", new AsyncCallback<Resource>() {
@@ -17,7 +17,7 @@
import org.objectfabric.AbstractResourceListener;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.Resource;
import org.objectfabric.Workspace;
@@ -33,7 +33,7 @@
public static void main(String[] args) {
ObjectModel.register();
Workspace workspace = new JVMWorkspace();
- workspace.addURIHandler(new NettyURIHandler());
+ workspace.addURIHandler(new Netty());
/*
* Write current prices and listens for future ones.
@@ -16,7 +16,7 @@
import org.objectfabric.IndexListener;
import org.objectfabric.JVMWorkspace;
-import org.objectfabric.NettyURIHandler;
+import org.objectfabric.Netty;
import org.objectfabric.TArrayLong;
import org.objectfabric.Workspace;
@@ -30,7 +30,7 @@ public static void main(String[] args) throws Exception {
Workspace w = new JVMWorkspace();
// Enable network connections
- w.addURIHandler(new NettyURIHandler());
+ w.addURIHandler(new Netty());
// Get live array of numbers through WebSocket
String uri = "ws://test.objectfabric.org/array";
@@ -10,8 +10,11 @@
<body>
<script>
function onof(of) {
+ var w = new of.workspace();
+ w.addURIHandler(new of.WebSocket());
+
// Get a room
- of.open("ws://localhost:8888/room1", function(err, resource) {
+ w.open("ws://localhost:8888/room1", function(err, resource) {
var messages = resource.get();
var me = "";
@@ -30,6 +30,10 @@
private final Backend _backend;
+ public Memory() {
+ this(false);
+ }
+
/**
* @param cache
* Must be true if this location is to be used as a cache (
@@ -36,7 +36,7 @@
public static final boolean COMMUNICATIONS = ENABLED && true;
- public static final boolean COMMUNICATIONS_LOG = ENABLED && true;
+ public static final boolean COMMUNICATIONS_LOG = ENABLED && false;
public static final boolean COMMUNICATIONS_LOG_ALL = ENABLED && false;
@@ -27,17 +27,17 @@
/**
* Netty (http://netty.io) transport. Supports "tcp", "ssl", "ws" and "wss" schemes.
*/
-public class NettyURIHandler extends ClientURIHandler {
+public class Netty extends ClientURIHandler {
private final ChannelFactory _factory;
private SSLContext _clientContext;
- public NettyURIHandler() {
+ public Netty() {
this(new NioClientSocketChannelFactory(ThreadPool.getInstance(), ThreadPool.getInstance()));
}
- public NettyURIHandler(ClientSocketChannelFactory factory) {
+ public Netty(ClientSocketChannelFactory factory) {
_factory = factory;
}
@@ -40,9 +40,9 @@
class NettyRemote extends Remote {
- private final NettyURIHandler _handler;
+ private final Netty _handler;
- protected NettyRemote(Address address, NettyURIHandler handler) {
+ protected NettyRemote(Address address, Netty handler) {
super(false, address);
_handler = handler;
@@ -223,8 +223,14 @@ void header() {
for (int i = 0; i < allValues.size(); i++) {
ValueDef value = allValues.get(i);
- if (!value.isReadOnly())
- wl(" " + value.Name + "(toCopy." + value.Name + "());");
+ if (!value.isReadOnly()) {
+ String name = Utils.getWithFirstLetterUp(value.Name);
+
+ if (g().addGetAndSet())
+ wl(" set" + name + "(toCopy.get" + name + "());");
+ else
+ wl(" " + value.Name + "(toCopy." + value.Name + "());");
+ }
}
wl(" }");
@@ -85,6 +85,7 @@ private void writeField(int index) {
String readVisibility = (value.publicVisibility().equals(FieldDef.TRUE) || value.publicVisibility().equals(FieldDef.READ)) ? "public" : "protected";
String writeVisibility = value.publicVisibility().equals(FieldDef.TRUE) ? "public" : "protected";
String type = value.type().fullName(_gen.target(), true);
+ String name = Utils.getWithFirstLetterUp(value.Name);
if (_gen.isCSharp()) {
if (value.Comment != null && value.Comment.length() > 0) {
@@ -93,7 +94,7 @@ private void writeField(int index) {
wl(" /// </summary>");
}
- wl(" public " + type + " " + Utils.getWithFirstLetterUp(value.Name));
+ wl(" public " + type + " " + name);
wl(" {");
wl(" get");
wl(" {");
@@ -125,7 +126,10 @@ private void writeField(int index) {
if (value.Comment != null && value.Comment.length() > 0)
wl(" /** " + value.Comment + " */");
- wl(" " + readVisibility + " final " + type + " " + value.Name + "() {");
+ if (_gen.addGetAndSet())
+ wl(" " + readVisibility + " final " + type + " get" + name + "() {");
+ else
+ wl(" " + readVisibility + " final " + type + " " + value.Name + "() {");
if (value.isReadOnly())
writeFieldGetReadOnly(value);
@@ -143,7 +147,10 @@ private void writeField(int index) {
if (value.Comment != null && value.Comment.length() > 0)
wl(" /** " + value.Comment + " */");
- wl(" " + writeVisibility + " final void " + value.Name + "(" + type + " value) {");
+ if (_gen.addGetAndSet())
+ wl(" " + writeVisibility + " final void set" + name + "(" + type + " value) {");
+ else
+ wl(" " + writeVisibility + " final void " + value.Name + "(" + type + " value) {");
writeFieldSet(value);
Oops, something went wrong.

0 comments on commit 803907f

Please sign in to comment.