Java 类org.aspectj.lang.JoinPoint.StaticPart 实例源码

项目:devops-cstack    文件:ModuleAspect.java   
@AfterThrowing(pointcut = "execution(* cn.org.once.cstack.service.ModuleService.remove(..)) " +
    "|| execution(* cn.org.once.cstack.service.ModuleService.initModule(..))",
    throwing = "e")
public void afterThrowingModule(StaticPart staticPart,
                                Exception e)
    throws ServiceException {
    User user = this.getAuthentificatedUser();
    Message message = null;
    logger.debug("CALLED CLASS : " + staticPart.getSignature().getName());
    switch (staticPart.getSignature().getName().toUpperCase()) {
        case initModule:
            message = MessageUtils.writeAfterThrowingModuleMessage(e, user,
                initModule);
            break;
        case deleteType:
            message = MessageUtils.writeAfterThrowingModuleMessage(e, user,
                deleteType);
            break;
    }
    if (message != null) {
        messageService.create(message);
    }
}
项目:devops-cstack    文件:ServerAspect.java   
@AfterReturning(pointcut = "execution(* cn.org.once.cstack.ServerService.create(..)) "
        + "|| execution(* cn.org.once.cstack.ServerService.updateType(..))", returning = "result")
public void afterReturningServer(StaticPart staticPart, Object result) throws MonitorException {
    try {
        if (result == null)
            return;
        Server server = (Server) result;
        User user = server.getApplication().getUser();
        Message message = null;
        switch (staticPart.getSignature().getName().toUpperCase()) {
        case createType:
            message = MessageUtils.writeServerMessage(user, server, createType);
            break;
        case updateType:
            message = MessageUtils.writeServerMessage(user, server, updateType);
            break;

        }
        logger.info(message.toString());
        messageService.create(message);

    } catch (ServiceException e) {
        throw new MonitorException("Error afterReturningApplication", e);
    }
}
项目:devops-cstack    文件:DeploymentAspect.java   
@AfterReturning(pointcut = "execution(* cn.org.once.cstack.service.DeploymentService.create(..))", returning = "result")
public void afterReturningDeployment(StaticPart staticPart, Object result)
    throws MonitorException {
    try {
        if (result == null)
            return;
        Deployment deployment = (Deployment) result;
        User user = deployment.getApplication().getUser();
        Message message = null;
        switch (staticPart.getSignature().getName().toUpperCase()) {
            case createType:
                message = MessageUtils.writeDeploymentMessage(user, deployment,
                    createType);
                break;
        }

        if (message != null) {
            logger.info(message.toString());
            messageService.create(message);
        }

    } catch (ServiceException e) {
        throw new MonitorException("Error afterReturningApplication", e);

    }
}
项目:spring4-understanding    文件:MethodInvocationProceedingJoinPointTests.java   
@Test
public void testCanGetStaticPartFromJoinPoint() {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {
        @Override
        public void before(Method method, Object[] args, Object target) throws Throwable {
            StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
            assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
            assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
            assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
            assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
}
项目:class-guard    文件:MethodInvocationProceedingJoinPointTests.java   
@Test
public void testCanGetStaticPartFromJoinPoint() {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {
        @Override
        public void before(Method method, Object[] args, Object target) throws Throwable {
            StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
            assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
            assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
            assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
            assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
}
项目:devops-cstack    文件:ModuleAspect.java   
@AfterReturning(pointcut = "execution(* cn.org.once.cstack.service.ModuleService.remove(..)) " +
    "&& execution(* cn.org.once.cstack.service.ModuleService.initModule(..))",
    returning = "result")
public void afterReturningModule(StaticPart staticPart, Object result)
    throws MonitorException {
    try {
        if (result == null)
            return;
        Module module = (Module) result;
        User user = module.getApplication().getUser();
        // scape tool module
        if (!module.getImage().getImageType().equalsIgnoreCase("tool")) {
            Message message = null;
            switch (staticPart.getSignature().getName().toUpperCase()) {
                case initModule:
                    message = MessageUtils.writeModuleMessage(user, module,
                        createType);
                    break;

                case deleteType:
                    message = MessageUtils.writeModuleMessage(user, module,
                        deleteType);
                    break;
            }
            if (message != null) {
                logger.info(message.toString());
                messageService.create(message);
            }
        }
    } catch (ServiceException e) {
        throw new MonitorException("Error afterReturningApplication", e);

    }
}
项目:devops-cstack    文件:ServerAspect.java   
@AfterThrowing(pointcut = "execution(* cn.org.once.cstack.ServerService.updateType(..))", throwing = "e")
public void afterThrowingServer(StaticPart staticPart, Exception e) throws ServiceException {
    User user = this.getAuthentificatedUser();
    Message message = null;
    logger.debug("CALLED CLASS : " + staticPart.getSignature().getName());
    switch (staticPart.getSignature().getName().toUpperCase()) {
    case updateType:
        message = MessageUtils.writeAfterThrowingModuleMessage(e, user, updateType);
        break;
    }
    if (message != null) {
        messageService.create(message);
    }
}
项目:spring4-understanding    文件:MethodInvocationProceedingJoinPointTests.java   
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {
        @Override
        public void before(Method method, Object[] args, Object target) throws Throwable {
            // makeEncSJP, although meant for computing the enclosing join point,
            // it serves our purpose here
            JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
            JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

            assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
            assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
            assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

            assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
            assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
            assertEquals(aspectJVersionJp.toString(), jp.toString());
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    itb.getAge();
    itb.setName("foo");
    itb.getDoctor();
    itb.getStringArray();
    itb.getSpouse();
    itb.setSpouse(new TestBean());
    try {
        itb.unreliableFileOperation();
    } catch (IOException ex) {
        // we don't realy care...
    }
}
项目:tracing-framework    文件:JoinPointTracking.java   
public StaticPart get(StaticPart default_pointcut) {
    if (XTraceSettings.On()) {
        StaticPart thecaller = caller.get();
        return thecaller == null ? default_pointcut : thecaller;
    }
    return null;
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public void close(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Close.starting(this, jp, true);
    try {
        super.close();
    } finally {
        DiskResource.Close.finished(this, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public int read(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Read.starting(this, 1, jp, true);
    try {
        return super.read();
    } finally {
        DiskResource.Read.finished(this, 1, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public int read(JoinPoint.StaticPart jp, byte[] b) throws IOException {
    DiskResource.Read.starting(this, b.length, jp, true);
    int numRead = 0;
    try {
        return numRead = super.read(b);
    } finally {
        DiskResource.Read.finished(this, numRead, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public int read(JoinPoint.StaticPart jp, byte[] b, int off, int len) throws IOException {
    DiskResource.Read.starting(this, len, jp, true);
    int numRead = 0;
    try {
        return numRead = super.read(b, off, len);
    } finally {
        DiskResource.Read.finished(this, numRead, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public void write(int b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, 1, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, 1, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public void write(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, b.length, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, b.length, jp, true);
    }
}
项目:tracing-framework    文件:RandomAccessFileWrapper.java   
public void write(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, len, jp, true);
    try {
        super.write(b, off, len);
    } finally {
        DiskResource.Write.finished(this, len, jp, true);
    }
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public NetworkOutputStreamWrapper(OutputStream os, JoinPoint.StaticPart instantiationJoinPoint, boolean isLoopback) {
    super(os);
    this.creator = instantiationJoinPoint;
    if (isLoopback)
        Write = Network.LoopbackWrite;
    else
        Write = Network.Write;
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public void close(JoinPoint.StaticPart jp) throws IOException {
    Network.Close.starting(out, jp);
    try {
        out.close();
    } finally {
        Network.Close.finished(out, jp);
    }
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public void flush(JoinPoint.StaticPart jp) throws IOException {
    Network.Flush.starting(out, jp);
    try {
        out.flush();
    } finally {
        Network.Flush.finished(out, jp);
    }
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public void write(int b, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b);
    } finally {
        Write.finished(out, 1, jp);
    }
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public void write(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b);
    } finally {
        Write.finished(out, b.length, jp);
    }
}
项目:tracing-framework    文件:NetworkOutputStreamWrapper.java   
public void write(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    Write.starting(out, jp);
    try {
        out.write(b, off, len);
    } finally {
        Write.finished(out, len, jp);
    }
}
项目:tracing-framework    文件:FileOutputStreamWrapper.java   
public void close(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Close.starting(this, jp, true);
    try {
        super.close();
    } finally {
        DiskResource.Close.finished(this, jp, true);
    }
}
项目:tracing-framework    文件:FileOutputStreamWrapper.java   
public void flush(JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Flush.starting(this, jp, true);
    try {
        super.flush();
    } finally {
        DiskResource.Flush.finished(this, jp, true);
    }
}
项目:tracing-framework    文件:FileOutputStreamWrapper.java   
public void write(int b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, 1, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, 1, jp, true);
        counter.wrote(1);
    }
}
项目:tracing-framework    文件:FileOutputStreamWrapper.java   
public void write(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, b.length, jp, true);
    try {
        super.write(b);
    } finally {
        DiskResource.Write.finished(this, b.length, jp, true);
        counter.wrote(b.length);
    }
}
项目:tracing-framework    文件:FileOutputStreamWrapper.java   
public void write(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    DiskResource.Write.starting(this, len, jp, true);
    try {
        super.write(b, off, len);
    } finally {
        DiskResource.Write.finished(this, len, jp, true);
        counter.wrote(len);
    }
}
项目:tracing-framework    文件:NetworkInputStreamWrapper.java   
public NetworkInputStreamWrapper(InputStream is, JoinPoint.StaticPart jp, boolean isLoopback) {
    super(is);
    this.creator = jp;
    if (isLoopback)
        Read = Network.LoopbackRead;
    else
        Read = Network.Read;
}
项目:tracing-framework    文件:NetworkInputStreamWrapper.java   
public int read(JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    try {
        return in.read();
    } finally {
        Read.finished(in, 1, jp);
    }
}
项目:tracing-framework    文件:NetworkInputStreamWrapper.java   
public int read(byte[] b, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    int numRead = 0;
    try {
        return numRead = in.read(b);
    } finally {
        Read.finished(in, numRead, jp);
    }
}
项目:tracing-framework    文件:NetworkInputStreamWrapper.java   
public int read(byte[] b, int off, int len, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    int numRead = 0;
    try {
        return numRead = in.read(b, off, len);
    } finally {
        Read.finished(in, numRead, jp);
    }
}
项目:tracing-framework    文件:NetworkInputStreamWrapper.java   
public long skip(long n, JoinPoint.StaticPart jp) throws IOException {
    Read.starting(in, jp);
    long numSkipped = 0;
    try {
        return numSkipped = in.skip(n);
    } finally {
        Read.finished(in, numSkipped, jp);
    }
}
项目:tracing-framework    文件:XTraceReport.java   
/**
 * Turns this report into an X-Trace "event", by adding the current thread's
 * parent event IDs to the report, generating a random event ID for the
 * report, and updating the current thread's parent event IDs to this
 * report's event ID
 * @param joinPoint 
 * 
 * @return This report, with additional fields added
 */
public XTraceReport makeXTraceEvent(StaticPart joinPoint) {
    AtomicInteger counter = new AtomicInteger();
    long taskId = XTraceBaggageInterface.getTaskID(counter);
    if (counter.get() > 1) {
        builder.addTags("TracingError");
    }
    long eventId = XTrace.randomId();
    Collection<Long> parentIds = XTraceBaggageInterface.getParentEventIds();
    setXTrace(taskId, eventId, parentIds);
    XTraceBaggageInterface.setParentEventId(eventId);
    return this;
}
项目:tracing-framework    文件:XTraceReport.java   
/** Indicates that the execution is entering the specified join point, and that all X-Trace reports should attribute to this join point */
public static void entering(JoinPoint.StaticPart jp) {
    if (jp == null) {
        originalJp.remove();
    } else {
        originalJp.set(jp);
    }
}
项目:tracing-framework    文件:XTraceReport.java   
/** Add information to the report such as source line, etc. */
public void setJoinPoint(JoinPoint.StaticPart joinPoint) {
    JoinPoint.StaticPart originalJoinPoint = originalJp.get();
    if (originalJoinPoint != null) {
        builder.setSource(originalJoinPoint.getSourceLocation().toString());
    } else if (joinPoint != null) {
        builder.setSource(joinPoint.getSourceLocation().toString());
    }
}
项目:class-guard    文件:MethodInvocationProceedingJoinPointTests.java   
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {
        @Override
        public void before(Method method, Object[] args, Object target) throws Throwable {
            // makeEncSJP, although meant for computing the enclosing join point,
            // it serves our purpose here
            JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
            JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

            assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
            assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
            assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

            assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
            assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
            assertEquals(aspectJVersionJp.toString(), jp.toString());
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    itb.getAge();
    itb.setName("foo");
    itb.getDoctor();
    itb.getStringArray();
    itb.getSpouses();
    itb.setSpouse(new TestBean());
    try {
        itb.unreliableFileOperation();
    } catch (IOException ex) {
        // we don't realy care...
    }
}
项目:Tanaguru    文件:EALoggerImpl.java   
public void logMethodExit(StaticPart staticPart, Object result) {
    // Nom de la méthode interceptée
    String name = staticPart.getSignature().toLongString();

    float time = ((float) (System.currentTimeMillis() - timeMap.get(name))) / 1000f;
    timeMap.remove(name);

    Logger.getLogger(EALoggerImpl.class).info(getHostname() + " - " + "LEAVING " + name + " returning: [" + result + "]");

    Logger.getLogger(EALoggerImpl.class).info("Execution Time is : " + time);
}
项目:tracing-framework    文件:JoinPointTracking.java   
public void set(StaticPart jp) {
    caller.set(jp);
}
项目:tracing-framework    文件:JoinPointTracking.java   
public StaticPart get() {
    return caller.get();
}
项目:tracing-framework    文件:JoinPointTracking.java   
public void set(StaticPart jp) {
}