Skip to content
This repository was archived by the owner on Mar 18, 2021. It is now read-only.

Ubuntu 18.04 aqueduct serve error #494

Closed
NTMS2017 opened this issue Jul 12, 2018 · 4 comments
Closed

Ubuntu 18.04 aqueduct serve error #494

NTMS2017 opened this issue Jul 12, 2018 · 4 comments

Comments

@NTMS2017
Copy link

I try to run my web api and got this error....

niyazi@niyazi-virtual-machine:~/aqueduct3_pro/niyaziapi$ aqueduct serve
-- Aqueduct CLI Version: 3.0.0-beta.1
-- Aqueduct project version: 3.0.0-beta.1
-- Preparing...
-- Starting application 'niyaziapi/niyaziapi'
Channel: niyaziapiChannel
Config: /home/niyazi/aqueduct3_pro/niyaziapi/config.yaml
Port: 8888
*** Application failed to start.
*** Uncaught error
Invalid argument(s): Invalid controller 'LoginController'. Controllers must not have setters and all fields must be marked as final, or it must implement 'Recyclable'.
**** Stacktrace


@NTMS2017
Copy link
Author

And this is my MacBook Pro settings. Its work perfectly

Niyazis-MacBook-Pro:niyaziapi niyazitoros$ aqueduct serve
-- Aqueduct CLI Version: 3.0.0-beta.1
-- Aqueduct project version: 3.0.0-beta.1
-- Preparing...
-- Starting application 'niyaziapi/niyaziapi'
Channel: niyaziapiChannel
Config: /Users/niyazitoros/Aqueduct3_Pro/niyaziapi/config.yaml
Port: 8888
[INFO] aqueduct: Server aqueduct/1 started.
[INFO] aqueduct: Server aqueduct/2 started.
[INFO] aqueduct: Server aqueduct/3 started.
[INFO] aqueduct: Server aqueduct/4 started.
[INFO] aqueduct: Server aqueduct/5 started.
[INFO] aqueduct: Server aqueduct/6 started.
[INFO] aqueduct: Server aqueduct/7 started.
[INFO] aqueduct: Server aqueduct/8 started.
^C-- Stopping application.
Reason: Process interrupted.
Niyazis-MacBook-Pro:niyaziapi niyazitoros$ dart --version
Dart VM version: 2.0.0-dev.67.0 (Tue Jul 3 18:17:07 2018 +0200) on "macos_x64"
Niyazis-MacBook-Pro:niyaziapi niyazitoros$

@itsjoeconway
Copy link
Contributor

itsjoeconway commented Jul 12, 2018

This isn't in the deployed doc site yet, so I'll quote it here:

It is important to understand why link takes a closure, instead of a controller object. Aqueduct is an object oriented framework. Objects have both state and behavior. An application will receive multiple requests that will be handled by the same type of controller. If a mutable controller object were reused to handle multiple requests, it could retain some of its state between requests. This would create problems that are difficult to debug.

Most controllers are immutable - in other words, all of their properties are final and they have no setters. This (mostly) ensures that the controller won't change behavior between requests. When a controller is immutable, the link closure is invoked once to create and link the controller object, and then the closure is discarded. The same controller object will be reused for every request.

Controllers can be mutable, with the caveat that they cannot be reused for multiple requests. For example, a ResourceController can have properties that are bound to the values of a request, and therefore these properties will change and a new instance must be created for each request.

A mutable Controller subclass must implement Recyclable<T>. The link closure will be invoked for each request, creating a new instance of the recyclable controller to handle the request. If a controller has an expensive initialization process, the results of that initialization can be calculated once and reused for each controller instance by implementing the methods from Recyclable<T>.

class MyControllerState {
  dynamic stuff;
}

class MyController extends Controller implements Recyclable<MyControllerState> {
  @override
  MyControllerState get recycledState => expensiveCalculation();

  @override
  void restore(MyControllerState state) {
    _restoredState = state;
  }

  MyControllerState _restoredState;

  @override
  FutureOr<RequestOrResponse> handle(Request request) async {
    /* use _restoredState */
    return new Response.ok(...);
  }
}

The recycledState getter is called once, when the controller is first linked. Each new instance of a recyclable controller has its restore method invoked prior to handling the request, and the data returned by recycledState is passed as an argument. As an example, ResourceController 'compiles' its operation methods. The compiled product is stored as recycled state so that future instances can bind request data more efficiently.

@NTMS2017
Copy link
Author

@joeconwaystk thanks. This is much clear now. I thought every time I create a new controller also after return cleans or remove from GC. "ControllerState get recycledState => expensiveCalculation();" this makes my life easier. Kind Regards

@NTMS2017
Copy link
Author

NTMS2017 commented Jul 28, 2018

@joeconwaystk can you give show me where I can get more detil about implements Recyclable. I after I appgrding to 2.0.0.69-4 I am getting recycle error again. Can founf expensiveCalculation(); and I am not sure how to us /* use _restoredState */ in Future<>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants