예제 #1
0
  /**
   * Deletes the session agent account, frees all resources and disconnects the XMPP connection.
   *
   * @throws org.jivesoftware.smack.XMPPException
   */
  public void shutdown() throws XMPPException {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection);

    // ServiceDiscovery (feature) http://rn.inf.tu-dresden.de/mobilis
    try {
      sdm.removeFeature(MobilisManager.discoNamespace);
    } catch (Exception e) {
      MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " + e.getMessage());
    }

    // ServiceDiscovery (info+items) http://rn.inf.tu-dresden.de/mobilis#services
    try {
      sdm.removeNodeInformationProvider(MobilisManager.discoServicesNode);
    } catch (Exception e) {
      MobilisManager.getLogger()
          .warning(
              "Problem with NodeInformationProvider: "
                  + MobilisManager.discoServicesNode
                  + " ("
                  + getIdent()
                  + ") "
                  + e.getMessage());
    }

    for (MobilisService service : mServices) {
      try {
        sdm.removeNodeInformationProvider(service.getNode());
        service.shutdown();
      } catch (Exception e) {
        // TODO Auto-generated catch block
      }
    }

    if ((mConnection != null) && mConnection.isConnected()) {
      mConnection.removeConnectionListener(this);
      mConnection.disconnect();
    }
    mConnection = null;

    // logging
    MobilisManager.getLogger().info("Mobilis Agent (" + getIdent() + ") shut down.");
  }
예제 #2
0
  public void startup() throws XMPPException {
    String host;
    Integer port;
    String service;

    synchronized (mDefaultSettings) {
      host = (String) mDefaultSettings.get("host");
      port = Integer.parseInt((String) mDefaultSettings.get("port"));
      service = (String) mDefaultSettings.get("service");
    }

    ConnectionConfiguration connConfig = new ConnectionConfiguration(host, port, service);
    mConnection = new XMPPConnection(connConfig);
    mConnection.connect();

    String password = null;
    String resource = null;

    synchronized (mDefaultSettings) {
      mJid = mDefaultSettings.get("username") + "@" + mDefaultSettings.get("service");
      password = (String) mDefaultSettings.get("password");
      resource = (String) mDefaultSettings.get("resource");
    }

    mConnection.login(mJid, password, resource);
    mConnection.addConnectionListener(this);

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mConnection);

    // Set on every established connection that this client supports the Mobilis
    // protocol. This information will be used when another client tries to
    // discover whether this client supports Mobilis or not.
    try {
      sdm.addFeature(MobilisManager.discoNamespace);
    } catch (Exception e) {
      MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " + e.getMessage());
    }

    synchronized (mServices) {
      for (MobilisService ms : mServices) {
        try {
          ms.startup();
          sdm.setNodeInformationProvider(ms.getNode(), ms);
        } catch (Exception e) {
          MobilisManager.getLogger()
              .warning(
                  "Couldn't startup Mobilis Service ("
                      + ms.getIdent()
                      + ") because of "
                      + e.getClass().getName()
                      + ": "
                      + e.getMessage());
        }
      }
    }

    // Set the NodeInformationProvider that will provide information about the
    // offered services whenever a disco request is received
    try {
      sdm.setNodeInformationProvider(MobilisManager.discoServicesNode, this);
    } catch (Exception e) {
      MobilisManager.getLogger()
          .warning(
              "Problem with NodeInformationProvider: "
                  + MobilisManager.discoServicesNode
                  + " ("
                  + getIdent()
                  + ") "
                  + e.getMessage());
    }

    // try {
    //	String entityID = mJid;
    //	DiscoverItems discoverItems = new DiscoverItems();
    //	Item item = new Item(entityID);
    //	item.setAction(Item.UPDATE_ACTION);
    //	item.setName("Mobilis Agent");
    //	item.setNode(null);
    //	discoverItems.addItem(item);
    //	sdm.publishItems(entityID, discoverItems);
    // } catch (Exception e) {
    //	MobilisManager.getLogger().warning("Problem with ServiceDiscoveryManager: " +
    // e.getMessage());
    // }

    // logging
    MobilisManager.getLogger().info("Mobilis Agent (" + getIdent() + ") started up.");
  }