Skip to content

Commit

Permalink
Small cosmetic updates and groovyfications
Browse files Browse the repository at this point in the history
  • Loading branch information
glaforge committed Apr 6, 2012
1 parent 1e04f30 commit 4de332a
Show file tree
Hide file tree
Showing 36 changed files with 128 additions and 116 deletions.
4 changes: 2 additions & 2 deletions src/examples/groovy/echo/EchoClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

vertx.createNetClient().connect(1234, "localhost") { socket->
vertx.createNetClient().connect(1234, "localhost") { socket ->

socket.dataHandler { buffer ->
println "Net client receiving: ${buffer.toString()}"
println "Net client receiving: ${buffer}"
}

// Now send some data
Expand Down
20 changes: 18 additions & 2 deletions src/examples/groovy/echo/EchoServer.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import org.vertx.groovy.core.streams.Pump
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import static org.vertx.groovy.core.streams.Pump.createPump

vertx.createNetServer().connectHandler { socket ->
Pump.createPump(socket, socket).start()
createPump(socket, socket).start()
}.listen(1234)


6 changes: 3 additions & 3 deletions src/examples/groovy/eventbus/Handler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

eb = vertx.eventBus()
def eb = vertx.eventBus()

address = 'example.address'
def address = 'example.address'

handler = { message -> println "Received message ${message.body}" }
def handler = { message -> println "Received message ${message.body}" }

eb.registerHandler(address, handler)
4 changes: 2 additions & 2 deletions src/examples/groovy/eventbus/Sender.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

eb = vertx.eventBus()
def eb = vertx.eventBus()

address = 'example.address'
def address = 'example.address'

def count = 0

Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/eventbusbridge/BridgeServer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

server = vertx.createHttpServer()
def server = vertx.createHttpServer()

// Serve the static resources
server.requestHandler { req ->
Expand Down
4 changes: 2 additions & 2 deletions src/examples/groovy/fanout/FanoutServer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

conns = vertx.sharedData().getSet('conns')
def conns = vertx.sharedData().getSet('conns')

eb = vertx.eventBus()
def eb = vertx.eventBus()

server = vertx.createNetServer().connectHandler { socket ->
conns << socket.writeHandlerID
Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/https/Server.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package https

server =
def server =
vertx.createHttpServer(SSL: true, keyStorePath: 'server-keystore.jks', keyStorePassword: 'wibble')

server.requestHandler { req ->
Expand Down
4 changes: 2 additions & 2 deletions src/examples/groovy/proxy/Proxy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package proxy

client = vertx.createHttpClient(port: 8282)
def client = vertx.createHttpClient(port: 8282)

server = vertx.createHttpServer().requestHandler { req ->
def server = vertx.createHttpServer().requestHandler { req ->
println "Proxying request: ${req.uri}"

def c_req = client.request(req.method, req.uri) { c_res ->
Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/sockjs/SockJSExample.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

server = vertx.createHttpServer()
def server = vertx.createHttpServer()

// Serve the index page
server.requestHandler { req ->
Expand Down
6 changes: 3 additions & 3 deletions src/examples/groovy/ssl/Server.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package ssl

import org.vertx.groovy.core.streams.Pump
import static org.vertx.groovy.core.streams.Pump.createPump

server = vertx.createNetServer(SSL: true, keyStorePath: 'server-keystore.jks', keyStorePassword: 'wibble')
def server = vertx.createNetServer(SSL: true, keyStorePath: 'server-keystore.jks', keyStorePassword: 'wibble')

server.connectHandler { sock ->
Pump.createPump(sock, sock).start()
createPump(sock, sock).start()
}.listen(1234, "localhost")
11 changes: 6 additions & 5 deletions src/examples/groovy/upload/Client.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package upload

import org.vertx.groovy.core.streams.Pump
import static org.vertx.groovy.core.streams.Pump.createPump

def req = vertx.createHttpClient(port: 8080).put("/someurl") { resp -> println "Response ${resp.statusCode}" }
def filename = "upload/upload.txt"
def fs = vertx.fileSystem()

req = vertx.createHttpClient(port: 8080).put("/someurl") { resp -> println "Response ${resp.statusCode}" }
filename = "upload/upload.txt"
fs = vertx.fileSystem()
fs.props(filename) { ares ->
def props = ares.result
println "props is ${props}"
Expand All @@ -29,7 +30,7 @@ fs.props(filename) { ares ->
fs.open(filename) { ares2 ->
def file = ares2.result
def rs = file.readStream
def pump = Pump.createPump(rs, req)
def pump = createPump(rs, req)
rs.endHandler { req.end() }
pump.start()
}
Expand Down
4 changes: 2 additions & 2 deletions src/examples/groovy/upload/Server.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package upload

import org.vertx.groovy.core.streams.Pump
import static org.vertx.groovy.core.streams.Pump.createPump

vertx.createHttpServer().requestHandler { req ->
req.pause()
def filename = "${UUID.randomUUID()}.uploaded"
vertx.fileSystem().open(filename) { ares ->
def file = ares.result
def pump = Pump.createPump(req, file.writeStream)
def pump = createPump(req, file.writeStream)
req.endHandler {
file.close {
println "Uploaded ${pump.bytesPumped} bytes to $filename"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/webapp/OrderMgr.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import groovy.json.JsonBuilder
eb = vertx.eventBus()
log = container.logger

handler = { orderMsg ->
def handler = { orderMsg ->
def order = orderMsg.body

log.info "Received order in order manager ${stringify(order)}"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/groovy/webapp/WebServer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

server =
def server =
vertx.createHttpServer(SSL: true, keyStorePath: 'server-keystore.jks', keyStorePassword: 'wibble')

// Serve the static resources
Expand Down
60 changes: 30 additions & 30 deletions src/main/groovy/org/vertx/groovy/core/Vertx.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -45,94 +45,94 @@ import org.vertx.java.core.shareddata.SharedData
*/
class Vertx {

private final VertxInternal jVertex;
private final EventBus eventBus;
private final org.vertx.groovy.core.file.FileSystem fileSystem;
private final VertxInternal jVertex
private final EventBus eventBus
private final org.vertx.groovy.core.file.FileSystem fileSystem

public Vertx(VertxInternal jVertex) {
this.jVertex = jVertex;
this.eventBus = new EventBus(jVertex.eventBus());
this.fileSystem = new org.vertx.groovy.core.file.FileSystem(jVertex.fileSystem());
Vertx(VertxInternal jVertex) {
this.jVertex = jVertex
this.eventBus = new EventBus(jVertex.eventBus())
this.fileSystem = new org.vertx.groovy.core.file.FileSystem(jVertex.fileSystem())
}

/**
* Create a non clustered Vertx instance
*/
public static Vertx newVertx() {
return new Vertx(new DefaultVertx());
static Vertx newVertx() {
return new Vertx(new DefaultVertx())
}

/**
* Create a clustered Vertx instance listening for cluster connections on the default port 25500
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Vertx newVertx(String hostname) {
return new Vertx(new DefaultVertx(hostname));
static Vertx newVertx(String hostname) {
return new Vertx(new DefaultVertx(hostname))
}

/**
* Create a clustered Vertx instance
* @param port The port to listen for cluster connections
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Vertx newVertx(int port, String hostname) {
return new Vertx(new DefaultVertx(port, hostname));
static Vertx newVertx(int port, String hostname) {
return new Vertx(new DefaultVertx(port, hostname))
}

/**
* Create a TCP/SSL server
*/
public NetServer createNetServer(Map props = null) {
return new DefaultNetServer(jVertex, props);
NetServer createNetServer(Map props = null) {
return new DefaultNetServer(jVertex, props)
}

/**
* Create a TCP/SSL client
*/
public NetClient createNetClient(Map props = null) {
return new DefaultNetClient(jVertex, props);
NetClient createNetClient(Map props = null) {
return new DefaultNetClient(jVertex, props)
}

/*
* Create an HTTP/HTTPS server
*/
public HttpServer createHttpServer(Map props = null) {
return new DefaultHttpServer(jVertex, props);
HttpServer createHttpServer(Map props = null) {
return new DefaultHttpServer(jVertex, props)
}

/**
* Create a HTTP/HTTPS client
*/
public HttpClient createHttpClient(Map props = null) {
return new DefaultHttpClient(jVertex, props);
HttpClient createHttpClient(Map props = null) {
return new DefaultHttpClient(jVertex, props)
}

/**
* Create a SockJS server that wraps an HTTP server
*/
public SockJSServer createSockJSServer(HttpServer httpServer) {
return new DefaultSockJSServer(jVertex, httpServer);
SockJSServer createSockJSServer(HttpServer httpServer) {
return new DefaultSockJSServer(jVertex, httpServer)
}

/**
* The File system object
*/
public org.vertx.groovy.core.file.FileSystem fileSystem() {
return fileSystem;
org.vertx.groovy.core.file.FileSystem fileSystem() {
return fileSystem
}

/**
* The event bus
*/
public EventBus eventBus() {
return eventBus;
EventBus eventBus() {
return eventBus
}

/**
* The shared data object
*/
public SharedData sharedData() {
return jVertex.sharedData();
SharedData sharedData() {
return jVertex.sharedData()
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ class Vertx {
}

org.vertx.java.core.Vertx toJavaVertx() {
return jVertex;
return jVertex
}

}
10 changes: 5 additions & 5 deletions src/main/groovy/org/vertx/groovy/core/buffer/Buffer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Buffer extends org.vertx.java.core.buffer.Buffer {
* Create an empty buffer
*/
Buffer() {
jBuffer = new JBuffer();
jBuffer = new JBuffer()
}

/**
Expand All @@ -61,28 +61,28 @@ class Buffer extends org.vertx.java.core.buffer.Buffer {
* automatic re-allocations as data is written to it.
*/
Buffer(int initialSizeHint) {
jBuffer = new JBuffer(initialSizeHint);
jBuffer = new JBuffer(initialSizeHint)
}

/**
* Create a new Buffer that contains the contents of a {@code byte[]}
*/
Buffer(byte[] bytes) {
jBuffer = new JBuffer(bytes);
jBuffer = new JBuffer(bytes)
}

/**
* Create a new Buffer that contains the contents of a {@code String str} encoded according to the encoding {@code enc}
*/
Buffer(String str, String enc) {
jBuffer = new JBuffer(str, enc);
jBuffer = new JBuffer(str, enc)
}

/**
* Create a new Buffer that contains the contents of {@code String str} encoded with UTF-8 encoding
*/
Buffer(String str) {
jBuffer = new JBuffer(str);
jBuffer = new JBuffer(str)
}

/**
Expand Down
12 changes: 3 additions & 9 deletions src/main/groovy/org/vertx/groovy/core/eventbus/EventBus.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ import org.vertx.java.core.json.JsonObject
*/
class EventBus {


private final JEventBus jEventBus;
private final JEventBus jEventBus

public EventBus(JEventBus jEventBus) {
this.jEventBus = jEventBus;
this.jEventBus = jEventBus
}

private Map handlerMap = new ConcurrentHashMap()
Expand Down Expand Up @@ -157,12 +156,7 @@ class EventBus {
def wrapped = { replyHandler(new Message(it)) } as Handler
return wrapped
} else {
return null;
return null
}
}




}

Loading

0 comments on commit 4de332a

Please sign in to comment.