Set<Bundle> copyOfBundles = new HashSet<Bundle>(bundlesToQuiesce);
Timer timer = new Timer();
//Create callback objects for all participants
for( ServiceReference sr : serviceRefs ) {
QuiesceParticipant participant = (QuiesceParticipant) bundleContext.getService(sr);
participants.add(participant);
callbacks.add(new QuiesceCallbackImpl(copyOfBundles, callbacks, timer));
}
//Quiesce each participant and wait for an interrupt from a callback
//object when all are quiesced, or the timeout to be reached
for( int i=0; i<participants.size(); i++ ) {
QuiesceParticipant participant = participants.get(i);
QuiesceCallbackImpl callback = callbacks.get(i);
List<Bundle> participantBundles = new ArrayList<Bundle>();
//deep copy
for (Bundle b : copyOfBundles) {
participantBundles.add(b);
}
participant.quiesce(callback, participantBundles);
}
timer.schedule(new TimerTask() {
@Override
public void run() {