Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] How to refer to an introduced field from an advice?

Hi Wim,

Did you get an answer to this?  Have you tried this, which gets the
instance and then accesses the flags through it.

    pointcut indexingMethod(JMXStorageService instance):execution(*
StorageServiceImpl.Indexer.doIndexing())  && this(instance) ;

    void around(JMXStorageService instance):indexingMethod(instance){
       instance.m_indexingStarted = true;
        long startTime = System.currentTimeMillis();
        proceed(instance);
        instance.m_indexingDurationInMs = System.currentTimeMillis() -
startTime;
        instance.m_indexingDone = true;
    }


Andy

2009/12/22 Wim Deblauwe <wim.deblauwe@xxxxxxxxx>:
> Hi,
>
> I want to add some profiling to a (Spring) service I have. So far, I have
> this:
>
> public aspect StorageServiceJmx
> {
>     declare parents : StorageServiceImpl implements JMXStorageService;
>
>     declare @type : StorageServiceImpl : @ManagedResource(objectName =
> "com.traficon.tmsng.server.common.storage:name=storageService");
>
>     public interface JMXStorageService extends StorageService
>     {
>         boolean isIndexingStarted();
>
>         boolean isIndexingDone();
>
>         long getIndexingDurationInMs();
>     }
>
>     private boolean JMXStorageService.m_indexingStarted = false;
>     private boolean JMXStorageService.m_indexingDone = false;
>     private long JMXStorageService.m_indexingDurationInMs = -1;
>
>
>     @ManagedAttribute
>     public boolean JMXStorageService.isIndexingStarted()
>     {
>         return m_indexingStarted;
>     }
>
>     @ManagedAttribute
>     public boolean JMXStorageService.isIndexingDone()
>     {
>         return m_indexingDone;
>     }
>
>     @ManagedAttribute
>     public long JMXStorageService.getIndexingDurationInMs()
>     {
>         return m_indexingDurationInMs;
>     }
>
>     pointcut indexingMethod():execution(*
> StorageServiceImpl.Indexer.doIndexing());
>
>     void around():indexingMethod(){
>         m_indexingStarted = true;
>         long startTime = System.currentTimeMillis();
>         proceed();
>         m_indexingDurationInMs = System.currentTimeMillis() - startTime;
>         m_indexingDone = true;
>     }
>
> }
>
> I have a class called 'StorageServiceImpl' that I want to make JMX enabled.
> Then I also add 3 methods and 3 fields via ITD. The problem is now in the
> around advice. The pointcut refers to a private method in a private inner
> class of StorageServiceImpl. In my around advice, I want to update the
> private fields I have introduced.
>
> How do I get a reference to the JMXStorageService in the around advice so I
> can set the fields?
>
> regards,
>
> Wim
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top