rmi_generator 0.0.4

Remote Method Invocation for dart #

Build Status

This project provides an solution for remote method invocation in dart without the use of reflection. Since reflection is only available on the Dart VM but not on a JS VM, this solution is entirely based on code generation instead.

Getting Started #

Let's say you want to invoke methods of an ExampleClass looking like this:

// in example.dart
part 'example.g.dart';
class ExampleClass implements RmiTarget {
  void someMethod() {
	print('some stuff');
  }

  ExampleClass();
  // required boilerplate for code generation
  @override
  Object invoke(Invocation invocation) =>
      _$ExampleClassInvoker.invoke(invocation, this);
  factory ExampleClass.getRemote(Context context, String uuid) =>
      _$ExampleClassRmi.getRemote(context, uuid);
  Provision provideRemote(Context context) =>
      _$ExampleClassRmi.provideRemote(context, this);
}

And you have the actual object present on machine A:

ExampleClass exampleObject = new ExampleClass();
/// ...setup some network connection, get a Stream and a StreamSink from it
Stream input = ...
StreamSink output = ...
Provision provision = exampleObject.provideRemote(new Context(input, output));
/// provision contains the uuid which identifies the object on this machine

On machine B:

/// Again we have the input and output you get from your network 
/// and additionally you have to provide the uuid from before
Stream input = ...
StreamSink output = ...
String uuid = ... provision.uuid // from above
ExampleClass remoteObject = ExampleClass.getRemote(new Context(input, output), uuid);
remoteObject.someMethod(); // prints 'some stuff' on the other machine

TODO #

  • generator warning when no factory was implemented
  • also for part ...
  • not invocable, not proxied method annotation
  • operators
  • think about object methods, tostring hashcode
  • check lang spec for other members what else could be here
  • Serialize exceptions
  • send stack on exception
  • Add else clause to invoker to provide an error message
  • write doc
  • cleanup exports
  • write install script
  • if static getRemoteis not specified, do not write it for stub constructors simply put a waringing
  • STREAMS!!!!
  • thorw exceptions from invoke
  • Proxy does implement, extend should be possible
  • sosuchmethod...
  • reduce tests to a minimum code
  • warn on rmi non future method
  • warn for contrast metadata
  • class hierarchy metadata
  • pass stream and future null arguments

Changelog #

0.0.4 #

  • JSON Serialization instead of build_values
  • Streams and Futures can be transferred
  • operators implemented
  • metaflags added, possibly forces a RmiTarget to be serialized instead of remote implemented

0.0.3 #

Compile Error fixed

0.0.2 #

Added examples

0.0.1 #

Initial version with all basics implemented

example/lib/example.dart

import 'package:rmi/remote_method_invocation.dart';
import 'package:rmi/proxy.dart';
import 'dart:async';

part 'example.g.dart';

class ExampleClass implements RmiTarget {
  void someMethod() {
    print('some stuff');
  }

  ExampleClass();
  // required boilerplate for code generation
  @override
  Object invoke(Invocation invocation) =>
      _$ExampleClassInvoker.invoke(invocation, this);
  factory ExampleClass.getRemote(Context context, String uuid) =>
      _$ExampleClassRmi.getRemote(context, uuid);
  Provision provideRemote(Context context) =>
      _$ExampleClassRmi.provideRemote(context, this);
}

main() {
  StreamController<String> aToB = StreamController();
  StreamController<String> bToA = StreamController();

  ExampleClass remoteTarget = new ExampleClass();
  var provision = remoteTarget.provideRemote(new Context(aToB.stream, bToA));

  ExampleClass proxy =
      ExampleClass.getRemote(new Context(bToA.stream, aToB), provision.uuid);

  proxy.someMethod();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  rmi_generator: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:rmi_generator/rmi_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
1
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30
Overall:
Weighted score of the above. [more]
6
Learn more about scoring.

We analyzed this package on Jul 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms:

Error(s) prevent platform classification:

Error(s) in lib/invoker_generator.dart: Target of URI doesn't exist: 'package:source_gen_helpers/class/util.dart'.

Health issues and suggestions

Fix lib/proxy_generator.dart. (-99.69 points)

Analysis of lib/proxy_generator.dart failed with 20 errors, 7 hints, including:

line 8 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/class/class_visitor.dart'.

line 9 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/class/output_visitor.dart'.

line 10 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/class/override_visitor.dart'.

line 11 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/class/util.dart'.

line 12 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/filter_generator.dart'.

Fix lib/invoker_generator.dart. (-57.81 points)

Analysis of lib/invoker_generator.dart failed with 3 errors:

line 9 col 8: Target of URI doesn't exist: 'package:source_gen_helpers/class/util.dart'.

line 41 col 28: The method 'allClassMember' isn't defined for the class 'InvokerGenerator'.

line 48 col 14: The method 'filterConcreteElements' isn't defined for the class 'InvokerGenerator'.

Fix lib/builder.dart. (-25 points)

Analysis of lib/builder.dart failed with 1 error:

line 9 col 28: The element type 'ProxyGenerator' can't be assigned to the list type 'Generator'.

Document public APIs. (-0.05 points)

59 out of 61 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/rmi_generator.dart. (-2.48 points)

Analysis of lib/rmi_generator.dart reported 5 hints:

line 47 col 7: DO use curly braces for all flow control structures.

line 48 col 9: DO use curly braces for all flow control structures.

line 91 col 22: DO use curly braces for all flow control structures.

line 92 col 7: DO use curly braces for all flow control structures.

line 94 col 54: DO use curly braces for all flow control structures.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/invoker_generator.dart: Target of URI doesn't exist: 'package:source_gen_helpers/class/util.dart'.

Support latest dependencies. (-40 points)

The version constraint in pubspec.yaml does not support the latest published versions for 4 dependencies (analyzer, build, build_config, source_gen).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.33.3 0.33.6+1 0.37.0
build ^1.0.0 1.1.0 1.1.5
build_config ^0.3.1 0.3.2 0.4.1
source_gen ^0.9.0 0.9.4+1 0.9.4+2
Transitive dependencies
args 1.5.2
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.16.1
dart_style 1.2.0 1.2.9
front_end 0.1.6+9 0.1.20
glob 1.1.7
html 0.14.0+2
kernel 0.3.6+9 0.3.20
logging 0.11.3+2
meta 1.1.7
package_config 1.0.5
path 1.6.2
pedantic 1.8.0+1
plugin 0.2.0+3
pub_semver 1.4.2
pubspec_parse 0.1.4
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.1.16
Dev dependencies
json_annotation any 2.4.0
source_gen_helpers any

Admin