コード例 #1
0
ファイル: Server.java プロジェクト: hlambertOld/ctk
  /**
   * This method is called to aggregate the list of constant attributes that the widgets relevant to
   * this server provide. This should be called after a constructor sets the widget handles to use
   * or after setWidgets() has been called.
   *
   * @return AttributeNameValues the server constant attributes
   */
  protected Attributes initConstantAttributes() {
    // 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;
    }

    Attributes atts = new Attributes();
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);

      DataObject widgetAtts =
          getWidgetConstantAttributes(handle.getHostName(), handle.getPort(), handle.getId());
      String error = new Error(widgetAtts).getError();
      if (error != null) {
        if (error.equals(Error.NO_ERROR)) {
          Attributes wAtts = new Attributes(widgetAtts);
          for (int j = 0; j < wAtts.numAttributes(); j++) {
            AttributeNameValue wAtt = (AttributeNameValue) wAtts.getAttributeAt(j);
            if (atts.getAttributeNameValue(wAtt.getName()) == null) {
              atts.addAttributeNameValue(wAtt);
            }
          }
        }
      }
    }

    atts.addAttributes(setServerConstantAttributes());

    return atts;
  }
コード例 #2
0
ファイル: Server.java プロジェクト: hlambertOld/ctk
  /**
   * 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);
        }
      }
    }
  }
コード例 #3
0
ファイル: Server.java プロジェクト: hlambertOld/ctk
  /**
   * This method is called to aggregate the list of services that the widgets relevant to this
   * widget provide. This allows the server to act as a proxy to the individual widgets' services.
   * This should be called after a constructor sets the widget handles to use or after setWidgets()
   * has been called.
   *
   * @return the server services
   */
  protected Services initServices() {
    if (widgets == null) {
      return null;
    }

    Services services = new Services();
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);
      DataObject widgetServices =
          getWidgetServices(handle.getHostName(), handle.getPort(), handle.getId());
      String error = new Error(widgetServices).getError();
      if (error != null) {
        if (error.equals(Error.NO_ERROR)) {
          ServiceDescriptions wServices = new ServiceDescriptions(widgetServices);
          for (int j = 0; j < wServices.numServiceDescriptions(); j++) {
            ServiceDescription desc = wServices.getServiceDescriptionAt(j);
            services.addService(
                new InheritedService(
                    this,
                    getId(),
                    desc.getName(),
                    desc.getFunctionDescriptions(),
                    handle.getHostName(),
                    Integer.toString(handle.getPort()),
                    handle.getId()));
          }
        }
      }
    }
    services.addServices(setServerServices());

    return services;
  }