<commit_before>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
library spark.services;

import 'dart:convert';
import 'dart:async';
import 'dart:isolate';

import 'lib/compiler.dart';


/**
 * This is a separate application spawned by Spark (via Services) as an isolate
 * for use in running long-running / heaving tasks.
 */
void main(List<String> args, SendPort sendPort) {
  // For use with top level print() helper function.
  _printSendPort = sendPort;

  final ServicesIsolate servicesIsolate = new ServicesIsolate(sendPort);
}

/**
 * Defines a handler for all worker-side service implementations.
 */
class ServicesIsolate {
  final SendPort _sendPort;

  // Fired when host responds to message
  Stream<ActionEvent> _onResponseMessage;

  // Fired when host originates a message
  Stream<ActionEvent> _onHostMessage ;

  // Services:
  // ExampleServiceImpl example;

  ServicesIsolate(this._sendPort) {
    StreamController<ActionEvent> hostMessageController =
        new StreamController<ActionEvent>.broadcast();
    StreamController<ActionEvent> responseMessageController =
        new StreamController<ActionEvent>.broadcast();

    _onHostMessage = hostMessageController.stream;
    _onResponseMessage = responseMessageController.stream;

    ReceivePort receivePort = new ReceivePort();
    _sendPort.send(receivePort.sendPort);

    receivePort.listen((arg) {
      String data = arg["data"];
      // TODO(ericarnold): differntiate between host and response messages ...
      //hostMessageController.add(new ActionEvent(
      //    arg["serviceId"], arg["actionId"], arg["callId"], JSON.decode(data)));
      //responseMessageController.add(new ActionEvent(
      //    arg["serviceId"], arg["actionId"], arg["callId"], JSON.decode(data)));
    });
  }


  _handleMessage(ActionEvent event) {
    // TODO(ericarnold): Initialize each requested ServiceImpl subclass as
    //    requested by the sender and add listeners to them to facilitate
    //    two-way communication.
    // TODO(ericarnold): Route ActionEvent by serviceId to the appropriate
    //    ServiceImpl instance.
  }


  // Sends a response message.
  Future<ActionEvent> _sendResponse(ActionEvent event, Map data,
      [bool expectResponse = false]) {
    _sendPort.send({
      "serviceId": event.serviceId,
      "actionId": event.actionId,
      "callId": event.callId,<commit_msg>Maintaining ping functionality<commit_after>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
library spark.services;

import 'dart:convert';
import 'dart:async';
import 'dart:isolate';

import 'lib/compiler.dart';


/**
 * This is a separate application spawned by Spark (via Services) as an isolate
 * for use in running long-running / heaving tasks.
 */
void main(List<String> args, SendPort sendPort) {
  // For use with top level print() helper function.
  _printSendPort = sendPort;

  final ServicesIsolate servicesIsolate = new ServicesIsolate(sendPort);
}

/**
 * Defines a handler for all worker-side service implementations.
 */
class ServicesIsolate {
  final SendPort _sendPort;

  // Fired when host responds to message
  Stream<ActionEvent> _onResponseMessage;

  // Fired when host originates a message
  Stream<ActionEvent> _onHostMessage ;

  // Services:
  // ExampleServiceImpl example;

  ServicesIsolate(this._sendPort) {
    StreamController<ActionEvent> hostMessageController =
        new StreamController<ActionEvent>.broadcast();
    StreamController<ActionEvent> responseMessageController =
        new StreamController<ActionEvent>.broadcast();

    _onHostMessage = hostMessageController.stream;
    _onResponseMessage = responseMessageController.stream;

    ReceivePort receivePort = new ReceivePort();
    _sendPort.send(receivePort.sendPort);

    receivePort.listen((arg) {
      _sendPort.send(arg);

      //String data = arg["data"];
      // TODO(ericarnold): differntiate between host and response messages ...
      //hostMessageController.add(new ActionEvent(
      //    arg["serviceId"], arg["actionId"], arg["callId"], JSON.decode(data)));
      //responseMessageController.add(new ActionEvent(
      //    arg["serviceId"], arg["actionId"], arg["callId"], JSON.decode(data)));
    });
  }


  _handleMessage(ActionEvent event) {
    // TODO(ericarnold): Initialize each requested ServiceImpl subclass as
    //    requested by the sender and add listeners to them to facilitate
    //    two-way communication.
    // TODO(ericarnold): Route ActionEvent by serviceId to the appropriate
    //    ServiceImpl instance.
  }


  // Sends a response message.
  Future<ActionEvent> _sendResponse(ActionEvent event, Map data,
      [bool expectResponse = false]) {
    _sendPort.send({
      "serviceId": event.serviceId,
      "actionId": event.actionId,
      "callId": event.callId,
{'fraction_non_alphanumeric': 0.10381978452497552, 'fraction_numerical': 0.0015670910871694416, 'mean_word_length': 3.727777777777778, 'pattern_counts': {'":': 6, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4792677', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1369, 'n_words': 420}