Example usage for org.springframework.aop.framework AopContext currentProxy

List of usage examples for org.springframework.aop.framework AopContext currentProxy

Introduction

In this page you can find the example usage for org.springframework.aop.framework AopContext currentProxy.

Prototype

ThreadLocal currentProxy

To view the source code for org.springframework.aop.framework AopContext currentProxy.

Click Source Link

Document

ThreadLocal holder for AOP proxy associated with this thread.

Usage

From source file:org.ngrinder.common.util.AopUtils.java

/**
 * Get current proxy./*from  w ww  . j  ava2 s .  c o m*/
 *
 * @param current current proxy wrapped component
 * @param <T>     the type of proxy
 * @return currently used proxy. current if no proxy is used.
 */
public static <T> T proxy(T current) {
    try {
        return cast(AopContext.currentProxy());
    } catch (IllegalStateException e) {
        return current;
    }
}

From source file:com.organization.automation.project.spice.mix.junit.test.ProxyAbstractTestCase.java

@Override
public void run() throws TCException {
    try {//from   ww  w  .ja  v  a  2  s . c o  m
        ((ITestCase) AopContext.currentProxy()).preconditions();
        ((ITestCase) AopContext.currentProxy()).init();
        ((ITestCase) AopContext.currentProxy()).setup();
        ((ITestCase) AopContext.currentProxy()).steps();
        ((ITestCase) AopContext.currentProxy()).poststeps();
        ((ITestCase) AopContext.currentProxy()).check();
    } catch (Exception e) {
        LOGGER.error("[TEST]       [EXCEPTION]");
        LOGGER.error("[TEST]        " + e.toString());
        throw new TCException(e);
    } catch (Error e) {
        LOGGER.error("[TEST]       [ERROR]");
        LOGGER.error("[TEST]        " + e.toString());
        throw new TCError(e);
    } finally {
        teardownSafely();
    }
}

From source file:com.organization.automation.project.spice.mix.junit.test.AbstractTestCase.java

@LogRun
@Override//  w  ww . j a  va2 s .  co  m
public void run() throws TCException {
    try {
        ((ITestCase) AopContext.currentProxy()).preconditions();
        ((ITestCase) AopContext.currentProxy()).init();
        ((ITestCase) AopContext.currentProxy()).setup();
        ((ITestCase) AopContext.currentProxy()).steps();
        ((ITestCase) AopContext.currentProxy()).poststeps();
        ((ITestCase) AopContext.currentProxy()).check();
    } catch (Exception e) {
        LOGGER.error("[TEST]       [EXCEPTION]");
        LOGGER.error("[TEST]        " + e.toString());
        throw new TCException(e);
    } catch (Error e) {
        LOGGER.error("[TEST]       [ERROR]");
        LOGGER.error("[TEST]        " + e.toString());
        throw new TCError(e);
    } finally {
        teardownSafely();
    }
}

From source file:com.organization.automation.project.spice.mix.junit.test.AbstractTestCase.java

public void teardownSafely() {
    try {/*from  w ww.  j av  a  2 s.co m*/
        ((ITestCase) AopContext.currentProxy()).teardown();
    } catch (Exception e) {
        LOGGER.error(e.toString());
    } catch (Error e) {
        LOGGER.error(e.toString());
    }
}

From source file:com.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java

@Around("modelChange()")
public void updateProperty(ProceedingJoinPoint pjp) throws Throwable {
    if (encendido && activo) {
        Object target = pjp.getTarget();
        Object proxyTarget = AopContext.currentProxy();
        if (!(target instanceof Metadata)) {
            String methodName = pjp.getSignature().getName();
            String propertyName = StringUtils.substringAfter(methodName, "set");
            String primeraLetra = propertyName.charAt(0) + "";
            propertyName = primeraLetra.toLowerCase() + StringUtils.substringAfter(propertyName, primeraLetra);
            processChange(proxyTarget, propertyName, pjp.getArgs()[0]);
        }//from w w w  . j ava  2s. c om
    }
    pjp.proceed();
}

From source file:org.LexGrid.LexBIG.caCore.client.proxy.LexEVSProxyHelperImpl.java

@Override
protected Object convertObjectToProxy(ApplicationService as, Object obj) {
    if (null == obj)
        return null;

    //Check to see if the returned object is an EVSRemoteExecutionResults.
    //If so, unwrap it and update the proxy target
    if (obj instanceof RemoteExecutionResults) {
        RemoteExecutionResults results = (RemoteExecutionResults) obj;

        //if the returned results are null, return null
        if (results.getReturnValue() == null)
            return null;

        //Get the current proxy target and update it with the retuned value
        //from the server
        Advised advised = (Advised) AopContext.currentProxy();
        advised.setTargetSource(new SingletonTargetSource(results.getObj()));

        obj = results.getReturnValue();//from w w w .j a  v  a  2  s.  c  o m
    }

    if (obj instanceof RemoteShell) {
        Class<?>[] targetInterfaces = ((RemoteShell) obj).getTargetInterfaces();
        Class<?> targetClass = ((RemoteShell) obj).getTargetClass();
        ProxyFactory pf = new ProxyFactory(targetInterfaces);
        pf.addAdvice(new LexEVSBeanProxy(as, this));
        pf.setProxyTargetClass(true);
        pf.setTargetClass(targetClass);
        pf.setTarget(obj);

        return pf.getProxy();
    }

    if (obj instanceof Integer || obj instanceof Float || obj instanceof Double || obj instanceof Character
            || obj instanceof Long || obj instanceof Boolean || obj instanceof String || obj instanceof Date
            || obj instanceof LexEVSBeanProxy || obj instanceof BeanProxy)
        return obj;

    if (!LexEVSCaCoreUtils.isLexBigClass(obj.getClass())) {
        return obj;
    }

    // Don't proxy client-safe LexBig objects
    if (isClientSafe(obj.getClass())) {
        return obj;
    } else {
        return LexEVSCaCoreUtils.createProxy(obj, as, this);
    }
}

From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java

@Async
public void initOneMillionData(final User user) {

    ExcelDataService proxy = (ExcelDataService) AopContext.currentProxy();

    long beginTime = System.currentTimeMillis();

    getExcelDataRepository().truncate();

    final int ONE_MILLION = 1000000; //100w
    for (int i = batchSize; i <= ONE_MILLION; i += batchSize) {
        //?AopContext.currentProxy() task:annotation-drivenproxy
        proxy.doBatchSave(i - batchSize);
    }/*from   w w w.  j  a va  2 s .  c  om*/

    long endTime = System.currentTimeMillis();

    Map<String, Object> context = Maps.newHashMap();
    context.put("seconds", (endTime - beginTime) / 1000);
    notificationApi.notify(user.getId(), "excelInitDataSuccess", context);

}

From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java

/**
 * csv?//from  ww  w. j  a va 2  s .  c o  m
 * @param user
 * @param is
 */
@Async
public void importCvs(final User user, final InputStream is) {

    ExcelDataService proxy = ((ExcelDataService) AopContext.currentProxy());
    BufferedInputStream bis = null;
    try {
        long beginTime = System.currentTimeMillis();

        bis = new BufferedInputStream(is);
        String encoding = FileCharset.getCharset(bis);

        LineIterator iterator = IOUtils.lineIterator(bis, encoding);

        String separator = ",";
        int totalSize = 0; //?

        final List<ExcelData> dataList = Lists.newArrayList();

        if (iterator.hasNext()) {
            iterator.nextLine();//
        }

        while (iterator.hasNext()) {

            totalSize++;

            String line = iterator.nextLine();
            String[] dataArray = StringUtils.split(line, separator);

            ExcelData data = new ExcelData();
            data.setId(Long.valueOf(dataArray[0]));
            data.setContent(dataArray[1]);
            dataList.add(data);

            if (totalSize % batchSize == 0) {
                try {
                    proxy.doBatchSave(dataList);
                } catch (Exception e) {
                    Long fromId = dataList.get(0).getId();
                    Long endId = dataList.get(dataList.size() - 1).getId();
                    log.error("from " + fromId + " to " + endId + ", error", e);
                }
                dataList.clear();
            }
        }

        if (dataList.size() > 0) {
            proxy.doBatchSave(dataList);
        }

        long endTime = System.currentTimeMillis();

        Map<String, Object> context = Maps.newHashMap();
        context.put("seconds", (endTime - beginTime) / 1000);
        notificationApi.notify(user.getId(), "excelImportSuccess", context);
    } catch (Exception e) {
        log.error("excel import error", e);
        Map<String, Object> context = Maps.newHashMap();
        context.put("error", e.getMessage());
        notificationApi.notify(user.getId(), "excelImportError", context);
    } finally {
        IOUtils.closeQuietly(bis);
    }
}

From source file:com.luna.common.plugin.serivce.BaseMovableService.java

public void reweight() {
    int batchSize = 100;
    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    Pageable pageable = new PageRequest(0, batchSize, sort);
    Page<M> page = findAll(pageable);
    do {//from w w  w  .j  av  a 2 s .  c  om
        //doReweight?requiresNew
        ((BaseMovableService) AopContext.currentProxy()).doReweight(page);

        RepositoryHelper.clear();

        if (page.isLastPage()) {
            break;
        }

        pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort);

        page = findAll(pageable);

    } while (true);
}

From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java

public void reweight() {
    int batchSize = 100;
    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    Pageable pageable = new PageRequest(0, batchSize, sort);
    Page<M> page = findAll(pageable);
    do {/* ww  w  . j  av  a  2s . co  m*/
        //doReweight?requiresNew
        ((BaseMovableService) AopContext.currentProxy()).doReweight(page);

        RepositoryHelper.clear();

        if (page.isLast()) {
            break;
        }

        pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort);

        page = findAll(pageable);

    } while (true);
}