Ejemplo n.º 1
0
  /**
   * 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);
        }
      }
    }
  }
Ejemplo n.º 2
0
 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);
   }
 }