I Don't Get This... [message #754295] |
Tue, 01 November 2011 21:14 |
Geoffry Roberts Messages: 29 Registered: March 2011 |
Junior Member |
|
|
All,
Why am I getting (at least) two object instantiations in a singleton bundle?
I am trying to use blueprint and I have setup a simple set of bundles to work with.
I have an interface bundle and an implementation bundle. I then have a bundle that contains an implementation of CommandProvider. This bundle is declared as a singleton. The idea is to execute a command that calls a method in the interface bundle.
During execution, I am encountering at least two CommandProviders. (1) Is being instantiated by the blueprint framework, but another (2) shows itself when the aforementioned command is issued.
NOTE: cmdapi.CommandSet implements CommandProvider.
This is from the log file. Notice the text that says, this==>1433741306 and this==>517116146, the numbers are the objects' hashcodes indicating there are two different objects. Why is this? especially considering that the bundle is a singleton?
This is what logs when the CommandSet class is instatiated:
[2011-11-01 12:41:18.946] INFO iniBlueprintExtenderThread-8 cmdapi.CommandSet setAPI==>blue!!
[2011-11-01 12:41:18.946] INFO iniBlueprintExtenderThread-8 cmdapi.CommandSet this==>1433741306
[2011-11-01 12:41:18.946] INFO iniBlueprintExtenderThread-8 cmdapi.CommandSet <==setAPI
...left out...
hread-8 cmdapi.CommandSet startUp=====>cmdapi.CommandSet
[2011-11-01 12:41:18.947] INFO iniBlueprintExtenderThread-8 cmdapi.CommandSet this==>1433741306
[2011-11-01 12:41:18.947] INFO iniBlueprintExtenderThread-8 cmdapi.CommandSet getBlue==>blue!!
This is what logs when I execute the command:
[2011-11-01 12:42:06.802] INFO Equinox Console Session cmdapi.CommandSet this==>517116146
This is the code being executed:
public class CommandSet implements CommandProvider {
Logger Log = LoggerFactory.getLogger(CommandSet.class);
API blueAPI = null;
// First, this method is being called upon instantiation. At this point, the value
// api is not null. The object is i.e this==>1433741306
public void setBlue(API api) {
Log.info("setAPI==>" + api.getAPI());
Log.info("this==>" + this.hashCode());
this.blueAPI = api;
Log.info("<==setAPI");
}
// Second, this method is also being called upon instantiation. At this point, the
// value blueAPI is not null. The object is i.e this==>1433741306
public void startUp() {
Log.info("startUp=====>" + this.getClass().getName());
Log.info("this==>" + this.hashCode());
Log.info("getBlue==>" + blueAPI.getAPI());
}
// Third, this method is the command, which is called from the OSGi command line.
// At this point the value blueAPI is null. Why? because we now have a different
// object i.e this==>517116146. Why do we have a different object?
public Object _blue(CommandInterpreter itrp) {
itrp.println("going blue!!" + blueAPI);
Log.info("this==>" + this.hashCode());
Log.info("getBlue==>" + blueAPI.getAPI());
itrp.println("getBlue==>" + blueAPI.getAPI());
return null;
}
@Override
public String getHelp() {
// TODO Auto-generated method stub
return null;
}
}
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03279 seconds