@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); } }
@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); } }
@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); } }
@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(); }
@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); } }
@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); } }
@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... } }
public StaticPart get(StaticPart default_pointcut) { if (XTraceSettings.On()) { StaticPart thecaller = caller.get(); return thecaller == null ? default_pointcut : thecaller; } return null; }
public void close(JoinPoint.StaticPart jp) throws IOException { DiskResource.Close.starting(this, jp, true); try { super.close(); } finally { DiskResource.Close.finished(this, jp, true); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
public NetworkOutputStreamWrapper(OutputStream os, JoinPoint.StaticPart instantiationJoinPoint, boolean isLoopback) { super(os); this.creator = instantiationJoinPoint; if (isLoopback) Write = Network.LoopbackWrite; else Write = Network.Write; }
public void close(JoinPoint.StaticPart jp) throws IOException { Network.Close.starting(out, jp); try { out.close(); } finally { Network.Close.finished(out, jp); } }
public void flush(JoinPoint.StaticPart jp) throws IOException { Network.Flush.starting(out, jp); try { out.flush(); } finally { Network.Flush.finished(out, jp); } }
public void write(int b, JoinPoint.StaticPart jp) throws IOException { Write.starting(out, jp); try { out.write(b); } finally { Write.finished(out, 1, jp); } }
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); } }
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); } }
public void flush(JoinPoint.StaticPart jp) throws IOException { DiskResource.Flush.starting(this, jp, true); try { super.flush(); } finally { DiskResource.Flush.finished(this, jp, true); } }
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); } }
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); } }
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); } }
public NetworkInputStreamWrapper(InputStream is, JoinPoint.StaticPart jp, boolean isLoopback) { super(is); this.creator = jp; if (isLoopback) Read = Network.LoopbackRead; else Read = Network.Read; }
public int read(JoinPoint.StaticPart jp) throws IOException { Read.starting(in, jp); try { return in.read(); } finally { Read.finished(in, 1, jp); } }
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); } }
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); } }
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); } }
/** * 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; }
/** 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); } }
/** 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()); } }
@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... } }
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); }
public void set(StaticPart jp) { caller.set(jp); }
public StaticPart get() { return caller.get(); }
public void set(StaticPart jp) { }