/**
   * Remove from our <tt>jids</tt> map all entries that have not seen any activity (i.e. neither
   * outgoing nor incoming messags) for more than JID_INACTIVITY_TIMEOUT. Note that this method is
   * not synchronous and that it is only meant for use by the {@link #getThreadIDForAddress(String)}
   * and {@link #putJidForAddress(String, String)}
   */
  private void purgeOldJids() {
    long currentTime = System.currentTimeMillis();

    Iterator<Map.Entry<String, StoredThreadID>> entries = jids.entrySet().iterator();

    while (entries.hasNext()) {
      Map.Entry<String, StoredThreadID> entry = entries.next();
      StoredThreadID target = entry.getValue();

      if (currentTime - target.lastUpdatedTime > JID_INACTIVITY_TIMEOUT) entries.remove();
    }
  }
  /**
   * Verifies that all operation sets have the type they are declarded to have.
   *
   * @throws java.lang.Exception if a class indicated in one of the keys could not be forName()ed.
   */
  public void testOperationSetTypes() throws Exception {
    Map<String, OperationSet> supportedOperationSets =
        fixture.provider1.getSupportedOperationSets();

    // make sure that keys (which are supposed to be class names) correspond
    // what the class of the values recorded against them.
    for (Map.Entry<String, OperationSet> entry : supportedOperationSets.entrySet()) {
      String setName = entry.getKey();
      Object opSet = entry.getValue();

      assertTrue(
          opSet + " was not an instance of " + setName + " as declared",
          Class.forName(setName).isInstance(opSet));
    }
  }
  /**
   * Makes sure that conference is allocated for given <tt>room</tt>.
   *
   * @param room name of the MUC room of Jitsi Meet conference.
   * @param properties configuration properties, see {@link JitsiMeetConfig} for the list of valid
   *     properties.
   * @throws Exception if any error occurs.
   */
  private void createConference(String room, Map<String, String> properties) throws Exception {
    JitsiMeetConfig config = new JitsiMeetConfig(properties);

    JitsiMeetConference conference =
        new JitsiMeetConference(room, focusUserName, protocolProviderHandler, this, config);

    conferences.put(room, conference);

    StringBuilder options = new StringBuilder();
    for (Map.Entry<String, String> option : properties.entrySet()) {
      options.append("\n    ").append(option.getKey()).append(": ").append(option.getValue());
    }

    logger.info(
        "Created new focus for "
            + room
            + "@"
            + focusUserDomain
            + " conferences count: "
            + conferences.size()
            + " options:"
            + options.toString());

    // Send focus created event
    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
    if (eventAdmin != null) {
      eventAdmin.sendEvent(EventFactory.focusCreated(conference.getId(), conference.getRoomName()));
    }

    try {
      conference.start();
    } catch (Exception e) {
      logger.info("Exception while trying to start the conference", e);

      // stop() method is called by the conference automatically in order
      // to not release the lock on JitsiMeetConference instance and avoid
      // a deadlock. It may happen when this thread is about to call
      // conference.stop() and another thread has entered the method
      // before us. That other thread will try to call
      // FocusManager.conferenceEnded, but we're still holding the lock
      // on FocusManager instance.

      // conference.stop();

      throw e;
    }
  }
Beispiel #4
0
  /**
   * Makes sure that conference is allocated for given <tt>room</tt>.
   *
   * @param room name of the MUC room of Jitsi Meet conference.
   * @param properties configuration properties, see {@link JitsiMeetConfig} for the list of valid
   *     properties.
   * @throws Exception if any error occurs.
   */
  private void createConference(String room, Map<String, String> properties) throws Exception {
    JitsiMeetConfig config = new JitsiMeetConfig(properties);

    JitsiMeetConference conference =
        new JitsiMeetConference(room, focusUserName, protocolProviderHandler, this, config);

    conferences.put(room, conference);

    StringBuilder options = new StringBuilder();
    for (Map.Entry<String, String> option : properties.entrySet()) {
      options.append("\n    ").append(option.getKey()).append(": ").append(option.getValue());
    }

    logger.info(
        "Created new focus for "
            + room
            + "@"
            + focusUserDomain
            + " conferences count: "
            + conferences.size()
            + " options:"
            + options.toString());

    // Send focus created event
    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();
    if (eventAdmin != null) {
      eventAdmin.sendEvent(EventFactory.focusCreated(conference.getId(), conference.getRoomName()));
    }

    try {
      conference.start();
    } catch (Exception e) {
      logger.info("Exception while trying to start the conference", e);

      conference.stop();

      throw e;
    }
  }
  /**
   * Gets the <tt>contactDetails</tt> to be set on a <tt>SourceContact</tt>.
   *
   * @param entry <tt>GoogleContactsEntry</tt>
   * @return the <tt>contactDetails</tt> to be set on a <tt>SourceContact</tt>
   */
  private List<ContactDetail> getContactDetails(GoogleContactsEntry entry) {
    List<ContactDetail> ret = new LinkedList<ContactDetail>();
    List<String> homeMails = entry.getHomeMails();
    List<String> workMails = entry.getWorkMails();
    List<String> mobilePhones = entry.getMobilePhones();
    List<String> homePhones = entry.getHomePhones();
    List<String> workPhones = entry.getWorkPhones();
    Map<String, GoogleContactsEntry.IMProtocol> ims = entry.getIMAddresses();
    ContactDetail detail = null;

    for (String mail : homeMails) {
      List<Class<? extends OperationSet>> supportedOpSets =
          new ArrayList<Class<? extends OperationSet>>(1);
      // can be added as contacts
      supportedOpSets.add(OperationSetPersistentPresence.class);

      detail =
          new ContactDetail(
              mail,
              ContactDetail.Category.Email,
              new ContactDetail.SubCategory[] {ContactDetail.SubCategory.Home});
      detail.setSupportedOpSets(supportedOpSets);
      ret.add(detail);
    }
    for (String mail : workMails) {
      List<Class<? extends OperationSet>> supportedOpSets =
          new ArrayList<Class<? extends OperationSet>>(1);
      // can be added as contacts
      supportedOpSets.add(OperationSetPersistentPresence.class);

      detail =
          new ContactDetail(
              mail,
              ContactDetail.Category.Email,
              new ContactDetail.SubCategory[] {ContactDetail.SubCategory.Work});
      detail.setSupportedOpSets(supportedOpSets);
      ret.add(detail);
    }

    for (String homePhone : homePhones) {
      List<Class<? extends OperationSet>> supportedOpSets =
          new ArrayList<Class<? extends OperationSet>>(2);

      supportedOpSets.add(OperationSetBasicTelephony.class);
      // can be added as contacts
      supportedOpSets.add(OperationSetPersistentPresence.class);
      homePhone = PhoneNumberI18nService.normalize(homePhone);
      detail =
          new ContactDetail(
              homePhone,
              ContactDetail.Category.Phone,
              new ContactDetail.SubCategory[] {ContactDetail.SubCategory.Home});
      detail.setSupportedOpSets(supportedOpSets);
      ret.add(detail);
    }

    for (String workPhone : workPhones) {
      List<Class<? extends OperationSet>> supportedOpSets =
          new ArrayList<Class<? extends OperationSet>>(2);

      supportedOpSets.add(OperationSetBasicTelephony.class);
      // can be added as contacts
      supportedOpSets.add(OperationSetPersistentPresence.class);
      workPhone = PhoneNumberI18nService.normalize(workPhone);
      detail =
          new ContactDetail(
              workPhone,
              ContactDetail.Category.Phone,
              new ContactDetail.SubCategory[] {ContactDetail.SubCategory.Work});
      detail.setSupportedOpSets(supportedOpSets);
      ret.add(detail);
    }

    for (String mobilePhone : mobilePhones) {
      List<Class<? extends OperationSet>> supportedOpSets =
          new ArrayList<Class<? extends OperationSet>>(2);

      supportedOpSets.add(OperationSetBasicTelephony.class);
      // can be added as contacts
      supportedOpSets.add(OperationSetPersistentPresence.class);
      mobilePhone = PhoneNumberI18nService.normalize(mobilePhone);
      detail =
          new ContactDetail(
              mobilePhone,
              ContactDetail.Category.Phone,
              new ContactDetail.SubCategory[] {ContactDetail.SubCategory.Mobile});
      detail.setSupportedOpSets(supportedOpSets);
      ret.add(detail);
    }

    for (Map.Entry<String, GoogleContactsEntry.IMProtocol> im : ims.entrySet()) {
      if (im.getValue() != GoogleContactsEntry.IMProtocol.OTHER) {
        ContactDetail.SubCategory imSubCat;
        switch (im.getValue()) {
          case AIM:
            imSubCat = ContactDetail.SubCategory.AIM;
            break;
          case ICQ:
            imSubCat = ContactDetail.SubCategory.ICQ;
            break;
          case YAHOO:
            imSubCat = ContactDetail.SubCategory.Yahoo;
            break;
          case JABBER:
            imSubCat = ContactDetail.SubCategory.Jabber;
            break;
          case MSN:
            imSubCat = ContactDetail.SubCategory.MSN;
            break;
          case GOOGLETALK:
            imSubCat = ContactDetail.SubCategory.GoogleTalk;
            break;
          default:
            imSubCat = null;
            break;
        }

        detail =
            new ContactDetail(
                im.getKey(),
                ContactDetail.Category.InstantMessaging,
                new ContactDetail.SubCategory[] {imSubCat});

        setIMCapabilities(detail, im.getValue());

        // can be added as contacts
        detail.getSupportedOperationSets().add(OperationSetPersistentPresence.class);

        ret.add(detail);
      }
    }

    return ret;
  }