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

Comment and formatting fixes.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@39 b35dd754-fafc-0310-a699-88a17e54d16e
parent e6292c62
/** /**
* DbAuthToken.java * $RCSfile$
* November 17, 2000 * $Revision$
* $Date$
* *
* Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved. * Copyright (C) 2004 Jive Software. All rights reserved.
* *
* This software is the proprietary information of CoolServlets, Inc. * This software is published under the terms of the GNU Public License (GPL),
* Use is subject to license terms. * a copy of which is included in this distribution.
*/ */
package org.jivesoftware.messenger.auth.spi; package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.messenger.auth.AuthToken; import org.jivesoftware.messenger.auth.AuthToken;
......
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
* $Revision$ * $Revision$
* $Date$ * $Date$
* *
* Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved. * Copyright (C) 2004 Jive Software. All rights reserved.
* *
* This software is the proprietary information of CoolServlets, Inc. * This software is published under the terms of the GNU Public License (GPL),
* Use is subject to license terms. * a copy of which is included in this distribution.
*/ */
package org.jivesoftware.messenger.auth.spi; package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
......
...@@ -15,8 +15,8 @@ import org.jivesoftware.messenger.auth.AuthProvider; ...@@ -15,8 +15,8 @@ import org.jivesoftware.messenger.auth.AuthProvider;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
/** /**
* <p>Implementation of auth provider interface for LDAP * Implementation of auth provider interface for LDAP
* authentication service plug-in.</p> * authentication service plug-in.
* *
* @author Jim Berrettini * @author Jim Berrettini
*/ */
......
...@@ -29,15 +29,16 @@ import javax.naming.NamingEnumeration; ...@@ -29,15 +29,16 @@ import javax.naming.NamingEnumeration;
import javax.naming.directory.*; import javax.naming.directory.*;
/** /**
* <p>LDAP implementation of the UserInfoProvider interface.</p> * LDAP implementation of the UserInfoProvider interface. The LdapUserIDProvider
* <p>The LdapUserIDProvider can operate in two modes -- in the pure LDAP mode, all user data is stored in the LDAP * can operate in two modes -- in the pure LDAP mode, all user data is stored in
* store. This mode generally requires modifications to the LDAP schema to accommodate data that Messenger needs.</p> * the LDAP store. This mode generally requires modifications to the LDAP schema
* <p>In the mixed mode, data that Messenger needs is stored locally.</p> * to accommodate data that Messenger needs. In the mixed mode, data that Messenger
* needs is stored locally.
* *
* @author Jim Berrettini * @author Jim Berrettini
*/ */
public class LdapUserInfoProvider implements UserInfoProvider { public class LdapUserInfoProvider implements UserInfoProvider {
private LdapManager manager;
private static final String LOAD_USER_BY_ID = private static final String LOAD_USER_BY_ID =
"SELECT name, nameVisible, email, emailVisible, " + "SELECT name, nameVisible, email, emailVisible, " +
"creationDate, modificationDate FROM jiveUser WHERE userID=?"; "creationDate, modificationDate FROM jiveUser WHERE userID=?";
...@@ -50,6 +51,8 @@ public class LdapUserInfoProvider implements UserInfoProvider { ...@@ -50,6 +51,8 @@ public class LdapUserInfoProvider implements UserInfoProvider {
"emailVisible=?, creationDate=?, modificationDate=? WHERE " + "emailVisible=?, creationDate=?, modificationDate=? WHERE " +
"userID=?"; "userID=?";
private LdapManager manager;
/** /**
* Constructor initializes the internal LdapManager instance. * Constructor initializes the internal LdapManager instance.
*/ */
...@@ -112,22 +115,10 @@ public class LdapUserInfoProvider implements UserInfoProvider { ...@@ -112,22 +115,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
throw new UnauthorizedException(); throw new UnauthorizedException();
} }
finally { finally {
try { try { if (pstmt != null) pstmt.close(); }
if (pstmt != null) { catch (Exception e) { Log.error(e); }
pstmt.close(); try { if (con != null) con.close(); }
} catch (Exception e) { Log.error(e); }
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
} }
...@@ -242,22 +233,10 @@ public class LdapUserInfoProvider implements UserInfoProvider { ...@@ -242,22 +233,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
+ id + " could not be loaded from the database."); + id + " could not be loaded from the database.");
} }
finally { finally {
try { try { if (pstmt != null) pstmt.close(); }
if (pstmt != null) { catch (Exception e) { Log.error(e); }
pstmt.close(); try { if (con != null) con.close(); }
} catch (Exception e) { Log.error(e); }
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
return userInfo; return userInfo;
} }
...@@ -273,7 +252,6 @@ public class LdapUserInfoProvider implements UserInfoProvider { ...@@ -273,7 +252,6 @@ public class LdapUserInfoProvider implements UserInfoProvider {
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
Date now = new Date(); Date now = new Date();
try { try {
// Add the user record in jiveUser // Add the user record in jiveUser
pstmt = con.prepareStatement(INSERT_USER); pstmt = con.prepareStatement(INSERT_USER);
pstmt.setLong(1, id); pstmt.setLong(1, id);
...@@ -290,22 +268,10 @@ public class LdapUserInfoProvider implements UserInfoProvider { ...@@ -290,22 +268,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e); Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
} }
finally { finally {
try { try { if (pstmt != null) pstmt.close(); }
if (pstmt != null) { catch (Exception e) { Log.error(e); }
pstmt.close(); try { if (con != null) con.close(); }
} catch (Exception e) { Log.error(e); }
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
return new BasicUserInfo(id, return new BasicUserInfo(id,
"", // name "", // name
......
...@@ -10,16 +10,12 @@ ...@@ -10,16 +10,12 @@
*/ */
package org.jivesoftware.messenger.spi; package org.jivesoftware.messenger.spi;
import org.jivesoftware.util.Cache;
import org.jivesoftware.util.CacheFactory;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.container.Container; import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.messenger.container.ModuleContext; import org.jivesoftware.messenger.container.ModuleContext;
import org.jivesoftware.messenger.container.TrackInfo; import org.jivesoftware.messenger.container.TrackInfo;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.Cache; import org.jivesoftware.util.Cache;
import org.jivesoftware.util.*;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.chatbot.ChatbotManager; import org.jivesoftware.messenger.chatbot.ChatbotManager;
...@@ -73,10 +69,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -73,10 +69,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// create caches - no size limit and never expire for presence caches // create caches - no size limit and never expire for presence caches
long HOUR = JiveConstants.HOUR; long HOUR = JiveConstants.HOUR;
onlineGuestCache = CacheFactory.createCache("Online Guests", -1, -1); onlineGuestCache = new DefaultCache("Online Guests", -1, -1);
onlineUserCache = CacheFactory.createCache("Online Users", -1, -1); onlineUserCache = new DefaultCache("Online Users", -1, -1);
foreignUserCache = CacheFactory.createCache("Foreign Users", foreignUserCache = new DefaultCache("Foreign Users", foreignCacheSize, HOUR);
foreignCacheSize, HOUR);
} }
public boolean isAvailable(User user) throws UnauthorizedException { public boolean isAvailable(User user) throws UnauthorizedException {
......
...@@ -10,9 +10,6 @@ ...@@ -10,9 +10,6 @@
*/ */
package org.jivesoftware.util; package org.jivesoftware.util;
import org.jivesoftware.util.*;
import org.jivesoftware.util.LinkedList;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
...@@ -27,14 +24,15 @@ import java.util.*; ...@@ -27,14 +24,15 @@ import java.util.*;
* they were originally added to cache. When objects are added to cache, they * they were originally added to cache. When objects are added to cache, they
* are first wrapped by a CacheObject which maintains the following pieces * are first wrapped by a CacheObject which maintains the following pieces
* of information:<ul> * of information:<ul>
*
* <li> The size of the object (in bytes). * <li> The size of the object (in bytes).
* <li> A pointer to the node in the linked list that maintains accessed * <li> A pointer to the node in the linked list that maintains accessed
* order for the object. Keeping a reference to the node lets us avoid * order for the object. Keeping a reference to the node lets us avoid
* linear scans of the linked list. * linear scans of the linked list.
* <li> A pointer to the node in the linked list that maintains the age * <li> A pointer to the node in the linked list that maintains the age
* of the object in cache. Keeping a reference to the node lets us avoid * of the object in cache. Keeping a reference to the node lets us avoid
* linear scans of the linked list.</ul> * linear scans of the linked list.</ul><p>
* <p/> *
* To get an object from cache, a hash lookup is performed to get a reference * To get an object from cache, a hash lookup is performed to get a reference
* to the CacheObject that wraps the real object we are looking for. * to the CacheObject that wraps the real object we are looking for.
* The object is subsequently moved to the front of the accessed linked list * The object is subsequently moved to the front of the accessed linked list
...@@ -81,7 +79,7 @@ public class DefaultCache implements Cache { ...@@ -81,7 +79,7 @@ public class DefaultCache implements Cache {
* Maintain the number of cache hits and misses. A cache hit occurs every * Maintain the number of cache hits and misses. A cache hit occurs every
* time the get method is called and the cache contains the requested * time the get method is called and the cache contains the requested
* object. A cache miss represents the opposite occurence.<p> * object. A cache miss represents the opposite occurence.<p>
* <p/> *
* Keeping track of cache hits and misses lets one measure how efficient * Keeping track of cache hits and misses lets one measure how efficient
* the cache is; the higher the percentage of hits, the more efficient. * the cache is; the higher the percentage of hits, the more efficient.
*/ */
...@@ -102,12 +100,12 @@ public class DefaultCache implements Cache { ...@@ -102,12 +100,12 @@ public class DefaultCache implements Cache {
* @param maxLifetime the maximum amount of time objects can exist in * @param maxLifetime the maximum amount of time objects can exist in
* cache before being deleted. -1 means objects never expire. * cache before being deleted. -1 means objects never expire.
*/ */
protected DefaultCache(String name, int maxSize, long maxLifetime) { public DefaultCache(String name, int maxSize, long maxLifetime) {
this.name = name; this.name = name;
this.maxCacheSize = maxSize; this.maxCacheSize = maxSize;
this.maxLifetime = maxLifetime; this.maxLifetime = maxLifetime;
// Our primary data structure is a hash map. The default capacity of 11 // Our primary data structure is a HashMap. The default capacity of 11
// is too small in almost all cases, so we set it bigger. // is too small in almost all cases, so we set it bigger.
map = new HashMap(103); map = new HashMap(103);
...@@ -328,16 +326,6 @@ public class DefaultCache implements Cache { ...@@ -328,16 +326,6 @@ public class DefaultCache implements Cache {
if (object instanceof Cacheable) { if (object instanceof Cacheable) {
return ((Cacheable)object).getCachedSize(); return ((Cacheable)object).getCachedSize();
} }
// Coherence puts DataInputStream objects in cache.
else if (object instanceof DataInputStream) {
int size = 1;
try {
size = ((DataInputStream)object).available();
}
catch (IOException ioe) {
}
return size;
}
// Check for other common types of objects put into cache. // Check for other common types of objects put into cache.
else if (object instanceof Long) { else if (object instanceof Long) {
return CacheSizes.sizeOfLong(); return CacheSizes.sizeOfLong();
...@@ -392,7 +380,7 @@ public class DefaultCache implements Cache { ...@@ -392,7 +380,7 @@ public class DefaultCache implements Cache {
// Determine the expireTime, which is the moment in time that elements // Determine the expireTime, which is the moment in time that elements
// should expire from cache. Then, we can do an easy to check to see // should expire from cache. Then, we can do an easy to check to see
// if the expire time is greater than the expire time. // if the expire time is greater than the expire time.
long expireTime = CacheFactory.currentTime - maxLifetime; long expireTime = System.currentTimeMillis() - maxLifetime;
while (expireTime > node.timestamp) { while (expireTime > node.timestamp) {
// Remove the object // Remove the object
......
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