I have the following class structure which works:
C1 <>------ C2 <>-------- C3 ------<> C4
The <> is supposed to be a UML filled diamond denoting object composition.
These are @References to other Services.
If I then add a @Reference to C1 in C4 I get a cycle:
C1 <>------ C2 <>-------- C3 ------<> C4 <>--
| |
|_________________________________ |
Sometimes on startup I'll get an Exception saying
"ServiceFactory.getService() resulted in a cycle", but other times the
application starts up and runs without any problems.
Is there something I can do to make this behave consistently? If it is
supposed to throw an Exception it should do it every time, not
inconsistently.
My second question is if I can fix this by dropping the @Reference that C4
has to C3 and having C4 get a (lower case) reference to C3 by going through
C1 and C2 with getter methods like this:
C1 <>------ C2 <>-------- C3 C4 <>--
| |
|_________________________________ |
Are there any problems getting the @Reference that C2 had to C3 like this:
@Service
public class C2 {
private @Reference IC3 c3;
IC3 getC3Reference() {return c3;}
}
where IC3 is the interface for Service C3.
Thanks.