Skip to main content

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

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

Back to the top