On 13 September 2010 11:07, Gadbury <[email protected]> wrote:
>
> Thanks Jukka and James for your replies.
>
> James: During iteration of repository's fields, It never finds a field type
> that equals RepositoryImpl.class. If I inspect repository, it has a
> private
> member called repository. I have tried using
> BindableRepository.class.getFields() and .getDeclaredFields().
>
> I changed the code to this. This works for me. Not sure if that means it
> is good code though!
>
>
Yes, sorry, you will need getDeclaredFields rather than getFields, since you
need to access a private field on that class. I did say it was from memory!
>
> Repository repository =
> RepositoryServiceLocator.INSTANCE.getRepository();
> RepositoryImpl impl = null;
>
> if (repository instanceof RepositoryImpl)
> {
> impl = (RepositoryImpl) repository;
> }
> else if (repository instanceof BindableRepository)
> {
> for (Field field :
> BindableRepository.class.getDeclaredFields())
> {
> if
> (field.getType().equals(JackrabbitRepository.class))
> {
> field.setAccessible(true);
> impl = (RepositoryImpl)
> field.get(repository);
> break;
> }
> }
>
> //Field privateRepositoryField =
> BindableRepository.class.getDeclaredField("repository");
> //privateRepositoryField.setAccessible(true);
> //impl = (RepositoryImpl)
> privateRepositoryField.get(repository);
> }
>
> if (impl != null)
> {
> CacheManager manager = impl.getCacheManager();
>
> manager.setMaxMemory (256 * 1024 *
> 1024); // default is 16 * 1024 *
> 1024
> manager.setMaxMemoryPerCache (64 * 1024 * 1024); //
> default is 4 * 1024 *
> 1024
> manager.setMinMemoryPerCache (1 * 1024 * 1024);
> // default is 128 *
> 1024]
> }
>
> Commented out is another method I was using to access the repository field.
>
> Not sure which way would be best. I figured the commented out way assumes
> that the field will always be called "repository" so could break more
> easily.
>
Yes, that's what I was referring to in my earlier mail. In Jackrabbit 1.4,
the field was named "delegatee", but in a later version it was renamed
"repository". That's when we elected to use iteration and filtering rather
than trying to access a named field.
>
> Cheers,
>
> James
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/CacheManager-Cannot-Cast-BindableRepository-to-RepositoryImpl-tp2533300p2537181.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>