New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overload with Function0 predicate to ReceiveBuilder #15446

Closed
ktoso opened this Issue Jun 25, 2014 · 2 comments

Comments

Projects
None yet
5 participants
@ktoso
Member

ktoso commented Jun 25, 2014

I found this when migrating the samples to the PersistentView, in there we don't enter a branch based on the message, but on an external check (isPersistent).

What one has to write now:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, m -> isPersistent(), msg -> { /*...*/ }).
        build()
      );
    }

What would be nicer to write:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, isPersistent(), msg -> { /*...*/ }).
        build()
      );
    }
@mkubala

This comment has been minimized.

Show comment
Hide comment
@mkubala

mkubala Sep 18, 2014

Contributor

We would create FI.PredicateVoid functional interface and overload appropriate *Match.match(..) methods.

And then, with Java8's method references we could do something like:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, this::isPersistent, msg -> { /*...*/ }).
        build()
      );
    }

where this::methodName is an instance method reference.

If checking that currently processed message was persisted is a common use-case in PersistentView receive (I haven't used it yet, I'm just guessing), then we can improve its conciseness also under older Java versions.
We just need to introduce some japi-specialized subclass of PersistentView that will bring appropriate predicate factory method.
For example (names, scopes, packages are only exemplary, thus don't bother about them for now):

package akka.persistence.japi;

import akka.japi.pf.FI;

public abstract class PersistentView implements akka.persistence.PersistentView {

    protected FI.PredicateVoid isPersistentF() {
        return new FI.PredicateVoid() {

            @Override
            public boolean defined() {
                return isPersistent();
            }
        };
    }

}

This would make API more friendly, even under legacy Java 6:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, isPersistentF(), msg -> { /*...*/ }).
        build()
      );
    }

Another idea (less invasive) is to just create some common functions/predicate factories within japi package.

What do you think about that additional enhancements?
Is it worth to be implemented, or we should rather assume that most of Akka's japi users already migrated to JDK 1.8 or will do it sooner or later?

Contributor

mkubala commented Sep 18, 2014

We would create FI.PredicateVoid functional interface and overload appropriate *Match.match(..) methods.

And then, with Java8's method references we could do something like:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, this::isPersistent, msg -> { /*...*/ }).
        build()
      );
    }

where this::methodName is an instance method reference.

If checking that currently processed message was persisted is a common use-case in PersistentView receive (I haven't used it yet, I'm just guessing), then we can improve its conciseness also under older Java versions.
We just need to introduce some japi-specialized subclass of PersistentView that will bring appropriate predicate factory method.
For example (names, scopes, packages are only exemplary, thus don't bother about them for now):

package akka.persistence.japi;

import akka.japi.pf.FI;

public abstract class PersistentView implements akka.persistence.PersistentView {

    protected FI.PredicateVoid isPersistentF() {
        return new FI.PredicateVoid() {

            @Override
            public boolean defined() {
                return isPersistent();
            }
        };
    }

}

This would make API more friendly, even under legacy Java 6:

public ExampleView() {
      receive(ReceiveBuilder.
        match(Object.class, isPersistentF(), msg -> { /*...*/ }).
        build()
      );
    }

Another idea (less invasive) is to just create some common functions/predicate factories within japi package.

What do you think about that additional enhancements?
Is it worth to be implemented, or we should rather assume that most of Akka's japi users already migrated to JDK 1.8 or will do it sooner or later?

@rkuhn rkuhn removed the 1 - triaged label Mar 9, 2016

@patriknw patriknw added this to the 2.4.x milestone Mar 18, 2016

@hepin1989

This comment has been minimized.

Show comment
Hide comment
@hepin1989

hepin1989 Jan 2, 2018

Contributor

This could be closed I think.

But we could add an external predicated too.

Contributor

hepin1989 commented Jan 2, 2018

This could be closed I think.

But we could add an external predicated too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment