def run(self):
        gson = Gson()

        # Initialize a zeromq context
        context = ZMQ.context(1)

        #print('{}> Trying to connect...'.format(wrk_num))

        # Set up a channel to receive work from the ventilator
        work_receiver = context.socket(ZMQ.PULL)
        work_receiver.connect("tcp://127.0.0.1:5557")

        # Set up a channel to send result of work to the results reporter
        results_sender = context.socket(ZMQ.PUSH)
        results_sender.connect("tcp://127.0.0.1:5558")

        # Set up a channel to receive control messages over
        control_receiver = context.socket(ZMQ.SUB)
        control_receiver.connect("tcp://127.0.0.1:5559")
        control_receiver.subscribe("")

        # Set up a poller to multiplex the work receiver and control receiver channels
        poller = context.poller(2)
        poller.register(work_receiver, ZMQ.Poller.POLLIN)
        poller.register(control_receiver, ZMQ.Poller.POLLIN)

        # Loop and accept messages from both channels, acting accordingly
        while True:
            poller.poll()

            # If the message came from work_receiver channel, square the number
            # and send the answer to the results reporter
            #if socks.get(work_receiver) == zmq.POLLIN:
            if poller.pollin(0):
                msg = work_receiver.recv(0)
                msg = msg.tostring()
                work_message = gson.fromJson(msg, HashMap)
                num = work_message.get('num')
                product = num * num
                answer_message = HashMap()
                answer_message.put('worker', self.wrk_num)
                answer_message.put('result', product)
                answer_message.put('input', num)
                msg = gson.toJson(answer_message)
                results_sender.send(msg, 0)

            # If the message came over the control channel, shut down the worker.
            #if socks.get(control_receiver) == zmq.POLLIN:
            if poller.pollin(1):
                msg = control_receiver.recv(0)
                control_message = msg.tostring()
                if control_message == "FINISHED":
                    #print("{}> Received FINSHED, quitting!".format(wrk_num))
                    break
Exemple #2
0
def handle_request(json_dict):
    try:
        json_string = Gson().toJson(json_dict)
        event = GsonUtils.fromJson(json_string, IssueCommentPayload)
    except StandardError:
        _, e, _ = sys.exc_info()
        logger.warn(
            "Could not parse payload as an issue comment, check your GitHub Webhook "
            "configuration. Error: %s. Payload:\n%s" % (e, json_string))
        return

    if not event.getIssue() or not event.getIssue().getPullRequest(
    ) or not event.getIssue().getPullRequest().getUrl():
        logger.debug("Issue #%s is not a pull request" %
                     event.getIssue().getNumber())
        return

    if event.getIssue().getState() != IssueService.STATE_OPEN:
        logger.debug("Pull request #%s is already closed" %
                     event.getIssue().getNumber())
        return

    message = event.getComment().getBody().lower()
    if not _is_xlr_command(message):
        logger.debug('Comment is not an XL Release command: "%s"' % message)
        return

    repo_full_name = re.search(
        '.*github.com/repos/(.*)/pulls/.*',
        event.getIssue().getPullRequest().getUrl()).group(1)
    pr_number = event.getIssue().getNumber()
    pr_title = event.getIssue().getTitle()

    start_pr_release(repo_full_name, pr_number, pr_title, message)
def export_calibration(imp, path):
    cal = imp.getCalibration()
    meta = dict(w=cal.pixelWidth,
                w_unit=cal.getXUnit(),
                h=cal.pixelHeight,
                h_unit=cal.getYUnit(),
                t=cal.frameInterval,
                t_unit=cal.getTimeUnit())
    writer = FileWriter(path)
    Gson().toJson(meta, writer)
    writer.close()  # important
    def run(self):
        gson = Gson()

        # Initialize a zeromq context
        context = ZMQ.context(1)

        # Set up a channel to receive results
        results_receiver = context.socket(ZMQ.PULL)
        results_receiver.bind("tcp://127.0.0.1:5558")

        # Set up a channel to send control commands
        control_sender = context.socket(ZMQ.PUB)
        control_sender.bind("tcp://127.0.0.1:5559")

        for task_nbr in xrange(NUM):
            msg = results_receiver.recv(0)
            msg = msg.tostring()
            result_message = gson.fromJson(msg, HashMap)
            #print "Worker %i answered: %i" % (result_message['worker'], result_message['result'])
            assert result_message['result'] == result_message['input'] * result_message['input']

            # Signal to all workers that we are finsihed
        control_sender.send("FINISHED", 0)
        time.sleep(1)
def export_rois(rm, is_hyperstack, path):
    frame = (lambda roi: roi.getTPosition()) if is_hyperstack else (
        lambda roi: roi.getPosition())
    rois = rm.getRoisAsArray()
    polys = {}
    for roi in rois:
        fp = roi.getFloatPolygon()
        polys[roi.getName()] = {
            't': frame(roi),
            'x': fp.xpoints,
            'y': fp.ypoints
        }

    writer = FileWriter(path)
    Gson().toJson(polys, writer)
    writer.close()  # important
Exemple #6
0
class Response(object):

    def __init__(self,status,data=None):
        # convert data to Java Map
        self.data = data
        #self.mapper = ObjectMapper()
        self.status = status
        self.gson = Gson()

    def to_json(self,return_data):
        if return_data is True:
            data = self.data
            # or writeValueAsBytes() to serialize to a byte array
            response = dict(status=self.status,results=self.data)
            #writer = self.mapper.writer()
            #json = writer.writeValueAsString(response)
            json = self.gson.toJson(response)
        else:
            json = str(self.status)
        return json
        return response.toString();
    }

    /*
     *  Most of this was not written by the team, only changed the return type to void.
     *  Source: https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-java-translate
     *
     *  Sets internal class attribute called translatedText to be the translation of "text" parameter.
     */
    public void translateAString (String text) throws Exception {
        URL url = new URL (HOST + PATH + params);

        List<RequestBody> objList = new ArrayList<>();
        objList.add(new RequestBody(text));
        String content = new Gson().toJson(objList);
        translatedText = Post(url, content);
    }

    /*
     *  This function was not written by the team.
     *  Source: https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-java-translate
     */
    public String prettify(String json_text) {
        JsonParser parser = new JsonParser();
        JsonElement json = parser.parse(json_text);
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        return gson.toJson(json);
    }

    /*
Exemple #8
0
 def __init__(self,status,data=None):
     # convert data to Java Map
     self.data = data
     #self.mapper = ObjectMapper()
     self.status = status
     self.gson = Gson()