Commit ff49ae5f authored by Matt Tucker's avatar Matt Tucker Committed by matt

Code cleanup, removed synchronization.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@679 b35dd754-fafc-0310-a699-88a17e54d16e
parent ea4e73d1
...@@ -9,11 +9,10 @@ import org.xmpp.packet.JID; ...@@ -9,11 +9,10 @@ import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
/** /**
* <p>Manages the registration and delegation of Components.</p> * Manages the registration and delegation of Components. The ComponentManager
* <p/> * is responsible for managing registration and delegation of <code>Components</code>,
* <p>The ComponentManager is responsible for managing registration and delegation of <code>Components</code>, * as well as offering a facade around basic server functionallity such as sending and
* as well as offering a facade around basic server functionallity such as sending and receiving of * receiving of packets.
* packets.
* *
* @author Derek DeMoro * @author Derek DeMoro
*/ */
...@@ -22,8 +21,7 @@ public class ComponentManager { ...@@ -22,8 +21,7 @@ public class ComponentManager {
private Map<String, Component> components = new ConcurrentHashMap<String, Component>(); private Map<String, Component> components = new ConcurrentHashMap<String, Component>();
private Map<JID, JID> presenceMap = new ConcurrentHashMap<JID, JID>(); private Map<JID, JID> presenceMap = new ConcurrentHashMap<JID, JID>();
static private ComponentManager singleton; private static ComponentManager instance = new ComponentManager();
private final static Object LOCK = new Object();
/** /**
...@@ -34,16 +32,7 @@ public class ComponentManager { ...@@ -34,16 +32,7 @@ public class ComponentManager {
* @return the singleton instance of <Code>ComponentManager</CODE> * @return the singleton instance of <Code>ComponentManager</CODE>
*/ */
public static ComponentManager getInstance() { public static ComponentManager getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating return instance;
// two singletons.
synchronized (LOCK) {
if (null == singleton) {
ComponentManager controller = new ComponentManager();
singleton = controller;
return controller;
}
}
return singleton;
} }
private ComponentManager() { private ComponentManager() {
......
...@@ -68,21 +68,22 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -68,21 +68,22 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
} }
/** /**
* Handles all roster queries. * Handles all roster queries. There are two major types of queries:
* There are two major types of queries: *
* <ul> * <ul>
* <li>Roster remove - A forced removal of items from a roster. Roster * <li>Roster remove - A forced removal of items from a roster. Roster
* removals are the only roster queries allowed to * removals are the only roster queries allowed to
* directly affect the roster from another user.</li> * directly affect the roster from another user.
* </li>
* <li>Roster management - A local user looking up or updating their * <li>Roster management - A local user looking up or updating their
* roster.</li> * roster.
* </li>
* </ul> * </ul>
* *
* @param packet The update packet * @param packet The update packet
* @return The reply or null if no reply * @return The reply or null if no reply
*/ */
public synchronized IQ handleIQ(IQ packet) throws public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
UnauthorizedException, PacketException {
try { try {
IQ returnPacket = null; IQ returnPacket = null;
org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet; org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet;
...@@ -93,7 +94,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -93,7 +94,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
if (recipientJID == null || recipientJID.getNode() == null) { if (recipientJID == null || recipientJID.getNode() == null) {
returnPacket = manageRoster(roster); returnPacket = manageRoster(roster);
} }
else { // The packet must be a roster removal from a foreign domain user // The packet must be a roster removal from a foreign domain user.
else {
removeRosterItem(roster); removeRosterItem(roster);
} }
return returnPacket; return returnPacket;
......
...@@ -25,6 +25,8 @@ import org.xmpp.packet.*; ...@@ -25,6 +25,8 @@ import org.xmpp.packet.*;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
/** /**
* Implements the presence protocol. Clients use this protocol to * Implements the presence protocol. Clients use this protocol to
...@@ -61,12 +63,6 @@ import java.util.*; ...@@ -61,12 +63,6 @@ import java.util.*;
* for a presence update broadcast from the other server or tracking them * for a presence update broadcast from the other server or tracking them
* as they are received. Requires S2S capabilities. * as they are received. Requires S2S capabilities.
* </ul> * </ul>
* <p/>
* <h2>Warning</h2>
* There should be a way of determining whether a session has
* authorization to access this feature. I'm not sure it is a good
* idea to do authorization in each handler. It would be nice if
* the framework could assert authorization policies across channels.
* *
* @author Iain Shigeoka * @author Iain Shigeoka
* *
...@@ -74,7 +70,7 @@ import java.util.*; ...@@ -74,7 +70,7 @@ import java.util.*;
*/ */
public class PresenceUpdateHandler extends BasicModule implements ChannelHandler { public class PresenceUpdateHandler extends BasicModule implements ChannelHandler {
private Map<String, Set> directedPresences = new HashMap<String, Set>(); private Map<String, Set> directedPresences = new ConcurrentHashMap<String, Set>();
private RosterManager rosterManager; private RosterManager rosterManager;
private XMPPServer localServer; private XMPPServer localServer;
...@@ -136,7 +132,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -136,7 +132,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
* *
* @param presence The presence presence to handle * @param presence The presence presence to handle
*/ */
public synchronized void process(Presence presence) throws PacketException { public void process(Presence presence) throws PacketException {
try { try {
process((Packet)presence); process((Packet)presence);
} }
...@@ -284,14 +280,15 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -284,14 +280,15 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
} }
/** /**
* Notification method sent to this handler when a user has sent a directed presence to an entity. * Notification method sent to this handler when a user has sent a directed
* If the sender of the presence is local (to this server) and the target entity does not belong * presence to an entity. If the sender of the presence is local (to this server)
* to the user's roster then update the registry of sent directed presences by the user. * and the target entity does not belong to the user's roster then update the
* registry of sent directed presences by the user.
* *
* @param update the directed Presence sent by the user to an entity. * @param update the directed Presence sent by the user to an entity.
* @param handler the handler that routed the presence to the entity. * @param handler the handler that routed the presence to the entity.
*/ */
public synchronized void directedPresenceSent(Presence update, ChannelHandler handler) { public void directedPresenceSent(Presence update, ChannelHandler handler) {
if (update.getFrom() == null) { if (update.getFrom() == null) {
return; return;
} }
...@@ -309,7 +306,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -309,7 +306,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
if (set == null) { if (set == null) {
// We are using a set to avoid duplicate handlers in case the user // We are using a set to avoid duplicate handlers in case the user
// sends several directed presences to the same entity // sends several directed presences to the same entity
set = new HashSet(); set = new CopyOnWriteArraySet();
directedPresences.put(update.getFrom().toString(), set); directedPresences.put(update.getFrom().toString(), set);
} }
if (Presence.Type.unavailable.equals(update.getType())) { if (Presence.Type.unavailable.equals(update.getType())) {
...@@ -391,14 +388,17 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -391,14 +388,17 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
} }
/** /**
* A WeakReference that redefines #equals(Object) so that the referent objects could be compared * A WeakReference that redefines #equals(Object) so that the referent objects
* as if the weak reference does not exists. * could be compared as if the weak reference does not exists.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
private class HandlerWeakReference extends WeakReference { private class HandlerWeakReference extends WeakReference {
//We need to store the hash code separately since the referent
//could be removed by the GC. /**
* We need to store the hash code separately since the referent
* could be removed by the GC.
*/
private int hash; private int hash;
public HandlerWeakReference(Object referent) { public HandlerWeakReference(Object referent) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment