users@grizzly.java.net

Re: Am I crazy? Yes... (I think I know more, so will re-ask)

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 15 Feb 2010 11:47:18 +0100

Hi Paul,

do you have an idea, what could be wrong?

WBR,
Alexey.

On Feb 13, 2010, at 3:57 , Paul.M wrote:

>
> I was able to add this, as another thread. I finally have the right
> combination of follow,finish,last, and start. It seems to work with
> dojo's
> cometd, but not the cometd.org project :/
>
> Hehe, now messaging to figure out
>
> new Thread(new Runnable() {
>
> public void run() {
> try {
> Thread.sleep(10 * 1000);
> } catch (InterruptedException ex) {
>
> Logger.getLogger(CometServer.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> while (true) {
> try {
> Thread.sleep(10 * 1000);
> System.out.println("Tick");
> CometEngine engine =
> CometEngine.getEngine();
> engine.register("/chat/demo");
> CometContext cometContext =
> engine.getCometContext("/chat/demo");
> Map map = new HashMap();
> map.put("chat", "Howdy");
> map.put("user", "server");
> Data data = new Data();
>
> data.setMapData(map);
> DeliverResponse deliverResponse = new
> DeliverResponse();
> deliverResponse.setChannel("/chat/demo");
> deliverResponse.setData(data);
> deliverResponse.setId(Integer.toString(id+
> +));
> deliverResponse.setFollow(true);
> deliverResponse.setFinished(true);
> deliverResponse.setLast(true);
>
> for (CometHandler handler :
> ((Set<CometHandler>)
> cometContext.getCometHandlers())) {
> try {
> System.out.println("" +
> ((DataHandler)
> handler).getClientId() + " -- " + data.toJSON());
>
> cometContext.notify(deliverResponse,
> handler);
> } catch (IOException ex) {
>
> Logger.getLogger(CometServer.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> }
> } catch (InterruptedException ex) {
>
> Logger.getLogger(CometServer.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> }
> }
> }).start();
>
>
> Oleksiy Stashok wrote:
>>
>> Hi Paul,
>>
>>> So This bit... Can I use this in a separate thread?
>> Yes.
>>> Would it be thread safe?
>> Should be :)
>>
>>> Would I have to bend the cometContext into a Publish Context?
>> CometContext is a static resource, so no need to save it somewhere.
>> You can always get it by CometEngine.getContext(channel);
>>
>>> Or do I use getCometHandlers and notify(attachment, CometHandler)
>>> to send the
>>> message?
>>>
>>> Or am I wrong, and that there is a different way I should be sending
>>> messages in? I want to keep async for this....
>> For now cometContext.notify(...) is the right way to send message
>> to a
>> client. You can call it async.
>>
>> WBR,
>> Alexey.
>>
>>>
>>> I keep reading the "documentation" hopeing a light goes off.
>>>
>>> final String channel = context.getChannel();
>>> final Set<DataHandler> handlers =
>>> context.lookupClientHandlers(channel);
>>>
>>> final CometContext cometContext =
>>> CometEngine.getEngine().getCometContext(channel);
>>>
>>> final DataHandler sender =
>>> context.getSenderClient();
>>>
>>> /// Send message to all clients except the sender
>>> for (DataHandler dataHandler : handlers) {
>>> try {
>>> cometContext.notify(patternResponse,
>>> dataHandler);
>>> }
>>> } catch (IOException ex) {
>>>
>>> Logger.getLogger(CometServer.class.getName()).log(Level.SEVERE,
>>> null, ex);
>>> }
>>> }
>>> }
>>> });
>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Am-I-crazy--Yes...--%28I-think-I-know-more%2C-so-will-re-ask%29-tp27475268p27516722.html
>>> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Am-I-crazy--Yes...--%28I-think-I-know-more%2C-so-will-re-ask%29-tp27475268p27572021.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>