Hi Paul,
please update svn Grizzly workspace, specifically cometd module.
I've introduced additional interface PublishInterceptor, which lets
customize the default "forward to all" logic of Cometd "publish"
message.
Bellow is the simple sample, which sends published message to everyone
except the sender.
I'm trying to not touch existing API and code, so PublishInterceptor
API looks a bit low level. Pls. let us know, if you have more specific
requirements or questions.
Thanks.
WBR,
Alexey.
public static void main(String args[]) {
try {
GrizzlyWebServer ws = new GrizzlyWebServer(8080, "");
ws.addAsyncFilter(new CometAsyncFilter());
CometdAdapter cometdAdapter = new CometdAdapter(new
PublishInterceptor() {
public void onPublish(PublishContext context,
DeliverResponse patternResponse) {
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) {
if (dataHandler != sender) {
try {
System.out.println("Sending to
client: " + dataHandler.getClientId());
cometContext.notify(patternResponse,
dataHandler);
} catch (IOException ex) {
Logger.getLogger(CometdTest.class.getName()).log(Level.SEVERE, null,
ex);
}
}
}
}
});
cometdAdapter.setHandleStaticResources(true);
cometdAdapter.addRootFolder("/home/my/cometd-app");
ws.addGrizzlyAdapter(cometdAdapter);
ws.start();
} catch (IOException ex) {
}
}
On Feb 8, 2010, at 18:21 , Paul.M wrote:
>
> That would be cool.
>
> I've been trying to do it with glassfish last night, but didn't
> succeed in
> getting it to work at all :( How am I supposed to incorporate
> glassfish/modules into my work? Do I just reference the jar file,
> are they
> somehow supposed to be pulled in with the main glassfish jar/war?
> Is it a
> config somewhere? So confusing.. But I'm determined :)
>
>
> Oleksiy Stashok wrote:
>>
>> Hi Paul,
>>
>> I'll check this today and let you know.
>>
>> WBR,
>> Alexey.
>>
>> On Feb 6, 2010, at 0:10 , Paul.M wrote:
>>
>>>
>>> My Goal:
>>>
>>> 1. I want to write a stripped down program. Am avoiding the default
>>> jar and
>>> config xml files.
>>> 2. I want a server that handles two cases.
>>> 2a. It should act as a repeater on most channels. So that it can
>>> act like a
>>> chat. (This could be the default case for 2b when it's not
>>> interested)
>>> 2b. I want it to be able to listen on channels also. When it
>>> receives
>>> something it is interested in
>>> 2b1. It should interpret the JSON and act on the message.
>>> 2b2. It should send a new message on a different channel (with
>>> browsers
>>> listening).
>>>
>>> It's driving me nuts because I'm not 100% on terminalolgy.
>>>
>>> * I can get 2a working using CometdAdapter, but I can't figure out
>>> how to
>>> make that do 2b.
>>> *All the examples I see tell me to set up a Servlet and add the
>>> CometAdapter
>>> to that using CometEngine and CometContext. But I can't make
>>> that do
>>> either 2a or 2b. I tried the example
>>>
>>> Side note, I couldn't get grizzly-cometd-client to work either.
>>>
>>> So before I go off crying and beat my head against jetty for a
>>> while... Any
>>> help please?
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Am-I-crazy--Yes...--%28I-think-I-know-more%2C-so-will-re-ask%29-tp27475268p27475268.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-tp27475268p27503216.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
>