Package org.qi4j.library.circuitbreaker

Examples of org.qi4j.library.circuitbreaker.CircuitBreaker


    public static CircuitBreaker newDataSourceCircuitBreaker( int threshold, long timeout )
    {
        @SuppressWarnings( "unchecked" )
        Specification<Throwable> in = in( ConnectException.class );
        return new CircuitBreaker( threshold, timeout, not( rootCause( in ) ) );
    }
View Full Code Here


        @Override
        public void assemble( ModuleAssembly module )
            throws AssemblyException
        {
            // START SNIPPET: cb-assembly
            CircuitBreaker circuitBreaker = newDataSourceCircuitBreaker( 5 /* threshold */,
                                                                         1000 * 60 * 5 /* 5min timeout */ );
            new DataSourceAssembler().
                withDataSourceServiceIdentity( DS_SERVICE_ID ).
                identifiedBy( DS_ID ).
                visibleIn( Visibility.layer ).
View Full Code Here

                Thread.currentThread().setContextClassLoader( cl );
            }
        }

        // Check if circuitbreaker is used
        final CircuitBreaker circuitBreaker = importedServiceDescriptor.metaInfo( CircuitBreaker.class );
        if ( circuitBreaker != null ) {

            DataSource wrappedDataSource = DataSources.wrapWithCircuitBreaker( importedServiceDescriptor.identity(), pool, circuitBreaker );
            circuitBreakers.put( pool, circuitBreaker );
            return wrappedDataSource;
View Full Code Here

    @Override
    public final boolean isAvailable( DataSource instance )
    {
        if ( pools.containsValue( instance ) ) {
            CircuitBreaker circuitBreaker = circuitBreakers.get( instance );
            if ( circuitBreaker != null ) {
                return circuitBreaker.isOn();
            } else {
                return true;
            }
        } else {
            return false;
View Full Code Here

    @Override
    public Object invoke( Object proxy, Method method, Object[] args )
            throws Throwable
    {
        CircuitBreaker circuitBreaker = serviceCircuitBreaker.circuitBreaker();
        try
        {
            if( !circuitBreaker.isOn() )
            {
                throw circuitBreaker.lastThrowable();
            }

            Object result = next.invoke( proxy, method, args );
            circuitBreaker.success();
            return result;
           
        } catch( Throwable throwable )
        {
            circuitBreaker.throwable( throwable );
            throw throwable;
        }
    }
View Full Code Here

            // START SNIPPET: jmx
            public void assemble( ModuleAssembly module )
                    throws AssemblyException
            {
                // END SNIPPET: jmx
                CircuitBreaker cb = new CircuitBreaker( 3, 250, CircuitBreakers.in( IllegalArgumentException.class ) );

                module.importedServices( TestService.class ).setMetaInfo( new TestService( cb ) );

                // START SNIPPET: jmx
                // JMX Library
View Full Code Here

TOP

Related Classes of org.qi4j.library.circuitbreaker.CircuitBreaker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.