internal static ICircuitBreaker GetOrCreateInstance(string name, CommandProperties properties, CommandMetrics metrics, IClock clock)
        {
            Contract.Assert(!String.IsNullOrEmpty(name));
            Contract.Assert(properties != null);
            Contract.Assert(metrics != null);
            Contract.Assert(clock != null);

            return _circuitBreakers.GetOrAdd(name, n => new DefaultCircuitBreaker(properties, metrics, clock));
        }
        internal static CommandState PrepareInternal(Type commandType, IJellyfishContext context, string commandGroup, string commandName, CommandPropertiesBuilder propertiesBuilder=null, IClock clock = null, CommandMetrics metrics = null, ICircuitBreaker circuitBreaker = null)
        {
            var state = new CommandState();

            state.CommandName = commandName ?? commandType.FullName;
            state.CommandGroup = commandGroup ?? state.CommandName;

            clock = clock ?? Clock.GetInstance();
            var properties = propertiesBuilder?.Build( state.CommandName ) ?? new CommandProperties( state.CommandName );
            metrics = metrics ?? CommandMetricsFactory.GetInstance( state.CommandName, state.CommandGroup, properties, clock );
            circuitBreaker = circuitBreaker ?? ( properties.CircuitBreakerEnabled.Value ? CircuitBreakerFactory.GetOrCreateInstance( state.CommandName, properties, metrics, clock ) : new NoOpCircuitBreaker() );
            context.MetricsPublisher.CreateOrRetrievePublisherForCommand( state.CommandGroup, metrics, circuitBreaker );

            ServiceCommandOptions flags = ServiceCommandOptions.None;
            if(IsMethodImplemented( commandType, "GetFallback" ))
                flags |= ServiceCommandOptions.HasFallBack;
            if(IsMethodImplemented( commandType, "GetCacheKey" ))
                flags |= ServiceCommandOptions.HasCacheKey;
            state.Flags = flags;
            return state;
        }
 internal DefaultCircuitBreaker([NotNull]CommandProperties properties, [NotNull]CommandMetrics metrics, [NotNull]IClock clock)
 {
     _clock = clock;
     _properties = properties;
     _metrics = metrics;
 }