FileDocCategorySizeDatePackage
DefaultNotificationHandler.javaAPI DocGlassfish v2 API7675Fri May 18 12:52:48 BST 2007com.sun.enterprise.web.connector.grizzly.comet

DefaultNotificationHandler

public class DefaultNotificationHandler extends Object implements NotificationHandler
Default Notificationhandler that uses the same a Grizzly Pipeline to execute the notification process.
author
Jeanfrancois Arcand

Fields Summary
protected com.sun.enterprise.web.connector.grizzly.Pipeline
pipeline
The Pipeline used to execute threaded notification.
protected boolean
blockingNotification
true if the caller of CometContext.notify should block when notifying other CometHandler.
Constructors Summary
Methods Summary
public booleanisBlockingNotification()
Return true if the invoker of notify() should block when notifying Comet Handlers.

        return blockingNotification;
    
public voidnotify(CometEvent cometEvent, java.util.Iterator iteratorHandlers)
Notify all CometHandler.

param
cometEvent the CometEvent used to notify CometHandler
param
iteratorHandlers An iterator over a list of CometHandler

        if (blockingNotification || pipeline == null){
            notify0(cometEvent,iteratorHandlers);
        } else {
            pipeline.addTask(new TaskBase(){
                public void doTask() throws IOException{
                    notify0(cometEvent,iteratorHandlers);
                }
            });
        }
    
public voidnotify(CometEvent cometEvent, CometHandler cometHandler)
Notify a single CometHandler.

param
cometEvent the CometEvent used to notify CometHandler
param
cometHandler a CometHandler

        if (blockingNotification || pipeline == null){
            notify0(cometEvent,cometHandler);
        } else {
            final ArrayList<Throwable> exceptions 
                    = new ArrayList<Throwable>();
            pipeline.addTask(new TaskBase(){
                public void doTask() throws IOException{
                    try{
                        notify0(cometEvent,cometHandler);
                    } catch (Throwable ex){
                        exceptions.add(ex);
                    }
                    if (exceptions.size() > 0){
                        StringBuffer errorMsg = new StringBuffer();
                        for(Throwable t: exceptions){
                            errorMsg.append(t.getMessage());
                        }
                        throw new IOException(errorMsg.toString());
                    }
                }
            });
        }
    
protected voidnotify0(CometEvent cometEvent, java.util.Iterator iteratorHandlers)

        ArrayList<Throwable> exceptions = null;
        while(iteratorHandlers.hasNext()){
            try{
                notify0(cometEvent,iteratorHandlers.next());
            } 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());
        }
    
protected voidnotify0(CometEvent cometEvent, CometHandler cometHandler)
Notify a CometHandler. CometEvent.INTERRUPT -> CometHandler.onInterrupt CometEvent.NOTIFY -> CometHandler.onEvent CometEvent.INITIALIZE -> CometHandler.onInitialize CometEvent.TERMINATE -> CometHandler.onTerminate CometEvent.READ -> CometHandler.onEvent CometEvent.WRITE -> CometHandler.onEvent

param
attachment An object shared amongst CometHandler.
param
cometHandler The CometHandler to invoke.

        switch (cometEvent.getType()) {
            case CometEvent.INTERRUPT:
                cometHandler.onInterrupt(cometEvent);
                break;
            case CometEvent.NOTIFY:
                cometHandler.onEvent(cometEvent);
                break;
            case CometEvent.READ:
                cometHandler.onEvent(cometEvent);
                break;      
            case CometEvent.WRITE:
                cometHandler.onEvent(cometEvent);
                break;                 
            case CometEvent.INITIALIZE:
                cometHandler.onInitialize(cometEvent);
                break;      
            case CometEvent.TERMINATE:
                cometHandler.onTerminate(cometEvent);
                break;                       
            default:
                throw new IllegalStateException();
        }
    
public voidsetBlockingNotification(boolean blockingNotification)
Set to true if the invoker of notify() should block when notifying Comet Handlers.

        this.blockingNotification = blockingNotification;
    
protected voidsetPipeline(com.sun.enterprise.web.connector.grizzly.Pipeline pipeline)
Set the Pipeline used for notifying the CometHandler.

    

                 
       
        this.pipeline = pipeline;