             @_emitter.addListener action, handler
 
             if identity = @addListener.identity
-                    
+
                 if !(@_eventHandlers ?= {})[identity.id]
                     @_eventHandlers[identity.id] = {}
 

                                do(check)=>
                                    checks.push (next)=>
                                        check.apply @, [identity, key, args, next]
                
                        
                        next true
                        
                ,

                    (next)=> # check for general remote restriction
                        
                        next (@permissions?[key] || @permissions) isnt false
                        
                ,
                
                    (next)=> # custom check function - must callback true to permit!
                        if typeof (check = @permissions) is 'function' || typeof (check = @permissions?[key]) is 'function' || check = (@permissions?[key]?.check || @permissions?.check)
                            
                            check identity, key, args, next                            
                            
                        else next true
                    
                ,

                    (next)=> # check for identity.id restriction
                        
                        if id = (@permissions?[key]?.identity || @permissions?.identity)
                            next identity.id is id
                        
                        else next true
                ,

                    (next)=> # check for token restriction
                        
                        if token = (@permissions?[key]?.token || @permissions?.token)
                            
                            identity.token (err, _token)=>
                                next token is _token
                        
                        else next true
                ,

                    (next)=> # check for login restriction
                        
                        if (@permissions?[key]?.login || @permissions?.login)
                            
                            identity.login (err, login)=>
                                next !!login
                        
                        else next true
                ,

                     (next)=> # check for user restriction and test identity.login
                        
                        if user = (@permissions?[key]?.user || @permissions?.user)
                            
                            identity.login (err, login)=>
                                next login is user
                        
                        else next true
                ,

                    (next)=> # check for roles restriction and test identity.hasRole
                        if roles = (@permissions?[key]?.roles || @permissions?.roles)
                            
                            identity.hasRole roles, (err, ok)=>
                                next ok
                                
                        else next true
                
                ]
                
                permit = (ok)=>
                    return fn(new floyd.error.Forbidden @ID+'.'+key) if !ok
                    
                    if check = checks.shift()
                        check permit
                    
                    else fn()
                
                # start recursion
                
                permit true

        ##

        ##
        _process: (obj, {each, done})->
            floyd.tools.objects.process obj, each: each, done: done


        ##
        ## nice logger id
        ##
        _createLogger: (id)->

            type = @type

            logger = new floyd.logger.Logger "#{id} - (#{type})"

            if (level = @data.find 'logger.level')

                logger.level(logger.Level[level.toUpperCase()])

            return logger


        ##
        ## triggers a status change emits status event
        ##
        _changeStatus: (status)->

            if status
                @_status.push status

                @_emit 'before:'+status

                if @logger.isLoggable @logger.Level.STATUS
                    @logger.status 'status changed to', status

                @_emit status

                @_emit 'after:'+status



        ## EventEmitter

        ##
        ## delegates
        ##
        on: ()->
            @addListener.identity = @on.identity
            @addListener.apply @, arguments

        off: ()->
            @removeListener.identity = @off.identity
            @removeListener.apply @, arguments

        addListener: (action, handler)->
            if !handler
                return console.log 'no handler', action
