/** * Remove records telling what entity caps node a contact has. * * @param contact the contact */ public void removeContactCapsNode(Contact contact) { Caps caps = null; String lastRemovedJid = null; Iterator<String> iter = userCaps.keySet().iterator(); while (iter.hasNext()) { String jid = iter.next(); if (StringUtils.parseBareAddress(jid).equals(contact.getAddress())) { caps = userCaps.get(jid); lastRemovedJid = jid; iter.remove(); } } // fire only for the last one, at the end the event out // of the protocol will be one and for the contact if (caps != null) { UserCapsNodeListener[] listeners; synchronized (userCapsNodeListeners) { listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS); } if (listeners.length != 0) { String nodeVer = caps.getNodeVer(); for (UserCapsNodeListener listener : listeners) listener.userCapsNodeRemoved(lastRemovedJid, nodeVer, false); } } }
/** * Add a record telling what entity caps node a user has. * * @param user the user (Full JID) * @param node the node (of the caps packet extension) * @param hash the hashing algorithm used to calculate <tt>ver</tt> * @param ver the version (of the caps packet extension) * @param ext the ext (of the caps packet extension) * @param online indicates if the user is online */ private void addUserCapsNode( String user, String node, String hash, String ver, String ext, boolean online) { if ((user != null) && (node != null) && (hash != null) && (ver != null)) { Caps caps = userCaps.get(user); if ((caps == null) || !caps.node.equals(node) || !caps.hash.equals(hash) || !caps.ver.equals(ver)) { caps = new Caps(node, hash, ver, ext); userCaps.put(user, caps); } else return; // Fire userCapsNodeAdded. UserCapsNodeListener[] listeners; synchronized (userCapsNodeListeners) { listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS); } if (listeners.length != 0) { String nodeVer = caps.getNodeVer(); for (UserCapsNodeListener listener : listeners) listener.userCapsNodeAdded(user, nodeVer, online); } } }
public static ServiceReferenceDTO[] newArrayServiceReferenceDTO( ServiceReference<?>[] references) { final int length = (references == null) ? 0 : references.length; List<ServiceReferenceDTO> refDTOs = new ArrayList<ServiceReferenceDTO>(length); for (int i = 0; i < length; i++) { ServiceReferenceDTO dto = getServiceReferenceDTO(references[i]); if (dto != null) { refDTOs.add(dto); } } return refDTOs.toArray(new ServiceReferenceDTO[refDTOs.size()]); }
public void testBasic() throws BundleException, InvalidSyntaxException, InterruptedException { // get the system region Region systemRegion = digraph.getRegion(0); // create a disconnected test region Region testRegion = digraph.createRegion(getName()); List<Bundle> bundles = new ArrayList<Bundle>(); // Install all test bundles Bundle pp1, cp2, sc1; bundles.add(pp1 = bundleInstaller.installBundle(PP1, testRegion)); // should be able to start pp1 because it depends on nothing pp1.start(); // do a sanity check that we have no services available in the isolated region assertNull("Found some services.", pp1.getBundleContext().getAllServiceReferences(null, null)); assertEquals("Found extra bundles in region", 1, pp1.getBundleContext().getBundles().length); pp1.stop(); bundles.add(bundleInstaller.installBundle(SP1, testRegion)); bundles.add(bundleInstaller.installBundle(CP1, testRegion)); bundles.add(bundleInstaller.installBundle(PP2, testRegion)); bundles.add(bundleInstaller.installBundle(SP2, testRegion)); bundles.add(cp2 = bundleInstaller.installBundle(CP2, testRegion)); bundles.add(bundleInstaller.installBundle(PC1, testRegion)); bundles.add(bundleInstaller.installBundle(BC1, testRegion)); bundles.add(sc1 = bundleInstaller.installBundle(SC1, testRegion)); bundles.add(bundleInstaller.installBundle(CC1, testRegion)); // Import the system bundle from the systemRegion digraph.connect(testRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_BUNDLE_NAMESPACE, "(id=0)").build(), systemRegion); // must import Boolean services into systemRegion to test digraph.connect(systemRegion, digraph.createRegionFilterBuilder().allow(RegionFilter.VISIBLE_SERVICE_NAMESPACE, "(objectClass=java.lang.Boolean)").build(), testRegion); bundleInstaller.resolveBundles(bundles.toArray(new Bundle[bundles.size()])); for (Bundle bundle : bundles) { assertEquals("Bundle did not resolve: " + bundle.getSymbolicName(), Bundle.RESOLVED, bundle.getState()); bundle.start(); } BundleContext context = getContext(); ServiceTracker<Boolean, Boolean> cp2Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + cp2.getBundleId() + "))"), null); ServiceTracker<Boolean, Boolean> sc1Tracker = new ServiceTracker<Boolean, Boolean>(context, context.createFilter("(&(objectClass=java.lang.Boolean)(bundle.id=" + sc1.getBundleId() + "))"), null); cp2Tracker.open(); sc1Tracker.open(); assertNotNull("The cp2 bundle never found the service.", cp2Tracker.waitForService(2000)); assertNotNull("The sc1 bundle never found the service.", sc1Tracker.waitForService(2000)); cp2Tracker.close(); sc1Tracker.close(); }
public static BundleWiringDTO[] newArrayBundleWiringDTO(BundleRevisions revisions) { if (revisions == null) { return null; } List<BundleRevision> revs = revisions.getRevisions(); final int size = revs.size(); List<BundleWiringDTO> dtos = new ArrayList<BundleWiringDTO>(size); for (int i = 0; i < size; i++) { BundleWiring wiring = revs.get(i).getWiring(); if (wiring != null) { dtos.add( new DTOBuilder().getBundleWiringDTO(wiring)); // use new DTOBuilder for each wiring dto } } return dtos.toArray(new BundleWiringDTO[dtos.size()]); }
/** * Remove a record telling what entity caps node a user has. * * @param user the user (Full JID) */ public void removeUserCapsNode(String user) { Caps caps = userCaps.remove(user); // Fire userCapsNodeRemoved. if (caps != null) { UserCapsNodeListener[] listeners; synchronized (userCapsNodeListeners) { listeners = userCapsNodeListeners.toArray(NO_USER_CAPS_NODE_LISTENERS); } if (listeners.length != 0) { String nodeVer = caps.getNodeVer(); for (UserCapsNodeListener listener : listeners) listener.userCapsNodeRemoved(user, nodeVer, false); } } }
/** * Gets the <tt>Content</tt>s of this <tt>Conference</tt>. * * @return the <tt>Content</tt>s of this <tt>Conference</tt> */ public Content[] getContents() { synchronized (contents) { return contents.toArray(new Content[contents.size()]); } }