FileDocCategorySizeDatePackage
CometdNotificationHandler.javaAPI DocGlassfish v2 API4540Fri May 04 22:36:56 BST 2007com.sun.grizzly.cometd

CometdNotificationHandler

public class CometdNotificationHandler extends com.sun.enterprise.web.connector.grizzly.comet.DefaultNotificationHandler
Customized NotificationHandler that isolate notification to subscribed channel.
author
Jeanfrancois Arcand

Fields Summary
Constructors Summary
Methods Summary
protected voidnotify0(com.sun.enterprise.web.connector.grizzly.comet.CometEvent cometEvent, java.util.Iterator iteratorHandlers)
Notify only client subscribed to the active channel.

        ArrayList<Throwable> exceptions = null;
        CometHandler handler = null;
        Object o = cometEvent.attachment();
        String activeChannel = "";
        String channel = "";
        
        if (o instanceof Data){
            activeChannel = ((Data)o).getChannel();
        } else if (o instanceof DataHandler){
            activeChannel = ((DataHandler)o).getChannel();
        }
        while(iteratorHandlers.hasNext()){
            try{
                handler = (CometHandler)iteratorHandlers.next();
                
                if (handler instanceof CometdHandler){
                    channel = ((CometdHandler)handler).getChannel();
                } else if (handler instanceof DataHandler){
                    channel = ((DataHandler)handler).getChannel();
                } 
                       
                if (channel != null 
                        && channel.equals(BayeuxCometHandler.BAYEUX_COMET_HANDLER) 
                        || channel.equalsIgnoreCase(activeChannel)){
                    notify0(cometEvent,handler);
                } else if (channel == null){    
                    CometEngine.logger().log(Level.WARNING,"Channel was null");
                }
            } catch (Throwable ex){
                if (exceptions == null){
                    exceptions = new ArrayList<Throwable>();
                }
                exceptions.add(ex);
            }
        }
        if (exceptions != null){
            StringBuffer errorMsg = new StringBuffer();
            for(Throwable t: exceptions){
                errorMsg.append(t.getMessage());
            }
            throw new IOException(errorMsg.toString());
        }