Code example for ProxyFactory

Methods: getProxy, addAdvice, setInterfaces, setTargetSource

0
            } 
            return activeDataSource; 
        } 
 
        HotSwappableTargetSource targetSource = new HotSwappableTargetSource(activeDataSource); 
        ProxyFactory pf = new ProxyFactory(); 
        pf.setInterfaces(new Class[] { DataSource.class }); 
        pf.setTargetSource(targetSource); 
         
         
        if (isPositiveFailoverEnable()) { 
            DataSource targetDetectorDataSource = descriptor.getTargetDetectorDataSource(); 
            DataSource standbyDetectorDataSource = descriptor.getStandbyDetectorDataSource(); 
            if (targetDetectorDataSource == null || standbyDetectorDataSource == null) { 
                throw new IllegalArgumentException( 
                        "targetDetectorDataSource or standbyDetectorDataSource can't be null if positive failover is enabled."); 
            } 
            // 1. create active monitoring job for failover event 
            ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); 
            ExecutorService jobExecutor = Executors.newFixedThreadPool(1); 
            jobExecutorRegistry.add(jobExecutor); 
            FailoverMonitorJob job = new FailoverMonitorJob(jobExecutor); 
            //    1.1  inject dependencies 
            job.setHotSwapTargetSource(targetSource); 
            job.setMasterDataSource(activeDataSource); 
            job.setStandbyDataSource(standbyDataSource); 
            job.setMasterDetectorDataSource(targetDetectorDataSource); 
            job.setStandbyDetectorDataSource(standbyDetectorDataSource); 
            job.setCurrentDetectorDataSource(targetDetectorDataSource); 
            job.setDetectingRequestTimeout(getDetectingTimeoutThreshold()); 
            job.setDetectingSQL(getDetectingSql()); 
            job.setRecheckInterval(recheckInterval); 
            job.setRecheckTimes(recheckTimes); 
            //    1.2  start scheduling and keep reference for canceling and shutdown 
            ScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(job, initialDelay, 
                    monitorPeriod, TimeUnit.MILLISECONDS); 
            schedulerFutures.put(future, scheduler); 
        } 
 
        if (isPassiveFailoverEnable()) { 
            // 2. create data source proxy with passive event advice 
            PassiveEventHotSwappableAdvice advice = new PassiveEventHotSwappableAdvice(); 
            advice.setRetryInterval(recheckInterval); 
            advice.setRetryTimes(recheckTimes); 
            advice.setDetectingSql(detectingSql); 
            advice.setTargetSource(targetSource); 
            advice.setMainDataSource(activeDataSource); 
            advice.setStandbyDataSource(standbyDataSource); 
            pf.addAdvice(advice); 
        } 
 
        return (DataSource) pf.getProxy(); 
    } 
 
    public void afterPropertiesSet() throws Exception { 
        if (!isPassiveFailoverEnable() && !isPositiveFailoverEnable()) { 
            return; 
Connect your IDE to all the code out there  Get Codota for Java