/** * This method first sends a message to the widget specified by handle to get the list of its * callbacks, then the server subscribes to each of them. The subscription is added to calls * * @param handle The widget to subscribe to * @param calls The subscription results are added to calls */ private void addWidgetCallbacksSubscription(WidgetHandle handle, Callbacks calls) { // Get all callbacks of each widget DataObject widgetCalls = getWidgetCallbacks(handle.getHostName(), handle.getPort(), handle.getId()); String error = new Error(widgetCalls).getError(); if (error != null) { if (error.equals(Error.NO_ERROR)) { Callbacks cbacks = new Callbacks(widgetCalls); // Subscribe to each callback received by the widget for (int j = 0; j < cbacks.numCallbacks(); j++) { Callback call = cbacks.getCallbackAt(j); ClientSideSubscriber css = new ClientSideSubscriber( this.getId(), this.getHostName(), this.getPort(), call.getName(), null, handle.getAttributes()); println("Server in <addWidgetCallbacksSubscription> subscribe to:" + css); Error done = subscribeTo( (Handler) this, handle.getId(), handle.getHostName(), handle.getPort(), css); // The unique id identifying the subscription is in css // call.setName(handle.getId()+"_"+call.getName()); // before call.setName(css.getSubscriptionId()); calls.addCallback(call); } } } }
/** * This method is called to subscribe to the widgets this server is interested in. It allows the * server to act as a proxy to the callbacks provided by each individual widget. This should be * called after a constructor sets the widget handles to use or after setWidgets() has been * called. * * @see #setCallbacks() */ protected Callbacks initCallbacks() { // this protects us against the Widget constructor // that calls us too early (we havent' got the widgets yet) // it's good practice anyway if (widgets == null) { return null; } Callbacks calls = new Callbacks(); // For all widgets for (int i = 0; i < widgets.size(); i++) { WidgetHandle handle = widgets.getWidgetHandleAt(i); addWidgetCallbacksSubscription(handle, calls); } calls.addCallbacks(setServerCallbacks()); return calls; }
public TourApp_122( int localport, java.lang.String userid, java.lang.String configFile, java.lang.String demoFile) { try { server = new context.arch.BaseObject(localport); port = localport; this.userid = userid; demo = new context.apps.Tour.DemoFile(demoFile); context.arch.util.XMLURLReader reader = new context.arch.util.XMLURLReader(configFile); context.arch.comm.DataObject data = reader.getParsedData(); context.arch.util.Configuration config = new context.arch.util.Configuration(data); context.arch.util.ConfigObjects interpreters = config.getInterpreterConfigurations(); if (interpreters != null) { context.arch.util.ConfigObject interpreter = (context.arch.util.ConfigObject) interpreters.getEnumeration().nextElement(); intId = interpreter.getId(); intHost = interpreter.getHost(); intPort = Integer.parseInt(interpreter.getPort()); } context.arch.util.ConfigObjects servers = config.getServerConfigurations(); if (servers != null) { for (java.util.Enumeration e = servers.getEnumeration(); e.hasMoreElements(); ) { context.arch.util.ConfigObject serverObj = (context.arch.util.ConfigObject) e.nextElement(); if (serverObj.getId().indexOf(userid) != -1) { java.lang.String serverId = serverObj.getId(); java.lang.String serverHost = serverObj.getHost(); int serverPort = Integer.parseInt(serverObj.getPort()); context.arch.comm.DataObject callbacks = server.getWidgetCallbacks(serverHost, serverPort, serverId); java.lang.String callbacksError = (new context.arch.util.Error(callbacks)).getError(); context.arch.subscriber.Callbacks calls = null; if (callbacksError.equals(Error.NO_ERROR)) { calls = new context.arch.subscriber.Callbacks(callbacks); } for (int i = 0; i < calls.numCallbacks(); i++) { context.arch.subscriber.Callback callback = calls.getCallbackAt(i); if (callback.getName().indexOf(WTourRegistration.UPDATE) != -1) { context.arch.util.Error error = server.subscribeTo( this, port, SUBSCRIBER_ID, serverHost, serverPort, serverId, callback.getName(), SUBSCRIBER_ID + Constants.SPACER + WTourRegistration.UPDATE); } else { if (callback.getName().indexOf(WTourDemo.VISIT) != -1) { context.arch.util.Error error = server.subscribeTo( this, port, SUBSCRIBER_ID, serverHost, serverPort, serverId, callback.getName(), SUBSCRIBER_ID + Constants.SPACER + WTourDemo.VISIT); } else { if (callback.getName().indexOf(WTourDemo.INTEREST) != -1) { context.arch.util.Error error = server.subscribeTo( this, port, SUBSCRIBER_ID, serverHost, serverPort, serverId, callback.getName(), SUBSCRIBER_ID + Constants.SPACER + WTourDemo.INTEREST); } else { if (callback.getName().indexOf(WTourEnd.END) != -1) { context.arch.util.Error error = server.subscribeTo( this, port, SUBSCRIBER_ID, serverHost, serverPort, serverId, callback.getName(), SUBSCRIBER_ID + Constants.SPACER + WTourEnd.END); } } } } } } } } } catch (java.net.MalformedURLException mue) { System.out.println("TourApp_122 MalformedURL: " + mue); } catch (context.arch.comm.language.DecodeException de) { System.out.println("TourApp_122 Decode: " + de); } }