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: an handler that will be called 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: an handler that will be called 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: an handler that will be called 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 @param handler: an handler that will be called when undeploy has completed
108 """
109 org.vertx.java.deploy.impl.VertxLocator.container.undeployVerticle(id, DoneHandler(handler))
110
112 """Undeploy a module
113
114 Keyword arguments:
115 @param id: the unique id of the module
116 @param handler: an handler that will be called when undeploy has completed
117 """
118 org.vertx.java.deploy.impl.VertxLocator.container.undeployModule(id, DoneHandler(handler))
119
127
129 return org.vertx.java.deploy.impl.VertxLocator.vertx
130
132 """Sets a one-shot timer that will fire after a certain delay.
133
134 Keyword arguments:
135 @param delay: the delay, in milliseconds
136 @param handler: an handler that will be called when the timer fires
137 @return: the unique id of the timer
138 """
139 return java_vertx().setTimer(delay, TimerHandler(handler))
140
142 """Sets a periodic timer.
143
144 Keyword arguments:
145 @param delay: the period of the timer, in milliseconds
146 @param handler: an handler that will be called each time the timer fires
147 @return: the unique id of the timer
148 """
149 return java_vertx().setPeriodic(delay, TimerHandler(handler))
150
152 """Cancels a timer.
153
154 Keyword arguments:
155 @param id: the id of the timer, as returned from set_timer or set_periodic
156 @return: true if the timer was cancelled, false if it wasn't found.
157 """
158 return java_vertx().cancelTimer(id)
159
161 """Put the handler on the event queue for this loop so it will be run asynchronously
162 ASAP after this event has been processed
163
164 Keyword arguments:
165 @param handler: an handler representing the code that will be run ASAP
166 """
167 java_vertx().runOnLoop(DoneHandler(handler))
168
170 """ Cause the container to exit """
171 org.vertx.java.deploy.impl.VertxLocator.container.exit()
172