Example usage for org.aspectj.lang ProceedingJoinPoint getTarget

List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getTarget.

Prototype

Object getTarget();

Source Link

Document

Returns the target object.

Usage

From source file:com.jmmd.common.shared.aspect.CommonLogger.java

License:Open Source License

/**
 * .//from  w ww.jav a  2 s.  c o m
 * 
 * @param jionpoint
 * @return
 * @throws Throwable
 */
@Around("commonPointcut() &&  @annotation(aspectLogger)")
public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
    /*
     * .
     */
    long l1 = System.currentTimeMillis();
    /*
     * ??.
     */
    String desc = aspectLogger.value();
    /*
     * ???.  
     */
    String targetMethodName = jionpoint.getSignature().getName();
    /*
     * ???.
     */
    String targetClassName = jionpoint.getTarget().getClass().getName();
    /*
     * ?.
     */
    Object o = jionpoint.proceed();
    /*
     * ?.
     */
    long l2 = System.currentTimeMillis();
    /*
     * ?.
     */
    StringBuilder aspectMessage = new StringBuilder();

    aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
            .append(".").append(targetMethodName).append("),(").append((l2 - l1)).append("ms)")
            .append(",?()");

    /*
     * .
     */
    logger.info(aspectMessage.toString());

    return o;
}

From source file:com.jmmd.core.shared.aspect.CoreAspect.java

License:Open Source License

/**
 * .//from w  w  w .  ja va  2 s. co m
 * 
 * @param jionpoint
 * @return
 * @throws Throwable
 */
@Around("corePointcut() &&  @annotation(aspectLogger)")
public Object aroundAdvice(ProceedingJoinPoint jionpoint, AspectLogger aspectLogger) throws Throwable {
    /*
     * .
     */
    long l1 = System.currentTimeMillis();
    /*
     * ??.
     */
    String desc = aspectLogger.value();
    /*
     * ???.  
     */
    String targetMethodName = jionpoint.getSignature().getName();
    /*
     * ???.
     */
    String targetClassName = jionpoint.getTarget().getClass().getName();
    /*
     * ?.
     */
    Object o = jionpoint.proceed();
    /*
     * ?.
     */
    long l2 = System.currentTimeMillis();
    /*
     * ?.
     */
    StringBuilder aspectMessage = new StringBuilder();

    aspectMessage.append("[]:(").append(desc).append("),(").append(targetClassName)
            .append(".").append(targetMethodName).append("),(").append(l2 - l1).append("ms)")
            .append(",?()");

    /*
     * .
     */
    logger.info(aspectMessage.toString());

    return o;
}

From source file:com.liferay.portal.messaging.proxy.MessagingProxyAdvice.java

License:Open Source License

public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    Message message = new Message();

    ProxyRequest proxyRequest = createProxyRequest(proceedingJoinPoint);

    message.setPayload(proxyRequest);/*ww  w  . j  a  v  a2  s. c o  m*/

    Map<String, Object> messageValues = MessageValuesThreadLocal.getValues();

    if (!messageValues.isEmpty()) {
        for (String key : messageValues.keySet()) {
            message.put(key, messageValues.get(key));
        }
    }

    BaseProxyBean baseProxyBean = (BaseProxyBean) proceedingJoinPoint.getTarget();

    if (proxyRequest.isSynchronous() || ProxyModeThreadLocal.isForceSync()) {

        return doInvokeSynchronous(message, baseProxyBean);
    } else {
        doInvokeAsynchronous(message, baseProxyBean);

        return null;
    }
}

From source file:com.liferay.portal.messaging.proxy.MultiDestinationMessagingProxyAdvice.java

License:Open Source License

public Object invoke(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

    Message message = new Message();

    ProxyRequest proxyRequest = createProxyRequest(proceedingJoinPoint);

    message.setPayload(proxyRequest);/*  w  w  w.j a  v a2s .c  o  m*/

    Map<String, Object> messageValues = MessageValuesThreadLocal.getValues();

    if (!messageValues.isEmpty()) {
        for (String key : messageValues.keySet()) {
            message.put(key, messageValues.get(key));
        }
    }

    BaseMultiDestinationProxyBean baseMultiDestinationProxyBean = (BaseMultiDestinationProxyBean) proceedingJoinPoint
            .getTarget();

    String destinationName = baseMultiDestinationProxyBean.getDestinationName(proxyRequest);

    if (proxyRequest.isSynchronous() || ProxyModeThreadLocal.isForceSync()) {

        return doInvokeSynchronous(message, baseMultiDestinationProxyBean, destinationName);
    } else {
        doInvokeAsynchronous(message, baseMultiDestinationProxyBean, destinationName);

        return null;
    }
}

From source file:com.lushapp.core.aop.LogAspect.java

License:Apache License

/**
 * @param point /*from  w w  w. ja  v a 2  s  .co  m*/
 */

@Around("execution(* com.lushapp.modules.*.service..*Manager.*(..))")
public Object logAll(ProceedingJoinPoint point) throws Throwable {
    Object result = null;
    // ??
    String methodName = point.getSignature().getName();
    String className = point.getTarget().getClass().getSimpleName();
    String userName = null;
    Long start = 0L;
    Long end = 0L;
    String ip = null;
    // ?
    try {
        // 
        start = System.currentTimeMillis();
        result = point.proceed();
        end = System.currentTimeMillis();

        // ??
        SessionInfo sessionInfo = null;
        try {
            sessionInfo = SecurityUtils.getCurrentSessionInfo();
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        if (sessionInfo != null) {
            userName = sessionInfo.getLoginName();
            ip = sessionInfo.getIp();
        } else {
            userName = "";
            ip = "127.0.0.1";
            logger.warn("sessionInfo.");
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
        throw e;
    }
    String name = null;
    // ?
    if (className.indexOf("Resource") > -1) {
        name = "??";
    } else if (className.indexOf("Role") > -1) {
        name = "?";
    } else if (className.indexOf("User") > -1) {
        name = "?";
    } else if (className.indexOf("Organ") > -1) {
        name = "?";
    } else {
        name = className;
    }
    // ?
    String opertype = methodName;
    if (StringUtils.isNotBlank(opertype) && (opertype.indexOf("save") > -1 || opertype.indexOf("update") > -1
            || opertype.indexOf("delete") > -1 || opertype.indexOf("merge") > -1)) {
        Long time = end - start;
        Log log = new Log();
        log.setType(LogType.operate.getValue());
        log.setLoginName(userName);
        log.setModule(name);
        log.setAction(opertype);
        log.setOperTime(new Date(start));
        log.setActionTime(time.toString());
        log.setIp(ip);
        BrowserType browserType = BrowserUtils.getBrowserType(SpringMVCHolder.getRequest());
        log.setBrowserType(browserType == null ? null : browserType.toString());
        defaultEntityManager.save(log);
    }
    if (logger.isDebugEnabled()) {
        logger.debug(":{},?{},?{},{}ms.",
                new Object[] { userName, className, methodName, end - start });
    }
    return result;
}

From source file:com.mpobjects.rtcalltree.rec.AspectJRecorder.java

License:Apache License

/**
 * @param aJoinPoint//from  www.  j a v a 2s.  c  o m
 * @return
 */
protected MutableCalltreeEntry createEntry(ProceedingJoinPoint aJoinPoint) {
    final Signature signature = aJoinPoint.getSignature();
    String className = signature.getDeclaringTypeName();
    final String methodName = signature.getName();
    final Object target = aJoinPoint.getTarget();
    if (target != null) {
        if (!Proxy.isProxyClass(target.getClass())) {
            className = target.getClass().getName();
        }
    }
    CalltreeEntryImpl entry = new CalltreeEntryImpl(className, methodName);
    /* Spring AOP throws exceptions on getFileName() etc. instead of just returning null for SourceLocation */
    // if (aJoinPoint.getSourceLocation() != null) {
    // entry.setSourceFilename(aJoinPoint.getSourceLocation().getFileName());
    // entry.setSourceLine(aJoinPoint.getSourceLocation().getLine());
    // }
    if (argumentConverter != null && aJoinPoint.getArgs() != null) {
        entry.setParameterValues(argumentConverter.convertArguments(aJoinPoint.getArgs()));
    }
    if (signature instanceof CodeSignature) {
        entry.setParameterTypes(getTypeNames(((CodeSignature) signature).getParameterTypes()));
    }
    return entry;
}

From source file:com.netflix.bdp.s3mper.listing.ConsistentListingAspect.java

License:Apache License

/**
 * Updates the metastore when a FileSystem.create(...) method is called.
 * /*from ww  w .j ava 2  s.  c  om*/
 * @param pjp
 * @return
 * @throws Throwable 
 */
@Around("create() && !within(ConsistentListingAspect)")
public Object metastoreUpdate(final ProceedingJoinPoint pjp) throws Throwable {
    if (disabled) {
        return pjp.proceed();
    }

    Configuration conf = ((FileSystem) pjp.getTarget()).getConf();
    updateConfig(conf);

    Object result = pjp.proceed();

    Path path = null;

    if (result instanceof Boolean && !((Boolean) result)) {
        return result;
    }

    try {
        //Locate the path parameter in the arguments
        for (Object arg : pjp.getArgs()) {
            if (arg instanceof Path) {
                path = (Path) arg;
                break;
            }
        }

        metastore.add(path, trackDirectories && pjp.getSignature().getName().contains("mkdir"));
    } catch (TimeoutException t) {
        log.error("Timeout occurred adding path to metastore: " + path, t);

        alertDispatcher.timeout("metastoreUpdate", Collections.singletonList(path));

        if (failOnTimeout) {
            throw t;
        }
    } catch (Exception e) {
        log.error("Failed to add path to metastore: " + path, e);

        if (shouldFail(conf)) {
            throw e;
        }
    }

    return result;
}

From source file:com.netflix.bdp.s3mper.listing.ConsistentListingAspect.java

License:Apache License

/**
 * Ensures that all the entries in the metastore also exist in the FileSystem listing.
 * //from  w ww  .j a v a2 s. c om
 * @param pjp
 * @return
 * @throws Throwable 
 */
@Around("list() && !cflow(delete()) && !within(ConsistentListingAspect)")
public Object metastoreCheck(final ProceedingJoinPoint pjp) throws Throwable {

    FileSystem fs = (FileSystem) pjp.getThis();

    if (disabled) {
        return pjp.proceed();
    }

    Configuration conf = ((FileSystem) pjp.getTarget()).getConf();
    updateConfig(conf);

    FileStatus[] s3Listing = (FileStatus[]) pjp.proceed();
    FileStatus[] originalListing = null;
    if (darkload) {
        originalListing = s3Listing.clone();
    }

    List<Path> pathsToCheck = new ArrayList<Path>();

    Object pathArg = pjp.getArgs()[0];

    //Locate paths in the arguments
    if (pathArg instanceof Path) {
        pathsToCheck.add((Path) pathArg);
    } else if (pathArg instanceof List) {
        pathsToCheck.addAll((List) pathArg);
    } else if (pathArg.getClass().isArray()) {
        pathsToCheck.addAll(Arrays.asList((Path[]) pathArg));
    }

    //HACK: This is just to prevent the emr metrics from causing consisteny failures
    for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
        if (e.getClassName().contains("emr.metrics")) {
            log.debug("Ignoring EMR metrics listing for paths: " + pathsToCheck);
            return s3Listing;
        }
    }
    //END HACK

    long recheck = recheckCount;
    long delay = recheckPeriod;

    try {
        if (isTask(conf) && !checkTaskListings) {
            log.info("Skipping consistency check for task listing");
            return s3Listing;
        }

        if (isTask(conf)) {
            recheck = taskRecheckCount;
            delay = taskRecheckPeriod;
        }
    } catch (Exception e) {
        log.error("Error checking for task side listing", e);
    }

    try {
        List<FileInfo> metastoreListing = metastore.list(pathsToCheck);

        List<Path> missingPaths = ImmutableList.of();
        if (statOnMissingFile) {
            missingPaths = checkListing(metastoreListing, s3Listing);

            if (!missingPaths.isEmpty()) {
                List<FileStatus> fullListing = new ArrayList<FileStatus>();
                fullListing.addAll(Arrays.asList(s3Listing));
                for (Path path : missingPaths) {
                    FileStatus status = fs.getFileStatus(path);
                    fullListing.add(status);
                }
                s3Listing = fullListing.toArray(new FileStatus[0]);
            }
        } else {

            int checkAttempt;

            for (checkAttempt = 0; checkAttempt <= recheck; checkAttempt++) {
                missingPaths = checkListing(metastoreListing, s3Listing);

                if (delistDeleteMarkedFiles) {
                    s3Listing = delistDeletedPaths(metastoreListing, s3Listing);
                }

                if (missingPaths.isEmpty()) {
                    break;
                }

                //Check if acceptable threshold of data has been met.  This is a little
                //ambigious becuase S3 could potentially have more files than the
                //metastore (via out-of-band access) and throw off the ratio
                if (fileThreshold < 1 && metastoreListing.size() > 0) {
                    float ratio = s3Listing.length / (float) metastoreListing.size();

                    if (ratio > fileThreshold) {
                        log.info(format(
                                "Proceeding with incomplete listing at ratio %f (%f as acceptable). Still missing paths: %s",
                                ratio, fileThreshold, missingPaths));

                        missingPaths.clear();
                        break;
                    }
                }

                if (recheck == 0) {
                    break;
                }

                log.info(format("Rechecking consistency in %d (ms).  Files missing %d. Missing paths: %s",
                        delay, missingPaths.size(), missingPaths));
                Thread.sleep(delay);
                s3Listing = (FileStatus[]) pjp.proceed();
            }

            if (!missingPaths.isEmpty()) {
                alertDispatcher.alert(missingPaths);

                if (shouldFail(conf)) {
                    throw new S3ConsistencyException(
                            "Consistency check failed. See go/s3mper for details. Missing paths: "
                                    + missingPaths);
                } else {
                    log.error("Consistency check failed.  See go/s3mper for details. Missing paths: "
                            + missingPaths);
                }
            } else {
                if (checkAttempt > 0) {
                    log.info(format("Listing achieved consistency after %d attempts", checkAttempt));
                    alertDispatcher.recovered(pathsToCheck);
                }
            }
        }
    } catch (TimeoutException t) {
        log.error("Timeout occurred listing metastore paths: " + pathsToCheck, t);

        alertDispatcher.timeout("metastoreCheck", pathsToCheck);

        if (failOnTimeout) {
            throw t;
        }
    } catch (Exception e) {
        log.error("Failed to list metastore for paths: " + pathsToCheck, e);

        if (shouldFail(conf)) {
            throw e;
        }
    }

    return darkload ? originalListing : s3Listing;
}

From source file:com.netflix.bdp.s3mper.listing.ConsistentListingAspect.java

License:Apache License

/**
 * Rename listing records based on a rename call from the FileSystem.
 *
 * @param pjp//w ww  .  j  a  va 2 s .  c om
 * @return
 * @throws Throwable
 */
@Around("rename() && !within(ConsistentListingAspect)")
public Object metastoreRename(final ProceedingJoinPoint pjp) throws Throwable {
    if (disabled) {
        return pjp.proceed();
    }

    Configuration conf = ((FileSystem) pjp.getTarget()).getConf();
    updateConfig(conf);
    FileSystem fs = (FileSystem) pjp.getTarget();

    Path srcPath = (Path) pjp.getArgs()[0];
    Path dstPath = (Path) pjp.getArgs()[1];

    Preconditions.checkNotNull(srcPath);
    Preconditions.checkNotNull(dstPath);

    RenameInfo renameInfo = new RenameInfo(fs, srcPath, dstPath);
    metadataRename(conf, fs, renameInfo);

    Object obj = pjp.proceed();
    if ((Boolean) obj) {
        // Everything went fine delete the old metadata.
        // If not then we'll keep the metadata to prevent incomplete listings.
        // Manual cleanup will be required in the case of failure.
        metadataCleanup(conf, fs, renameInfo);
    }
    return obj;
}

From source file:com.netflix.bdp.s3mper.listing.ConsistentListingAspect.java

License:Apache License

/**
 * Deletes listing records based on a delete call from the FileSystem.
 * // w w w  .jav  a  2s.c  o m
 * @param pjp
 * @return
 * @throws Throwable 
 */
@Around("delete() && !within(ConsistentListingAspect)")
public Object metastoreDelete(final ProceedingJoinPoint pjp) throws Throwable {
    if (disabled) {
        return pjp.proceed();
    }

    Configuration conf = ((FileSystem) pjp.getTarget()).getConf();
    updateConfig(conf);

    Path deletePath = (Path) pjp.getArgs()[0];

    boolean recursive = false;

    if (pjp.getArgs().length > 1) {
        recursive = (Boolean) pjp.getArgs()[1];
    }

    try {
        FileSystem s3fs = (FileSystem) pjp.getTarget();

        Set<Path> filesToDelete = new HashSet<Path>();
        filesToDelete.add(deletePath);

        List<FileInfo> metastoreFiles = metastore.list(Collections.singletonList(deletePath));

        for (FileInfo f : metastoreFiles) {
            filesToDelete.add(f.getPath());
        }

        try {
            if (s3fs.getFileStatus(deletePath).isDir() && recursive) {
                filesToDelete.addAll(recursiveList(s3fs, deletePath));
            }
        } catch (Exception e) {
            log.info("A problem occurred deleting path: " + deletePath + " " + e.getMessage());
        }

        for (Path path : filesToDelete) {
            metastore.delete(path);
        }
    } catch (TimeoutException t) {
        log.error("Timeout occurred deleting metastore path: " + deletePath, t);

        alertDispatcher.timeout("metastoreDelete", Collections.singletonList(deletePath));

        if (failOnTimeout) {
            throw t;
        }
    } catch (Exception e) {
        log.error("Error deleting paths from metastore: " + deletePath, e);

        if (shouldFail(conf)) {
            throw e;
        }
    }

    return pjp.proceed();
}