Commit Graph

33 Commits

Author SHA1 Message Date
Dave Syer
5aeba1ea96 Convert Consumer<Foo> to Function<Flux<Foo>,Mono<Void>>
This results in a better experience for users because the consumer
that they write is only applied to a Flux that is subscribed to
by the framework once. It gives better control over the flow of
foos, e.g. if some component wants to subscribe on a thread.
2018-03-26 10:06:13 +01:00
Dave Syer
a1b624b28a Inspect bean class if it is available
Avoids instantiating beans if not necessary, and allows user to
provide Function as a @SpringBootApplication (for instance), or
more generally as a source to the application context (as opposed
to being component scanned).
2018-03-21 11:09:57 +00:00
Dave Syer
773dddbe68 Ensure composite wrapper type reflects reality
When a Supplier<Flux<Foo>> is composed with a Function<Foo,Bar>
the resulting handler (supplier) should have Flux as its output
wrapper still (the most general output wrapper type in the chain).
2018-03-16 08:35:21 -04:00
Dave Syer
47f86671ca Allow pipe as well as comma in function composition 2018-03-16 08:05:29 -04:00
Dave Syer
5528659b4b Inspect bean definition more thoroughly for factory arguments
Fixes gh-153
2018-03-02 11:28:33 +00:00
Dave Syer
dc008cc24d Ensure a function is inspectable as itself and its wrapper
Since a function is wrapper in a FluxWrapper (and possibly also
an Isolated), the link is lost between the bean and the type
metadata without this change.
2018-03-01 09:10:14 +00:00
Dave Syer
33b33adb4b Change FunctionCatalog to key off Class<?>
Makes it possible to support other "function" types in the future.
The user is always taking a risk with the lookup that the object
returned has the generic type desired (but that hasn't changed
with this commit). FunctionCatalog is a lot simpler as a result
and also a lot more flexible.
2018-02-28 14:18:09 +00:00
Dave Syer
616e2825c6 Move FunctionCatalog into context module 2018-02-27 09:05:28 +00:00
Dave Syer
7bc6d7dfee Re-order type discovery and function wrapping
Otherwise the explicit types from the function registration are
not used.
2018-02-26 16:28:50 +00:00
Dave Syer
5203401e00 Use Void as input type for Supplier, etc. 2018-02-26 14:15:54 +00:00
Dave Syer
f9e4546070 Add convenience methods to FunctionType 2018-02-26 11:45:01 +00:00
Dave Syer
38f6caf4dc Add FunctionType abstraction and test it 2018-02-26 09:56:02 +00:00
Dave Syer
ccd3953163 Cache result of isMessage() computation before function is wrapped
Otherwise you get the wrong result when you go back and ask later
(but only if the bean is a singleton with no bean definition).
2018-02-14 16:25:12 +00:00
Dave Syer
c728cd4c01 Support for Function<Publisher<...>,...> 2018-02-14 14:09:28 +00:00
Dave Syer
1af0d451cf Migrate to servlet binder for web features 2018-01-03 15:06:33 +00:00
Artem Bilan
46fdca479b Properly resolve FactoryBean for function
Fixes: gh-118

When the `BeanDefinition` for `Function` is a `FactoryBean`
(e.g. `GatewayProxyFactoryBean` in Spring Integration) and that
`BeanDefinition` isn't registered as `@Bean` method (e.g.
Spring Integration Java DSL parser), the `ContextFunctionCatalogAutoConfiguration`
doesn't resolve the target `Function` type properly

* Get the target `Function` bean type via `BeanFactory.getType(String)`
* Make fallback to the `Object.class` instead of bean type since we are
expecting here a generic type anyway
2017-12-01 10:31:18 +00:00
Dave Syer
e824fbf6cb Isolate the context class loader if function appears to need it
When a function is created using an isolated class loader it might
want to use that class loader again for its invocations, and a lot
of tools (Spring etc.) use the context class loader for that kind
of thing if they don't have an explicit default value. So we
set the context class loader before, and unset it after, the
function invocation using a convenience wrapper.
2017-11-25 05:25:29 +09:00
Dave Syer
f3951cba66 Prefer explicit route to default 2017-11-24 13:21:08 +09:00
Dave Syer
1ee517ab01 Use unique function if there is only one and name not provided
If the user doesn't ask for a specific function, but there is only
one possible choice, we can just use that.
2017-11-24 12:41:10 +09:00
Dave Syer
8459fb4e30 Ensure a concrete type with parametrric subtype is detected
If user defines their own @Beans from conrete types that implement
Function<...> then their type signature is detectable from the
class.
2017-11-20 15:34:06 +00:00
Dave Syer
219d056801 Add FunctionRegistry interface (writable FunctionCatalog)
This makes dynamic function registration (after context starts) much
easier. Also frees us from having to employ BeanFactoryPostProcessor
and other tricks to get the functions registered on startup.
2017-11-13 14:13:59 +00:00
Dave Syer
41d1dfa6bc Add public registration method to bean post processor
Also simplifies logic of looking up message types
2017-11-13 09:27:36 +00:00
Dave Syer
d4b87c1fe7 Initial support for composable functions
There's a test for each of the supported types. No error handling
yet.

Fixes gh-122
2017-11-10 16:45:11 +00:00
Dave Syer
ad0ebd5cfc Add additional logic to function catalog to help with singletons
A registered singleton doesn't have a BeanDefinition, but it might have
a compiled type with enough generic information to pull out the
input and output types.
2017-11-10 12:11:55 +00:00
Oleg Zhurakousky
a973b678f1 FunctionUtils polishing
- attempted to make code more functional (eat our own dog food) and concise
- addressed PR comment
- additional cleanup/polishing of FunctionUtils and related classes
- Removed Function/Supplier/ConsumerProxy classes by extending type info on their super interface
- Renamed FunctionUtils to FunctionFactoryUtils
- Added javadoc to FunctionFactoryUtils to explain its design considerations as well as what it can and can not doi

Fixes gh-90
2017-08-22 14:07:42 +01:00
Oleg Zhurakousky
182317dbe9 Minor polishing of InMemoryFunctionCatalog
- Removed constructor in InMemoryFunctionCatalog that creates empty maps and no registrations since there is no way to register anything after catalog is created.
- Refactored registration logic a bit more functional/concise in the FunctionRegistration constructor of InMemoryFunctionCatalog
- Added additional assertions in tests

rebased and removed the assertion that was causing certain test failures
2017-07-13 16:07:53 +01:00
Dave Syer
c8646d64d8 Strangle old inspector methods
Fixes gh-81
2017-07-13 13:37:45 +01:00
Dave Syer
4b30721d02 Fix naming indirection so that input types are correctly located
Also applies to output types, wrapper types and identifying if
messages can be processed directly.

See gh-81 (the ambiguity is still there, but the indirection bug
is fixed).
2017-07-11 17:39:42 +01:00
Dave Syer
d826884d02 Ensure @Component scanned from jar on classpath can be inspected
And test it using a new POF sample.
2017-06-28 17:52:37 +01:00
Dave Syer
f94d672dc4 Add test and fix type inspection for scanned functions
Fixes gh-73
2017-06-28 11:00:07 +01:00
Dave Syer
0756dc3394 Add support for Message<Foo> in stream apps
The FunctionInspector needs to be able to distinguish between a
function of Flux<Foo> and a function of Flux<Message<Foo>>. Then
it can do the conversion a level below.

Only supports Message->Message or POJO->POJO (no mixtures), so there
is only one new method in FunctionInspector.

No support in the web endpoints yet. But it's probably not so hard
to add.
2017-06-15 12:32:46 +01:00
Dave Syer
9bf3601143 Fixed consumer sample to accept bare string 2017-05-26 12:51:56 +01:00
Dave Syer
99c7b995e0 Add FunctionFactoryMetadata interface for type discovery
The compiled functions implement that interface which means you can inspect
the signature of the method that created them and discover its
generic types.
2017-05-26 10:09:47 +01:00