Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] Using a container multiple times

Hi Robert,

One other thought that might be useful...

On 11/5/2010 3:09 AM, Robert Onslow wrote:
Found the problem.
I was listening for a ContainerConnectedEvent to trigger a lookup of
the service on the IRemoteServiceContainerAdapter

The trouble was that the IRemoteServiceContainerAdapter of course
listens for a ContainerConnectedEvent before initialising with the
remote server.

So when if my handler was being handled first, then there was nothing
on the IRemoteServiceContainerAdapter to find yet.

Solved by using a IRemoteServiceListener on the IRemoteServiceContainerAdapter:

container = manager.getContainerFactory().createContainer("ecf.generic.client");
ID id = IDFactory.getDefault().createID(container.getConnectNamespace(),
uri.toString());
final IRemoteServiceContainerAdapter rsc =
(IRemoteServiceContainerAdapter) ((IAdaptable)
container).getAdapter(IRemoteServiceContainerAdapter.class);
rsc.addRemoteServiceListener(new IRemoteServiceListener() {

	@Override
	public void handleServiceEvent(IRemoteServiceEvent event) {
	String[] clazzes = event.getClazzes();
	boolean quit = false;
	for (int i = 0; quit = false&&  i<  clazzes.length; i++)
		quit = clazzes[i].equals(StateProvider.class.getName());
	if (quit){
	IRemoteServiceReference ref = event.getReference();
	StateProvider provider = (StateProvider) rsc.getRemoteService(ref);
	Map<String, Object>  state = provider.provideState();
	syncBundles(state);
												}
});


I'm not sure from your code whether this is completely appropriate or not, but another option might be to use the ECF RemoteServiceTracker. In effect, what it does is create/add an IRemoteService listener...and listen for IRemoteService events...and then turn around and call addingService, etc...which you can then respond to with your code.

In any event (so to speak :), RemoteServiceTracker is also available. One advantage is that it does all it's own cleanup/removing listener on RemoteServiceTracker.close().

Again, thanks.

Scott




Back to the top