Example usage for org.aspectj.lang ProceedingJoinPoint proceed

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

Introduction

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

Prototype

public Object proceed() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:com.mycompany.flooringmvc.controllers.createAudit.java

public Object createLog(ProceedingJoinPoint pjp) throws Throwable {

    Order output = (Order) pjp.proceed();

    int orderId = output.getId();
    String product = output.getProduct();
    double total = output.getTotal();
    String name = output.getName();

    Audit audit = new Audit();
    audit.setOrderId(orderId);// w w w  .j a  v  a2  s  .  c  o  m
    audit.setProductType(product);
    audit.setTotal(total);
    audit.setType("Created");
    audit.setName(name);

    adao.createNew(audit);

    return output;
}

From source file:com.mycompany.flooringmvc.controllers.createAudit.java

public Object updateLog(ProceedingJoinPoint pjp) throws Throwable {

    Order output = (Order) pjp.proceed();

    int orderId = output.getId();
    String product = output.getProduct();
    double total = output.getTotal();
    String name = output.getName();

    Audit audit = new Audit();
    audit.setOrderId(orderId);/*from w w w. ja  v  a2s  .  c  o m*/
    audit.setProductType(product);
    audit.setTotal(total);
    audit.setType("Updated");
    audit.setName(name);

    adao.createNew(audit);

    return output;
}

From source file:com.mycompany.flooringmvc.controllers.createAudit.java

public Object deleteLog(ProceedingJoinPoint pjp) throws Throwable {

    Order output = (Order) pjp.proceed();

    int orderId = output.getId();
    String product = output.getProduct();
    double total = output.getTotal();
    String name = output.getName();

    Audit audit = new Audit();
    audit.setOrderId(orderId);/*from ww w  .  j  a va2  s.  c o  m*/
    audit.setProductType(product);
    audit.setTotal(total);
    audit.setType("Deleted");
    audit.setName(name);

    adao.createNew(audit);

    return output;
}

From source file:com.mycompany.floormaster.aop.TimerAspect.java

public Object timeMethod(ProceedingJoinPoint jp) {

    Object o = null;//www .j  a v  a2 s . c  o  m

    long start = System.nanoTime();

    try {
        o = jp.proceed();
    } catch (Throwable ex) {
        Logger.getLogger(TimerAspect.class.getName()).log(Level.SEVERE, null, ex);
    }

    long end = System.nanoTime();

    System.out.println("\n" + jp.getSignature().getName() + " took " + (end - start) + " nanoseconds");

    return o;
}

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

License:Apache License

/**
 * Updates the metastore when a FileSystem.create(...) method is called.
 * //  ww w .  j ava 2  s  .co  m
 * @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.
 * /*  w  ww.ja  v a2  s  .c  o m*/
 * @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/*from   w ww  . j a va2s .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.
 * //from  w  w  w  .j a  va2 s.co 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();
}

From source file:com.netflix.genie.web.aspect.DataServiceRetryAspect.java

License:Apache License

/**
 * Aspect implementation method of retrying the data service method on certain failures.
 * @param pjp join point/*from   w w  w. j a v  a  2 s . co  m*/
 * @return return the data method response
 * @throws GenieException any exception thrown by the data service method
 */
@Around("com.netflix.genie.web.aspect.SystemArchitecture.dataOperation()")
public Object profile(final ProceedingJoinPoint pjp) throws GenieException {
    try {
        return retryTemplate.execute(context -> pjp.proceed());
    } catch (GenieException | ConstraintViolationException e) {
        throw e;
    } catch (Throwable e) {
        throw new GenieServerException(e);
    }
}

From source file:com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCacheAspect.java

License:Apache License

@Around("cacheRemoveAnnotationPointcut()")
public Object methodsAnnotatedWithCacheRemove(final ProceedingJoinPoint joinPoint) throws Throwable {
    Method method = getMethodFromTarget(joinPoint);
    Object obj = joinPoint.getTarget();
    Object[] args = joinPoint.getArgs();
    Validate.notNull(method, "failed to get method from joinPoint: %s", joinPoint);
    MetaHolder metaHolder = MetaHolder.builder().args(args).method(method).obj(obj)
            .executionType(ExecutionType.SYNCHRONOUS).build();
    CacheInvocationContext<CacheRemove> context = CacheInvocationContextFactory
            .createCacheRemoveInvocationContext(metaHolder);
    HystrixRequestCacheManager.getInstance().clearCache(context);
    return joinPoint.proceed();
}