getOSGiComponentInstanceOfType sometimes return null

Stefan F_ December 12, 2018

Hi!

I have followed the tutorial from j-tricks accessing Active Objects using my own service (https://www.j-tricks.com/tutorials/active-objects-injection).

This is really working well (using Jira 7.10.2).

But ... sometimes after Jira startup, the getOSGiComponentInstanceOfType returns null.

I think (I guess, but I don't know!) the reason is that some clients accessing my REST api during Jira startup and these calls sometimes trigger the getOSGiComponentInstanceOfType quite early.

And the strange thing is, that it is repeatable null, then. Even when I uninstall and reinstall my plugin, it will return null until next reboot.

So I wonder if there is a kind of caching behind getOSGiComponentInstanceOfType. Is there a way I can wipe this cache or really reinitialize my component?

Here are my classes:

// AoBranchService.java

public interface AoBranchService
{
ActiveObjects getActiveObjects();
}

// AoBranchServiceImpl.java

@ExportAsService
({AoBranchService.class})
@Name("AoBranchServiceImpl")
public class AoBranchServiceImpl implements AoBranchService
{
private static final Logger log = LoggerFactory.getLogger(AoBranchServiceImpl.class);

@ComponentImport
private final ActiveObjects m_ao;

@Inject
public AoBranchServiceImpl(ActiveObjects ao)
{
m_ao = ao;
}

@Override
public ActiveObjects getActiveObjects()
{
return m_ao;
}
}

// BranchManager

public class BranchManager implements BranchManagerInterface
{
private static final Logger log = LoggerFactory.getLogger(BranchManager.class);

private ActiveObjects m_aoBranches = null;

public BranchManager()
{
// get access to database (active object table for this plugin)
AoBranchService aoBranchService = ComponentAccessor.getOSGiComponentInstanceOfType(AoBranchService.class);

if (aoBranchService != null)
{
m_aoBranches = aoBranchService.getActiveObjects();
}
else
{
log.error("Critical: could not get AoBranchService");
}
}
[...]


//

 

Help! I have no idea how I can wait until I can call getOSGiComponentInstanceOfType, safely.

Are there alternatives how to retrieve this instance?

Are there special wait methods I can invoke?

Can I lazy load my plugin somehow?

 

Thanks for any hint!

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events