Class: Needle::Lifecycle::Threaded

### Home Classes Methods

### In Files

- lib/needle/lifecycle/threaded.rb

### Parent

Needle::Pipeline::Element

### Methods

- #call
- #reset!
- #service_cache

### Files

- README

### Class/Module Index

Quicksearch

- Needle
- Needle::Bug
- Needle::Container
- Needle::DefinitionContext
- Needle::IncludeExclude
- Needle::Interceptor
- Needle::Interceptor::DynamicInterceptor
- Needle::InterceptorChainBuilder
- Needle::InterceptorChainBuilder::InterceptedServiceProxy
- Needle::InterceptorChainBuilder::InterceptorChainElement
- Needle::InterceptorChainBuilder::ProxyObjectChainElement
- Needle::InterceptorConfigurationError
- Needle::Lifecycle
- Needle::Lifecycle::Deferred
- Needle::Lifecycle::Initialize
- Needle::Lifecycle::Multiton
- Needle::Lifecycle::Proxy
- Needle::Lifecycle::Singleton
- Needle::Lifecycle::Threaded
- Needle::LogFactory
- Needle::Logger
- Needle::LoggingInterceptor
- Needle::NeedleError
- Needle::Pipeline
- Needle::Pipeline::Collection
- Needle::Pipeline::Collection::BlockElement
- Needle::Pipeline::Element
- Needle::Pipeline::InterceptorElement
- Needle::QueryableMutex
- Needle::Registry
- Needle::ServiceNotFound
- Needle::ServicePoint
- Needle::Version

No matching classes.

# Needle::Lifecycle::Threaded

The instantiation pipeline element that enforces the singleton multiplicity, on a per-thread basis.

### Public Instance Methods

call( container, point ) click to toggle source

Returns the cached reference, if it has been previously cached for the current thread. Otherwise, invokes the next element in the pipeline and caches the result. The cached reference is returned.

    # File lib/needle/lifecycle/threaded.rb, line 36
    def call( container, point )
      cache = service_cache
      name = service_point.fullname

      unless cache.has_key?( name )
        service = succ.call( container, point )
        cache[ name ] = service
      end

      cache[ name ]
    end

reset!() click to toggle source

Resets the cached singleton instance, so that the next time it is requested it is re-constructed. Only the cache for the current thread and service point is reset.

    # File lib/needle/lifecycle/threaded.rb, line 51
    def reset!
      cache = service_cache
      cache.delete service_point.fullname
    end

service_cache() click to toggle source

Returns a Hash of threaded services that are cached by the current thread.

    # File lib/needle/lifecycle/threaded.rb, line 29
    def service_cache
      Thread.current[ :threaded_services ] ||= Hash.new
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.