Пример #1
0
 public Object checkServiceAOP(ProceedingJoinPoint call) throws Throwable {
   try {
     checkService((ServiceStatusDetectable) call.getThis());
   } catch (Throwable e) {
     LOG.error("Could not check service status", e);
   }
   return call.proceed();
 }
Пример #2
0
 @Around("execution(java.util.*  com.acme.domain.**.get*())")
 public Object lazy(ProceedingJoinPoint pjp) throws Throwable {
   Object res = pjp.proceed();
   if (res instanceof AbstractPersistentCollection
       && !((AbstractPersistentCollection) res).wasInitialized()) {
     EntityManagerImpl em =
         (EntityManagerImpl) Persistence.createEntityManagerFactory("jpa").createEntityManager();
     em.getSession().replicate(pjp.getThis(), ReplicationMode.LATEST_VERSION);
     res.equals(null);
     em.close();
   }
   return res;
 }
Пример #3
0
 /**
  * Do basic logging.
  *
  * @param pjp the pjp
  * @return the object
  * @throws Throwable the throwable
  */
 public Object doBasicLogging(final ProceedingJoinPoint pjp) throws Throwable {
   // start stopwatch
   System.out.println("Kind : " + pjp.getKind());
   System.out.println("args : " + pjp.getArgs());
   System.out.println("signature : " + pjp.getSignature());
   System.out.println("target : " + pjp.getTarget());
   System.out.println("this : " + pjp.getThis());
   final long start = System.nanoTime();
   final Object retVal = pjp.proceed();
   // stop stopwatch
   System.out.println("time taken : " + (System.nanoTime() - start));
   System.out.println(retVal);
   return retVal;
 }
Пример #4
0
 @Around("execution(* brut.androlib.res.data.ResPackage.getResSpec(..))" + "&& args(resID)")
 public ResResSpec getResSpec(ProceedingJoinPoint joinPoint, ResID resID) throws Throwable {
   try {
     return (ResResSpec) joinPoint.proceed(joinPoint.getArgs());
   } catch (UndefinedResObject e) {
     if (ShakaDecodeOption.getInstance().isFuckUnkownId()) {
       ResPackage thiz = (ResPackage) joinPoint.getThis();
       return new ResResSpec(
           resID,
           String.format("[%08x]", resID.id),
           thiz,
           new ResTypeSpec("FuckUnkownId", thiz.getResTable(), thiz, (byte) (resID.id & 0xFF), 0));
     } else {
       throw e;
     }
   }
 }
Пример #5
0
  /**
   * 创建并保存日志对象
   *
   * @param logMethod
   * @param jp
   */
  private void doLog(LogMethod logMethod, ProceedingJoinPoint jp) {
    String logText = logMethod.name();
    String classStr = jp.getTarget().getClass().getName();

    Object obj = jp.getThis();
    if (obj instanceof AbstractAction) {
      AbstractAction action = (AbstractAction) obj;
      HttpServletRequest request = action.getRequest();
      logText += "\r\n请求:" + request.getRequestURI() + "\r\n";
      Enumeration params = request.getParameterNames();
      while (params.hasMoreElements()) {
        String param = (String) params.nextElement();
        String value = request.getParameter(param);
        logText += ("参数->" + param + ":" + value + "\r\n");
      }
    }
    saveLog(jp, logText, classStr);
  }
  @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;
    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());
    }
  }