directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: Usage of static variables in BaseInterceptor
Date Thu, 13 Aug 2015 21:53:40 GMT
Le 13/08/15 20:40, Stefan Seelmann a écrit :
> Hi dev,
>
> while doing some checkstyle cleanup in ApacheDS I found some strange
> usage of static varables, e.g. in BaseInterceptor, there are lot of
> definitions like
>
>     protected static AttributeType OBJECT_CLASS_AT;
>
> However those variables are not initialized in a static block, but in
> the BaseInterceptor.init() method which is called for each interceptor
> added. This means during server startup this static varables are set
> multiple times.
>
> Is there are reason that those are static? Is it to save some space
> because I suspect that each AT is the same?
>
> Otherwise I'd remove the static keyword and rename the variables,
> because in fact they member variables.

Those variable are meant to be initialized once and only once. I think
the current code is only implementing this partially. The rational is
that we are using AT all over the interceptors, and they never change
(because the schema can't be updated dynamically without a server
restart). Having those variables allows the interceptor instance to
avoid doing a hell lots of lookups.

Can it be done in a static code ? Short answer : only if we have a way
to get access to the schemaManager instance, and I don't think we do.

So this is a partial implementation that saves a bit of CPU when a
session uses many times eachinterceptors. It does not save as much CPU
as expected, if those variable were to be initialized once and only once.

So to speak, it's not perfect. It's not even good if we consider that we
could imagine a future situation where the schemaManager is to be
updated without restarting the server, as we may have to reload those AT
(not likely, but who knows).

So, here is what I think : we should have a diect access to those AT
through the SchemaManager without having to do a lookup in the
registries. Some ways to do it is to have a static class that is
initialized after the SM, and which provides a direct access to the AT,
like :

...
AttributeType objectClassAt =
directoryService.getAtProvider.getObjectClass();
...

where AtProvider class is like :

class AtProvider
{
    private static AttributeType OBJECT_CLASS_AT;
    ...

    AtProvider( SchemaManager sm)
    {
        OBJECT_CLASS_AT = sm.lookupAttributeType( OBJECT_CLASS_OID );
        ...
    }

    public AttributeType getObjectClass()
    {
        return OBJECT_CLASS_AT;
    }
    ...
}

Ideally, the VM would inline the getObjectClass() method to have a
direct access to the OBJECT_CLASS_AT instance.

This is just a suggestion, there may be better ways.

I hope I explain the reason we have such variables, even if it's not
perfect...



Mime
View raw message