1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 """
16 This module provides the entry point to the vert.x platform
17 """
18
19 import org.vertx.java.deploy.impl.VertxLocator
20 import org.vertx.java.core.json
21 import org.vertx.java.deploy.impl
22
23 from core.http import HttpServer, HttpClient
24 from core.net import NetServer, NetClient
25 from core.sock_js import SockJSServer
26 from core.handlers import TimerHandler, DoneHandler
27 from core.javautils import map_to_java, map_from_java
28
29 __author__ = "Scott Horn"
30 __email__ = "scott@hornmicro.com"
31 __credits__ = "Based entirely on work by Tim Fox http://tfox.org"
32
35
37 """ Return a HttpServer """
38 return HttpServer(**kwargs)
39
41 """ Return a HttpClient """
42 return HttpClient(**kwargs)
43
45 """ Return a NetServer """
46 return NetServer(**kwargs)
47
49 """ Return a NetClient """
50 return NetClient(**kwargs)
51
53 """ Return a SockJSServer """
54 return SockJSServer(http_server)
55
57 """ Get the logger for the verticle"""
58 return org.vertx.java.deploy.impl.VertxLocator.container.getLogger()
59
61 """Deploy a verticle. The actual deploy happens asynchronously
62
63 Keyword arguments:
64 @param main: the main of the verticle to deploy
65 @param config: dict configuration for the verticle
66 @param instances: number of instances to deploy
67 @param handler: will be executed when deploy has completed
68
69 """
70 if config != None:
71 config = org.vertx.java.core.json.JsonObject(map_to_java(config))
72
73 org.vertx.java.deploy.impl.VertxLocator.container.deployVerticle(main, config, instances, DoneHandler(handler))
74
76 """Deploy a worker verticle. The actual deploy happens asynchronously
77
78 Keyword arguments:
79 @param main: the main of the verticle to deploy
80 @param config: dict configuration for the verticle
81 @param instances: the number of instances to deploy
82 @param handler: handler will be executed when deploy has completed
83 """
84 if config != None:
85 config = org.vertx.java.core.json.JsonObject(map_to_java(config))
86 org.vertx.java.deploy.impl.VertxLocator.container.deployWorkerVerticle(main, config, instances, DoneHandler(handler))
87
88
89 -def deploy_module(module_name, config=None, instances=1, handler=None):
90 """Deploy a module. The actual deploy happens asynchronously
91
92 Keyword arguments:
93 @param module_name: The name of the module to deploy
94 @param config: dict configuration for the module
95 @param instances: Number of instances to deploy
96 @param handler: handler will be executed when deploy has completed
97 """
98 if config != None:
99 config = org.vertx.java.core.json.JsonObject(map_to_java(config))
100 org.vertx.java.deploy.impl.VertxLocator.container.deployModule(module_name, config, instances, DoneHandler(handler))
101
103 """Undeploy a verticle
104
105 Keyword arguments:
106 @param id: the unique id of the deployment
107 """
108 org.vertx.java.deploy.impl.VertxLocator.container.undeployVerticle(id)
109
111 """Undeploy a module
112
113 Keyword arguments:
114 @param id: the unique id of the module
115 """
116 org.vertx.java.deploy.impl.VertxLocator.container.undeployModule(id)
117
125
127 return org.vertx.java.deploy.impl.VertxLocator.vertx
128
130 """Sets a one-shot timer that will fire after a certain delay.
131 This method will accept either a Proc or a block.
132
133 Keyword arguments:
134 @param delay: the delay, in milliseconds
135 @param handler: a block representing the code that will be run after the delay the unique id of the timer
136 """
137 java_vertx().setTimer(delay, TimerHandler(handler))
138
140 """Sets a periodic timer.
141
142 Keyword arguments:
143 @param delay: the period of the timer, in milliseconds
144 @param handler: a block representing the code that will be when the timer fires the unique id of the timer
145 """
146 java_vertx().setPeriodic(delay, TimerHandler(handler))
147
148
150 """Cancels a timer.
151
152 Keyword arguments:
153 @param id: the id of the timer, as returned from set_timer or set_periodic
154 @return: true if the timer was cancelled, false if it wasn't found.
155 """
156 java_vertx().cancelTimer(id)
157
158
160 """Put the handler on the event queue for this loop so it will be run asynchronously
161 ASAP after this event has been processed
162
163 Keyword arguments:
164 @param handler: a block representing the code that will be run ASAP
165 """
166 java_vertx().runOnLoop(DoneHandler(handler))
167