Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue 125 - first cut to support Comet
- Loading branch information
Showing
8 changed files
with
168 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package zk | ||
|
||
import org.zkoss.zkgrails.* | ||
|
||
class MyComet extends GrailsComet { | ||
|
||
int i | ||
|
||
static trigger = [startDelay: 3000L, delay: 1000L] | ||
|
||
def execute = { desktop, page -> | ||
i++ | ||
lblTest.value = "time : ${i}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package zk | ||
|
||
import org.zkoss.zkgrails.GrailsComposer; | ||
|
||
class MyComposer extends GrailsComposer { | ||
|
||
def lblTest | ||
def myComet | ||
|
||
def afterCompose = { | ||
myComet.start() | ||
} | ||
|
||
def onClick_btnStop() { | ||
myComet.stop() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.zkoss.zkgrails; | ||
|
||
import org.codehaus.groovy.grails.commons.GrailsClassUtils; | ||
import org.codehaus.groovy.grails.commons.spring.DefaultBeanConfiguration; | ||
import org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.beans.factory.BeanFactoryAware; | ||
import org.zkoss.zk.ui.Executions; | ||
|
||
class GrailsComet { | ||
|
||
GrailsComposer grailsComposer | ||
Thread th | ||
Boolean stop = false | ||
|
||
public void start() { | ||
final desktop = grailsComposer.desktop | ||
final page = grailsComposer.page | ||
|
||
def trigger = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(this, "trigger") | ||
|
||
final Long startDelay | ||
final Long delay | ||
|
||
if(trigger instanceof Number) { | ||
startDelay = 0L | ||
delay = (Number)trigger | ||
} else if(trigger instanceof Map) { | ||
startDelay = trigger['startDelay'] | ||
delay = trigger['delay'] | ||
} | ||
if (desktop.isServerPushEnabled() == false) { | ||
desktop.enableServerPush(true) | ||
} | ||
final executeClosure = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(this, "execute") | ||
executeClosure.delegate = grailsComposer | ||
executeClosure.resolveStrategy = Closure.DELEGATE_FIRST | ||
|
||
th = Thread.start { | ||
Thread.sleep(startDelay) | ||
while(!stop) { | ||
Executions.activate(desktop) | ||
executeClosure.call(desktop, page) | ||
Executions.deactivate(desktop) | ||
Thread.sleep(delay) | ||
} | ||
} | ||
} | ||
|
||
public void stop() { | ||
stop = true | ||
final desktop = grailsComposer.desktop | ||
desktop.enableServerPush(false) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/java/org/zkoss/zkgrails/artefacts/DefaultGrailsCometClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test/integration/zk/ComposerComentInstatiationTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package zk; | ||
|
||
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication; | ||
import org.codehaus.groovy.grails.commons.GrailsApplication; | ||
|
||
import groovy.util.GroovyTestCase; | ||
|
||
class ComposerComentInstatiationTests extends GroovyTestCase { | ||
|
||
GrailsApplication grailsApplication | ||
|
||
void testWiring() { | ||
def appCtx = grailsApplication.getMainContext() | ||
def myComposer = appCtx.getBean("zk.myComposer") | ||
myComposer.injectComet() | ||
assert myComposer != null | ||
assert myComposer.myComet != null | ||
assert myComposer.myComet.grailsComposer != null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<zk xmlns="http://www.zkoss.org/2005/zul" | ||
xmlns:h="http://www.w3.org/1999/xhtml" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd" > | ||
|
||
<window id="wndMain" apply="zk.myComposer"> | ||
<button id="btnStop" label="Stop"/> | ||
<label id="lblTest">Ready</label> | ||
</window> | ||
|
||
</zk> |