Example #1
0
  /**
   * If there is no variable with the specified name, then create one. This is done in
   * preinitialize() so that we can set up a type constraint that ensures that the type of the
   * variable is at least that of the input port.
   *
   * @exception IllegalActionException If the superclass throws it, or if there is no container.
   */
  public void preinitialize() throws IllegalActionException {
    super.preinitialize();

    Attribute attribute = getModifiedVariable();

    if (attribute instanceof Variable) {
      ((Variable) attribute).setTypeAtLeast(input);
    }
  }
Example #2
0
  ///////////////////////////////////////////////////////////////////
  ////                         public methods                    ////
  public void preinitialize() throws IllegalActionException {
    super.preinitialize();
    PropertyConfigurator.configure(System.getProperties());

    // if (configDir.hasToken()) {
    // String Dir = ((StringToken)configDir.getToken()).stringValue();
    // } else {
    String Dir = "c:/Cygwin/home/ellen_zh/ptII/ptolemy/actor/lib/jxta";

    // }
    // if (actorList.hasToken()) {
    // String _actorListFileName = ((StringToken)actorList.getToken()).stringValue();
    // } else {
    String _actorListFileName = "c:/Cygwin/home/ellen_zh/ptII/ptolemy/actor/lib/jxta/actors.xml";

    // }
    _properties = new Properties(System.getProperties());

    InputStream configProperties = null;

    try {
      configProperties = new FileInputStream(_CONFIG_FILE);
      _properties.load(configProperties);
    } catch (IOException e) {
      System.out.println(
          "Warning: Can't find configuration propertiees file. ' " + e.getMessage() + "'");
    } finally {
      if (configProperties != null) {
        try {
          configProperties.close();
        } catch (Throwable throwable) {
          System.out.println("Ignoring failure to close stream " + "on '" + _CONFIG_FILE + "'");
          throwable.printStackTrace();
        }
      }
    }

    PeerGroup netPeerGroup = null;

    try {
      netPeerGroup = PeerGroupFactory.newNetPeerGroup();
    } catch (PeerGroupException ex) {
      System.out.println("Error: cannot locate net peer group.\n" + ex.getMessage());
    }

    // load the peer group adv for actor exchange
    String groupAdvFileName = _properties.getProperty("GroupAdvFileName");

    if (groupAdvFileName == null) {
      System.out.println("Error: property undefined - GroupAdvFileName.\n");
    }

    PeerGroupAdvertisement groupAdv = null;

    try {
      groupAdv =
          (PeerGroupAdvertisement)
              AdvertisementFactory.newAdvertisement(
                  XML_MIME_TYPE, new FileInputStream(Dir + "/" + groupAdvFileName));
    } catch (FileNotFoundException ex) {
      System.out.println("Error: cannot find group adv file.\n" + ex.getMessage());
    } catch (IOException ex) {
      System.out.println("Error: reading group adv file.\n" + ex.getMessage());
    }

    System.out.println("peer groupAdv: " + groupAdvFileName);
    System.out.println("success before instantiate peer group");

    // instantiate the peer group for actor exchange
    try {
      _group = netPeerGroup.newGroup(groupAdv);
    } catch (PeerGroupException ex) {
      System.out.println("Error: cannot instantiate peer group.\n" + ex.getMessage());
    }

    // join the peer group for actor exchange
    // no authentication is done here
    // modeled after JoinDemo from JXTA Examples
    StructuredDocument identityInfo = null;

    try {
      AuthenticationCredential authCred = new AuthenticationCredential(_group, null, identityInfo);
      MembershipService membershipService = _group.getMembershipService();
      _authenticator = membershipService.apply(authCred);

      if (_authenticator.isReadyForJoin()) {
        _credential = membershipService.join(_authenticator);
        System.out.println("Info: join group successful.");
        _credential.getDocument(XML_MIME_TYPE).sendToStream(System.out);
      } else {
        System.out.println("Error: unable to join group.");
      }
    } catch (Exception ex) {
      System.out.println("Error: failure in authentication.\n" + ex.getMessage());
    }

    _discoveryService = _group.getDiscoveryService();
    _discoveryService.addDiscoveryListener(this);

    _resolverService = _group.getResolverService();

    // register this as a query handler
    _resolverService.registerHandler(_ACTOR_QUERY_HANDLER_NAME, this);

    // construct the actor query message
    StringBuffer queryTextBuffer = new StringBuffer("<?xml version=\"1.0\"?>\n\n");
    queryTextBuffer = queryTextBuffer.append("<ActorQuery>\n");
    queryTextBuffer = queryTextBuffer.append("What actors do you have?");
    queryTextBuffer = queryTextBuffer.append("\n</ActorQuery>\n");
    _actorQueryMessage =
        new ResolverQuery(_ACTOR_QUERY_HANDLER_NAME, null, null, queryTextBuffer.toString(), 0);
    _actorQueryMessage.setSrc(_group.getPeerID().toString());

    // construct the actor query response message
    if (_actorListFileName != null) {
      StringBuffer actorListText = new StringBuffer();

      BufferedReader fileReader = null;
      try {
        fileReader = new BufferedReader(new FileReader(_actorListFileName));
        String newline = System.getProperty("line.separator");

        while (true) {
          String line = fileReader.readLine();

          if (line == null) {
            break;
          }

          actorListText = actorListText.append(line);
          actorListText = actorListText.append(newline);
        }

        _actorQueryResponse =
            new ResolverResponse(_ACTOR_QUERY_HANDLER_NAME, null, 0, actorListText.toString());
      } catch (IOException ex) {
        System.out.println("Warning: error reading actor list file.\n" + ex.getMessage());
      } finally {
        if (fileReader != null) {
          try {
            fileReader.close();
          } catch (Exception ex) {
            System.out.println("Failed to close: " + ex.getMessage());
          }
        }
      }
    }
  }
Example #3
0
 /** Initialize the actor by getting the input and output parameters from the soap service. */
 public void preinitialize() throws IllegalActionException {
   super.preinitialize();
 }