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:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Constructor.newInstance(..)) && target(constructor)")
public Object createNewCloudObjectViaReflection(ProceedingJoinPoint pjp, Object constructor) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    Constructor<?> constr = (Constructor<?>) constructor;
    Class<?> coType = constr.getDeclaringClass();

    // check if we are constructing some other object
    if (!coType.isAnnotationPresent(CloudObject.class))
        return pjp.proceed();

    // check if this is already a CGLib modified class
    if (CgLibUtil.isCGLibEnhancedClass(coType))
        return pjp.proceed();

    // everything checked, we should intercept this reflection call
    return deployCloudObject(coType, pjp.getArgs(), constr);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("target(object) && "
        + "(get(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObject *.*) || "
        + " get(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObjectParent *.*))")
public Object getCloudObjectField(Object object, ProceedingJoinPoint pjp) throws Throwable {

    // //from  w  w  w.j a v  a 2 s. c  om

    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    UUID id = CloudObjects.getId(object);

    if (id == null) {
        // maybe we are just working on a cloudobjectparent that is not actually a cloud object
        return pjp.proceed();
    }

    FieldSignature sig = (FieldSignature) pjp.getSignature();
    Field field = sig.getField();

    return getFieldValue(id, field);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Field.get(..)) && target(field)")
public Object getCloudObjectFieldViaReflection(ProceedingJoinPoint pjp, Field field) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext())
        return pjp.proceed();

    // check if this field is @local
    if (field.getAnnotation(Local.class) != null)
        return pjp.proceed();

    Field theField = field;/*from   ww  w . j  a  v a2 s  .  co  m*/
    Object arg = pjp.getArgs()[0];

    if (arg == null) {
        // we are getting a static field
        return pjp.proceed();
    }

    UUID id = CloudObjects.getId(arg);

    // check if we are intercepting a class we are not interested in
    if (!isCloudObjectOrParent(theField.getDeclaringClass()))
        return pjp.proceed();

    return getFieldValue(id, theField);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("target(object) && args(val) && "
        + "(set(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObject *.*) || "
        + " set(!@at.ac.tuwien.infosys.jcloudscale.annotations.Local * @at.ac.tuwien.infosys.jcloudscale.annotations.CloudObjectParent *.*))")
public void setCloudObjectField(Object object, Object val, ProceedingJoinPoint pjp) throws Throwable {

    if (JCloudScaleConfiguration.isServerContext()) {
        pjp.proceed();
        return;//  www  . j a  v  a  2s. co m
    }

    UUID id = CloudObjects.getId(object);

    if (id == null) {
        // maybe we are just working on a cloudobjectparent that is not actually a cloud object
        pjp.proceed();
        return;
    }

    if (CloudObjects.isDestroyed(id)) {
        // throw new JCloudScaleException("Field access on already destroyed CloudObject!");
        // this case happens during regular object construction - just proceed
        pjp.proceed();
        return;
    }

    FieldSignature sig = (FieldSignature) pjp.getSignature();
    Field field = sig.getField();

    setFieldValue(id, field, val);

}

From source file:at.ac.tuwien.infosys.jcloudscale.aspects.CloudObjectAspect.java

License:Apache License

@Around("call(* java.lang.reflect.Field.set(..)) && target(field)")
public void setCloudObjectFieldViaReflection(ProceedingJoinPoint pjp, Field field) throws Throwable {

    // check if we are running in a server context
    if (JCloudScaleConfiguration.isServerContext()) {
        pjp.proceed();
        return;/*from w  w w .  j av  a  2s .c  o  m*/
    }

    Field theField = field;

    // check if this field is @local
    if (field.getAnnotation(Local.class) != null) {
        pjp.proceed();
        return;
    }

    // check if we are intercepting a class we are not interested in
    if (!isCloudObjectOrParent(theField.getDeclaringClass())) {
        pjp.proceed();
        return;
    }

    Object arg = pjp.getArgs()[0];
    Object val = pjp.getArgs()[1];

    if (arg == null) {
        // we are setting a static field
        pjp.proceed();
        return;
    }

    UUID id = CloudObjects.getId(arg);

    setFieldValue(id, theField, val);

}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("call(void at.ac.tuwien.infosys.jcloudscale.management.CloudManager.destructCloudObject(..)) && target(manager)")
public void logObjectDestructed(ProceedingJoinPoint jp, CloudManager manager) throws Throwable {

    UUID coId = (UUID) jp.getArgs()[0];
    String address = manager.getHost(coId).getIpAddress();

    jp.proceed();

    log.info(String.format(// www  .  ja  v  a  2s  . c o  m
            "Destructed cloud object with id %s on host %s. We now manage %d cloud objects on %d hosts.",
            coId.toString(), address, manager.countCloudObjects(), manager.countVirtualMachines()));

}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("execution(Object at.ac.tuwien.infosys.jcloudscale.management.CloudManager.invokeCloudObject(..)) && target(manager) && args(*, method, *, *)")
public Object logInvokedCloudObject(ProceedingJoinPoint jp, CloudManager manager, Method method)
        throws Throwable {

    UUID coId = (UUID) jp.getArgs()[0];
    //      Object[] args = (Object[])jp.getArgs()[2];
    String address = coId == null ? null : manager.getHost(coId).getIpAddress();
    String methodName = method.getName();

    long before = System.currentTimeMillis();
    Object ret = jp.proceed();
    long after = System.currentTimeMillis();

    //      log.info(String.format("Invoked method %s of cloud object %s with parameters %s on host %s. Result= %s Invocation took %d ms.",
    //            methodName,
    //            coId.toString(),
    //            Arrays.toString(args),
    //            address,
    //            ret,
    //            (after - before)
    //      ));/*  w w  w.  j  ava 2s.  c  o  m*/

    log.info(String.format("Invoked method %s of cloud object %s on host %s. Invocation took %d ms.",
            methodName, coId, address, (after - before)));

    return ret;
}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("call(at.ac.tuwien.infosys.jcloudscale.vm.IVirtualHost at.ac.tuwien.infosys.jcloudscale.vm.VirtualHostPool.findFreeHost(..))")
public IVirtualHost logSelectedCloudHost(ProceedingJoinPoint jp) throws Throwable {

    long before = System.currentTimeMillis();
    IVirtualHost ret = (IVirtualHost) jp.proceed();
    long after = System.currentTimeMillis();

    log.info(String.format("Finding a suitable host took %d ms in total.", (after - before)));

    return ret;/*w  ww .j  a v a  2  s  .c o m*/

}

From source file:at.ac.tuwien.infosys.jcloudscale.logging.RemoteObjectLoggingAspect.java

License:Apache License

@Around("execution(void at.ac.tuwien.infosys.jcloudscale.management.JCloudScaleReferenceCallbackListener.MessageHandler.executeCallback(..)) && args(callback)")
public void referenceHandlerInvoked(ProceedingJoinPoint jp, StartCallbackObject callback) throws Throwable {

    log.info(String.format("Starting to execute callback of reference object %s (method %s)",
            callback.getRef().getReferenceObjectId().toString(), callback.getMethod()));

    jp.proceed();

    log.info("Finished callback on client side");

}

From source file:at.ac.tuwien.infosys.jcloudscale.server.aspects.eventing.ObjectLifecycleEventAspect.java

License:Apache License

@Around("execution(public void at.ac.tuwien.infosys.jcloudscale.server.JCloudScaleServer.destroyCloudObject(..))")
public void matchObjectDestroyed(ProceedingJoinPoint pjp) throws Throwable {

    Class<?> cloudObjectType = null;
    JCloudScaleServer server = null;//from   www . j av  a  2  s  .com
    UUID cloudObjectId = null;
    try {
        server = (JCloudScaleServer) pjp.getThis();
        cloudObjectId = UUID.fromString((String) (pjp.getArgs()[0]));

        Object cloudObject = server.getCloudObject(cloudObjectId);
        if (cloudObject != null)
            cloudObjectType = cloudObject.getClass();
    } catch (Exception e) {
        e.printStackTrace();
        log.severe("Error while triggering ObjectDestroyedEvent: " + e.getMessage());
    }

    pjp.proceed();

    try {
        ObjectDestroyedEvent event = new ObjectDestroyedEvent();
        initializeBaseEventProperties(event);
        // XXX AbstractJCloudScaleServerRunner
        // UUID serverId = JCloudScaleServerRunner.getInstance().getId();
        UUID serverId = AbstractJCloudScaleServerRunner.getInstance().getId();
        event.setHostId(serverId);
        event.setObjectId(cloudObjectId);
        event.setObjectType(cloudObjectType);
        getMqHelper().sendEvent(event);
        log.finer("Sent object destroyed for object " + cloudObjectId);
    } catch (Exception e) {
        e.printStackTrace();
        log.severe("Error while triggering ObjectDestroyedEvent: " + e.getMessage());
    }

}