grails / grails-async Goto Github PK
View Code? Open in Web Editor NEWRepository for Grails async plugins
License: Apache License 2.0
Repository for Grails async plugins
License: Apache License 2.0
The monolithic grails project has been broken up into several smaller projects. Visit http://github.com/grails.
Run ./gradlew iT
in the example repository. Test will fail.
Application is annotated as @ComponentScan
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
import org.springframework.context.annotation.ComponentScan
import groovy.transform.CompileStatic
@CompileStatic
@ComponentScan
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
Class to capture the insertion and deletion:
import org.grails.datastore.mapping.engine.event.PreInsertEvent
import org.grails.datastore.mapping.engine.event.PreUpdateEvent
import grails.events.annotation.gorm.Listener
import groovy.transform.CompileStatic
import org.springframework.stereotype.Component
@Component
@CompileStatic
class UserPasswordEncoderListener {
@Listener
void beforeInsert(PreInsertEvent event) {
if ( event.entityObject instanceof User ) {
User u = (event.entityObject as User)
event.getEntityAccess().setProperty('password', insertEncodePassword(u.password))
}
}
@Listener
void beforeUpdate(PreUpdateEvent event) {
if ( event.entityObject instanceof User) {
User u = (event.entityObject as User)
if ( u.isDirty('password') ) {
event.getEntityAccess().setProperty('password', updateEncodePassword(u.password))
}
}
}
private String insertEncodePassword(String password) {
'xxxx'
}
private String updateEncodePassword(String password) {
'yyyy'
}
}
GORM Data service :
import grails.compiler.GrailsCompileStatic
import grails.gorm.services.Service
@GrailsCompileStatic
@Service(User)
abstract class UserService {
abstract User saveUser(String username, String password)
User updateUser(String username, String password) {
User u = User.findByUsername(username)
if(u != null) {
u.password = password
u.save()
}
u
}
}
Failing integration test:
package app
import grails.test.mixin.integration.Integration
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.Specification
@Integration
class UserServiceSpec extends Specification {
@Autowired UserService userService
void "test something"() {
when:
def u = userService.saveUser('sherlock', 'elementary')
then:
!u.hasErrors()
when:
sleep(500)
User.withTransaction {
u = User.findByUsername('sherlock')
}
then:
u
u.password == 'xxxx'
when:
u = userService.updateUser('sherlock', 'foobar')
then:
!u.hasErrors()
when:
sleep(500)
User.withTransaction {
u = User.findByUsername('sherlock')
}
then:
u
u.password == 'yyyy'
}
}
I expected GORM events to be captures by @Listener
annotated methods as described in the GORM events section of the async docs.
I looked into the Grails Aysnc example application.
@Listener
does not capture any event
Create new Grails Web Application
build.gradle
memory usage to a reasonably small value -Xmx512m
Insert an async task into the default controller
Promise promise = task {
try {
//Insert High Memory Usage Task
} catch (Exception e) {
log.error("Exceptions does not occur here", e)
} finally {
//Code here does not process
}
}
promise.onError { Exception e ->
log.error("OOME exceptions should at least occur here, but do not", e)
}
JSONSluper
to read a huge JSON
file and then try to write it back out to a file.Run grails run-app in your dev environment or go big and make a production environment and run the war file.
Execute the task in the controller
Wait for OOME, get coffee, watch movie, drink beer, concur that an OOME should occur
An OOME Exception should occur and the task should stop processing
The task runs indefinitely and my laptop gets hot enough to grill a hamburger
Thanks!
Create a fresh 3.3.0.M1 app
Add compile "org.grails.plugins:grails-spring-websocket:2.3.0"
App starts without exception
***************************
APPLICATION FAILED TO START
***************************
Description:
Field springTaskExecutor in org.grails.events.bus.spring.EventBusFactoryBean required a single bean, but 4 were found:
- clientInboundChannelExecutor: defined by method 'clientInboundChannelExecutor' in org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
- clientOutboundChannelExecutor: defined by method 'clientOutboundChannelExecutor' in org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
- brokerChannelExecutor: defined by method 'brokerChannelExecutor' in org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
- messageBrokerTaskScheduler: defined by method 'messageBrokerTaskScheduler' in org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
FAILURE: Build failed with an exception.
n/a
The value of the version attribute should be "4.0.0"
The value of the version attribute is "SNAPSHOT"
See:
2aece37
I needed to add sitemesh dependency here:
Or return a promiseList. We can then use the get or wait to block if we need the results of the event to proceed for certain business logic.
example use need
class CostService implements EventPublisher {
Long sumWithTax(List<Long> nums) {
Long result =nums.sum()
AtomicLong taxTotal = new AtomicLong(0)
sendAndReceive("calcTaxes", result){ Long tax ->
taxTotal.addAndGet(tax)
}.get() //assuming it returns a promisList
return result + taxTotal.get()
}
}
Would it be better to add a new method instead of the sendAndReceive? Maybe call it notifyPromise?
Spring's @EventListener
has a condition
attribute that can use an SpEL expression to match:
@EventListener(condition = "#creationEvent.awesome")
public void handleOrderCreatedEvent(CreationEvent<Order> creationEvent) {
}
It would be super handy if @Subscriber
could add the same support. This would allow for a better replacement to the pattern matching support that @Selector
used to provide with the legacy reactor bus.
Also, we have an enumeration for our eventTypes to make it easier to find and maintain. Having the SpEL expression would allow us to match based on the actual enum value instead of needing to duplicate the string for the eventId (since you can't say value = MyEnum.name()
in an annotation).
Shouldn't be this test the other way around?
Event.isAssignableFrom(parameterTypes[0])
instead of
At the moment I cannot derive form Event and use this subclass directly in subscriber method.
class MyEvent extends Event {
...
}
class Handler {
@Subcriber("myEvent")
void handleEvent(MyEvent event) {
}
}
This does not work.
A workaround is as follows:
class Handler {
@Subcriber("myEvent")
void handleEvent(Event event) {
MyEvent e = (MyEvent) event
...
}
}
Will try and issue a pr for this
With Grails 3.3.9 and it's compatible async plugin.
When a grails web Interceptor with a namespace selector is present, a WebPromise causes a server exception due to a null when calling getControllerName().
See the sample project at https://github.com/rrsdev/grails-async-interceptor
Example URLs would be:
If you delete or rename the secured.async.AuthorizationInterceptor class then all URLs work.
Add a buildNotificationCallableSync and a subscribeSync to make it possible to add Synchronous subscriptions listeners without the need for a Gorm AbstractPersitentEvent. This would be especially useful in easily enabling subscribers to participate in Transactions.
I left an empty implementation of addErrorHandler
here:
The SPI descriptor is incorrect, and thus, no matter what is in the classpath, you end up seeing:
No event bus implementations found on classpath, using synchronous implementation
A PR is coming to fix this issue.
./gradlew pubsub-demo:compileGroovy
> BUG! exception in phase 'canonicalization' in source unit '/Users/sdelamo/Developer/grails/grails-async/examples/pubsub-demo/grails-app/controllers/pubsub/demo/ApplicationController.groovy' java.lang.NoClassDefFoundError: org/grails/encoder/CodecFactory
Update the credentials in .travis.yml
.
The build is failing while trying to upload the snapshot artifacts to artifactory:
Could not PUT 'https://repo.grails.org/grails/libs-snapshots-local/org/grails/grails-async/4.0.0.BUILD-SNAPSHOT/grails-async-4.0.0.BUILD-20181128.185900-1.jar'. Received status code 401 from server: Unauthorized
And while trying to publish the documentation:
remote: Invalid username or password.
fatal: Authentication failed for 'https://[secure]@github.com/grails/grails-async.git/'
see: 8f7b0e4
The war file deploys successfully without error
The war file does not deploy. The following error is logged:
[2018-05-14T15:00:02.054-0500] [glassfish 4.1] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=45 _ThreadName=admin-listener(4)] [timeMillis: 1526328002054] [levelValue: 1000] [[
Exception while deploying the app [sec-access-issue-0.1] : The lifecycle method [close] must not throw a checked exception. Related annotation information: annotation [@javax.annotation.PreDestroy()] on annotated element [public void org.grails.async.factory.future.CachedThreadPoolPromiseFactory.close() throws java.io.IOException] of type [METHOD]
The lifecycle method [close] must not throw a checked exception. Related annotation information: annotation [@javax.annotation.PreDestroy()] on annotated element [public void org.grails.async.factory.future.CachedThreadPoolPromiseFactory.close() throws java.io.IOException] of type [METHOD]
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:373)
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:381)
at org.glassfish.apf.impl.AnnotationProcessorImpl.processAnnotations(AnnotationProcessorImpl.java:289)
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:217)
at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:134)
Methods annotated with @PreDestroy should not throw a checked exception.
Taking into account that this is a javax.* annotations and checking the documentation https://docs.oracle.com/javaee/7/api/javax/annotation/PreDestroy.html we can see that methods in the Grails source code not fully following the signature according to the Javadoc, thus we may want to adjust the signatures of the the methods that use @PreDestroy
annotation by removing the checked exceptions from them.
see:
a054a17
My issue is documentation related.
There are no links to earlier versions
All links from the grails core doc (docs.grails.org) to the async doc (async.grails.org)
either use the '.../latest/...' path e.g.:
https://async.grails.org/latest/guide/index.html
... or use the root URI https://async.grails.org/ which redirects to the 'latest'
The current latest version is 4.0.2
Assuming that the version number matches the core grails version, where is the doc for a 3.3.x version of grails/async?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
org.springframework:spring-web
, org.springframework:spring-tx
, org.springframework:spring-context
, org.springframework:spring-core
, org.springframework:spring-beans
)org.grails:grails-web-mvc
, org.grails:grails-web-common
, org.grails:grails-plugin-controllers
, org.grails:grails-core
, org.grails:grails-bootstrap
, org.grails:grails-docs
)These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/gradle.yml
actions/checkout v4
gradle/wrapper-validation-action v2
actions/setup-java v4
gradle/actions v3
actions/checkout v4
gradle/wrapper-validation-action v2
actions/setup-java v4
gradle/actions v3
gradle/actions v3
.github/workflows/groovy-joint-workflow.yml
actions/setup-java v4
actions/cache v4
actions/checkout v4
gradle/actions v3
actions/checkout v4
actions/setup-java v4
actions/cache v4
gradle/actions v3
.github/workflows/release-notes.yml
actions/checkout v3
release-drafter/release-drafter v5
ncipollo/release-action v1
.github/workflows/release.yml
actions/checkout v4
gradle/wrapper-validation-action v2
actions/setup-java v4
gradle/actions v3
gradle/actions v3
gradle.properties
settings.gradle
com.gradle.enterprise 3.16.2
com.gradle.common-custom-user-data-gradle-plugin 1.13
build.gradle
buildSrc/settings.gradle
buildSrc/build.gradle
docs/build.gradle
gradle/api-docs-config.gradle
gradle/buildsrc.libs.versions.toml
org.grails:grails-gradle-plugin 6.1.2
org.grails.plugins:views-gradle 3.2.1
io.github.gradle-nexus:publish-plugin 1.3.0
io.github.groovylang.groovydoc:groovydoc-gradle-plugin 1.0.1
org.grails:grails-docs 6.1.2
gradle/grails-plugin-config.gradle
gradle/java-config.gradle
gradle/libs.versions.toml
net.bytebuddy:byte-buddy 1.14.12
org.grails:grails-bootstrap 6.1.2
org.grails:grails-core 6.1.2
org.grails:grails-plugin-controllers 6.1.2
org.grails:grails-datastore-core 8.1.2
org.grails:grails-datastore-gorm 8.1.2
org.grails:grails-datastore-gorm-test 8.1.2
org.grails:grails-web-common 6.1.2
org.grails:grails-web-mvc 6.1.2
org.grails:grails-web-sitemesh 6.2.1
org.codehaus.gpars:gpars 1.2.1
org.codehaus.groovy:groovy 3.0.21
javax.annotation:javax.annotation-api 1.3.2
org.objenesis:objenesis 3.3
io.reactivex:rxjava 1.3.8
io.reactivex.rxjava2:rxjava 2.2.21
opensymphony:sitemesh 2.4.4
org.slf4j:slf4j-api 1.7.36
org.slf4j:slf4j-nop 1.7.36
javax.servlet:javax.servlet-api 4.0.1
org.spockframework:spock-core 2.3-groovy-3.0
org.springframework:spring-beans 5.3.33
org.springframework:spring-core 5.3.33
org.springframework:spring-context 5.3.33
org.springframework:spring-tx 5.3.33
org.springframework:spring-web 5.3.33
gradle/publishing.gradle
grails-async-core/build.gradle
grails-async-gpars/build.gradle
grails-async-rxjava/build.gradle
grails-async-rxjava2/build.gradle
grails-events-compat/build.gradle
grails-events-core/build.gradle
grails-events-gpars/build.gradle
grails-events-rxjava/build.gradle
grails-events-rxjava2/build.gradle
grails-events-spring/build.gradle
grails-events-transform/build.gradle
grails-plugin-async/build.gradle
grails-plugin-events/build.gradle
gradle/wrapper/gradle-wrapper.properties
gradle 7.6.4
docs/src/main/docs/resources/styles/layout.html
clipboard.js 1.7.1
two seperate plugin can not notify events
i have two plugin
eg APlugin,BPlugin
then in APlugin notify event
i can not subscribe the event in BPlugin
I have time to take this task
afterCommit
callback of a TransactionSynchronizationAdapter
The event should be received by listeners
The event is not received by listeners
This is existing code in a grails 3.2 app migrated to 4.0.3, so firing events like this used to work.
It seems to be associated with the thread which the event is fired from, as wrapping the publish in a promise seems to make it work.
Spring boot had supported servlet 3.1 since version 1.2, but the document of grails async just says supporting servlet 3.0. I want to confirm whether grails async support servlet 3.1, if not, what's the plan? Thanks!
Apply Change similar to grails/grails-core#13387
There is currently no source jar available at http://repo.grails.org/grails/core/org/grails/grails-events/4.0.0/. I have not checked any of the other artifacts from this repo.
Thanks for reporting an issue for Grails Async, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.
NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.
I am trying to upgrade a grails 2.5.4 application to grails 3.3.2. Some of the codes used to work now couldn't work. Basically, the issue is that the async task in the controller is referencing request.params which is not available in the async thread.
I created a 2.5.4 project (demo254) and a 3.3.2 project (demo332) to demonstrate the issue. Both projects have the same controller and view code.
Please refer to the readme in https://github.com/ruiyang/grails-issue-demo.git to reproduce.
I am not sure about the expected behaviour. I just need to know if there is any way I could get this code working to avoid a lot of rewrites.
Exception:
URI /helloWorld
Class . java.lang.IllegalStateException
Message . null
Caused by: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
sendAndReceive
with a reply closuresendAndReceive
with a reply closureOnce the subscriber handles the event, trigger the reply closure.
The event is handled, but the reply closure is not called
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.