def connect_handler(socket): vertx.logger().info('I am connected') @socket.data_handler def receive(buffer): vertx.logger().info('receive %d bytes of data, <%s>'%(buffer.length,buffer)) def period_send(tid): socket.write_str('hello socket\r\n') tid=vertx.set_periodic(1000,period_send) @socket.close_handler def closed(): vertx.logger().info('I am disconnected')
def connect_handler(socket): vertx.logger().info('I am connected') @socket.data_handler def receive(buffer): vertx.logger().info('receive %d bytes of data, <%s>' % (buffer.length, buffer)) def period_send(tid): socket.write_str('hello socket\r\n') tid = vertx.set_periodic(1000, period_send) @socket.close_handler def closed(): vertx.logger().info('I am disconnected')
import vertx from core.event_bus import EventBus from core.file_system import FileSystem from core.http import RouteMatcher from server import upload from server import file_service #inicialize server = vertx.create_http_server() route_matcher = RouteMatcher() logger = vertx.logger() fs = vertx.file_system() app_config = vertx.config() #set global path_web = app_config['paths']['web'] path_public = app_config['paths']['path_public'] path_symlink = app_config['paths']['path_symlink'] #cros module variable ##TODO upload.path_public = path_public file_service.path_public = path_public file_service.path_private = app_config['paths']['path_private'] upload.path_symlink = path_symlink upload.path_upload = app_config['paths']['path_private'] upload.path_temp = app_config['paths']['path_temp'] def index_handler(req): req.response.send_file( "%sindex.html"% path_web)
def listen_handler(err, server): if err is None: vertx.logger().info('Server is listen OK') else: err.printStackTrace()
def closed(): vertx.logger().info('I am disconnected')
def receive(buffer): vertx.logger().info('receive %d bytes of data, <%s>' % (buffer.length, buffer))
import vertx from core.event_bus import EventBus import uuid logger = vertx.logger() class CredentialManager(object): ADDRESS = 'hbdriver:credentials' def __init__(self, credentials, address=ADDRESS): self._pool = list(credentials) self._inuse = {} EventBus.register_handler(address, handler=self.handle) def handle(self, msg): cmd = msg.body['command'] actor = msg.body['id'] if cmd == 'acquire': try: creds = self._pool.pop(0) self._inuse[actor] = creds logger.info("%s has acquired credentials" % actor) msg.reply(dict(status=200, credentials=creds)) except IndexError: msg.reply(dict(status=404, msg="No credentials available")) if cmd == 'release': try: creds = self._inuse.pop(actor) self._pool.append(creds) logger.info("%s has released credentials" % actor)
#!/usr/bin/env python # -*- coding: utf-8 -*- import vertx from frobnicate import handler _log = vertx.logger() _log.info("hello there") server = vertx.create_http_server() server.request_handler(handler) server.listen(8080)
def receive(buffer): vertx.logger().info('receive %d bytes of data, <%s>'%(buffer.length,buffer))
import vertx import random as rnd import time as time from core.event_bus import EventBus def create_package(): result = { 'time': int(round(time.time() * 1000)), 'data': 200 #rnd.randint(0,500), } return result def handler(tid): EventBus.publish("data.source.raw", create_package()) tid = vertx.set_periodic(1, handler=handler) vertx.logger().info("DataProducer started")