You should remove the call to doInBackground
from inside the constructor of ImageDeployer
:
public ImageDeployer(HashMap<String, String> volIDMap, HashMap<String, String> osMap) {
....
makeAConnection();
//doInBackground();
...
}
This will initialize the channel
when you create an instance of ImageDeployer
. And you can add channel
to the list of constructor arguments of OVFImageDeployer
:
public OVFImageDeployer(String VolID,String oS,String imageName, Channel channel){
this.channel = channel;
...
}
This will create an instance of OVFImageDeployer
with the channel
that is present in the ImageDeployer
instance. You need to remove these two statements from inside the doInBackground
method and pass channel
along with the other parameters while constructing an instance of OVFImageDeployer
:
@Override
protected Boolean doInBackground() throws Exception {
//ImageDeployer imageDeployer = new ImageDeployer();
//imageDeployer.makeAConnection();
...
ImageDeployer imageDeployer = new OVFImageDeployer(volID, oS, imageName, channel);
...
}
Now the client code can create an instance of ImageDeployer
and can execute doInBackground
on it:
ImageDeployer imageDeployer = new ImageDeployer();
imageDeployer.doInBackground();
With this, every time you create an instance of OVFImageDeployer
inside the doInBackground
method, you can use the same channel
which was created by the makeAConnection
method while constructing the ImageDeployer
instance.