diff options
author | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-24 14:28:46 +0000 |
---|---|---|
committer | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2011-05-24 14:28:46 +0000 |
commit | 2f83f5e8e091074cbd4e3d0d7cc15af22411314c (patch) | |
tree | 478a38c939ac9bfa46cb03ca3c8ea7d87ffe5562 /sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java | |
parent | e03b437442335d33ad52d31a750701933fb021d0 (diff) |
Update sample to reflect latest upgrades in the comet module.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1127081 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java index 4798a3457e..2c064a3ae6 100644 --- a/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java +++ b/sca-java-2.x/contrib/samples/learning-more/binding-comet/weather-webapp/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java @@ -20,8 +20,11 @@ package org.apache.tuscany.sca.sample.comet; import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; import org.apache.tuscany.sca.binding.comet.runtime.callback.CometCallback; +import org.apache.tuscany.sca.binding.comet.runtime.callback.Status; import org.apache.tuscany.sca.sample.comet.model.Location; import org.apache.tuscany.sca.sample.comet.model.Response; import org.oasisopen.sca.annotation.Callback; @@ -31,22 +34,23 @@ import org.oasisopen.sca.annotation.Service; public class PrecipitationServiceImpl implements PrecipitationService { @Callback - protected CometCallback callback; + protected CometCallback client; @Override public void getPrecipitation(final Location location) { - while (callback.isClientConnected()) { - Response response = new Response(); - response.setDate(new Date()); - response.setData(Helper.randomInt(100) + "%"); - - callback.sendResponse(response); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); + new Timer().scheduleAtFixedRate(new TimerTask() { + + @Override + public void run() { + Response response = new Response(); + response.setDate(new Date()); + response.setData(Helper.randomInt(100) + "%"); + Status status = client.sendMessage(response); + if (status == Status.CLIENT_DISCONNECTED) { + System.out.println("Client disconnected from PrecipitationService."); + this.cancel(); + } } - } + }, 0L, 1000L); } - } |