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;
import org.xmpp.packet.Presence;
/**
* <p>Manages the registration and delegation of Components.</p>
* <p/>
* <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 receiving of
* packets.
* Manages the registration and delegation of Components. 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
* receiving of packets.
*
* @author Derek DeMoro
*/
......@@ -22,8 +21,7 @@ public class ComponentManager {
private Map<String, Component> components = new ConcurrentHashMap<String, Component>();
private Map<JID, JID> presenceMap = new ConcurrentHashMap<JID, JID>();
static private ComponentManager singleton;
private final static Object LOCK = new Object();
private static ComponentManager instance = new ComponentManager();
/**
......@@ -34,16 +32,7 @@ public class ComponentManager {
* @return the singleton instance of <Code>ComponentManager</CODE>
*/
public static ComponentManager getInstance() {
// Synchronize on LOCK to ensure that we don't end up creating
// two singletons.
synchronized (LOCK) {
if (null == singleton) {
ComponentManager controller = new ComponentManager();
singleton = controller;
return controller;
}
}
return singleton;
return instance;
}
private ComponentManager() {
......
......@@ -68,21 +68,22 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
}
/**
* Handles all roster queries.
* There are two major types of queries:
* Handles all roster queries. There are two major types of queries:
*
* <ul>
* <li>Roster remove - A forced removal of items from a roster. Roster
* removals are the only roster queries allowed to
* directly affect the roster from another user.</li>
* <li>Roster management - A local user looking up or updating their
* roster.</li>
* <li>Roster remove - A forced removal of items from a roster. Roster
* removals are the only roster queries allowed to
* directly affect the roster from another user.
* </li>
* <li>Roster management - A local user looking up or updating their
* roster.
* </li>
* </ul>
*
* @param packet The update packet
* @return The reply or null if no reply
*/
public synchronized IQ handleIQ(IQ packet) throws
UnauthorizedException, PacketException {
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
try {
IQ returnPacket = null;
org.xmpp.packet.Roster roster = (org.xmpp.packet.Roster)packet;
......@@ -93,7 +94,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
if (recipientJID == null || recipientJID.getNode() == null) {
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);
}
return returnPacket;
......
......@@ -25,6 +25,8 @@ import org.xmpp.packet.*;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* Implements the presence protocol. Clients use this protocol to
......@@ -61,12 +63,6 @@ import java.util.*;
* for a presence update broadcast from the other server or tracking them
* as they are received. Requires S2S capabilities.
* </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
*
......@@ -74,7 +70,7 @@ import java.util.*;
*/
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 XMPPServer localServer;
......@@ -136,7 +132,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
*
* @param presence The presence presence to handle
*/
public synchronized void process(Presence presence) throws PacketException {
public void process(Presence presence) throws PacketException {
try {
process((Packet)presence);
}
......@@ -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.
* If the sender of the presence is local (to this server) and the target entity does not belong
* to the user's roster then update the registry of sent directed presences by the user.
* Notification method sent to this handler when a user has sent a directed
* presence to an entity. If the sender of the presence is local (to this server)
* 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 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) {
return;
}
......@@ -309,7 +306,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
if (set == null) {
// We are using a set to avoid duplicate handlers in case the user
// sends several directed presences to the same entity
set = new HashSet();
set = new CopyOnWriteArraySet();
directedPresences.put(update.getFrom().toString(), set);
}
if (Presence.Type.unavailable.equals(update.getType())) {
......@@ -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
* as if the weak reference does not exists.
* A WeakReference that redefines #equals(Object) so that the referent objects
* could be compared as if the weak reference does not exists.
*
* @author Gaston Dombiak
*/
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;
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