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
* November 17, 2000
* $RCSfile$
* $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.
* Use is subject to license terms.
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.messenger.auth.AuthToken;
......
......@@ -3,11 +3,12 @@
* $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.
* Use is subject to license terms.
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.auth.spi;
import org.jivesoftware.database.DbConnectionManager;
......
......@@ -15,8 +15,8 @@ import org.jivesoftware.messenger.auth.AuthProvider;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* <p>Implementation of auth provider interface for LDAP
* authentication service plug-in.</p>
* Implementation of auth provider interface for LDAP
* authentication service plug-in.
*
* @author Jim Berrettini
*/
......
......@@ -29,26 +29,29 @@ import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
/**
* <p>LDAP implementation of the UserInfoProvider interface.</p>
* <p>The LdapUserIDProvider can operate in two modes -- in the pure LDAP mode, all user data is stored in the LDAP
* store. This mode generally requires modifications to the LDAP schema to accommodate data that Messenger needs.</p>
* <p>In the mixed mode, data that Messenger needs is stored locally.</p>
* LDAP implementation of the UserInfoProvider interface. The LdapUserIDProvider
* can operate in two modes -- in the pure LDAP mode, all user data is stored in
* the LDAP store. This mode generally requires modifications to the LDAP schema
* to accommodate data that Messenger needs. In the mixed mode, data that Messenger
* needs is stored locally.
*
* @author Jim Berrettini
*/
public class LdapUserInfoProvider implements UserInfoProvider {
private LdapManager manager;
private static final String LOAD_USER_BY_ID =
"SELECT name, nameVisible, email, emailVisible, " +
"creationDate, modificationDate FROM jiveUser WHERE userID=?";
"SELECT name, nameVisible, email, emailVisible, " +
"creationDate, modificationDate FROM jiveUser WHERE userID=?";
private static final String INSERT_USER =
"INSERT INTO jiveUser (userID, password, name, nameVisible, " +
"email, emailVisible, creationDate, modificationDate) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
"INSERT INTO jiveUser (userID, password, name, nameVisible, " +
"email, emailVisible, creationDate, modificationDate) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
private static final String SAVE_USER =
"UPDATE jiveUser SET name=?, nameVisible=?, email=?," +
"emailVisible=?, creationDate=?, modificationDate=? WHERE " +
"userID=?";
"UPDATE jiveUser SET name=?, nameVisible=?, email=?," +
"emailVisible=?, creationDate=?, modificationDate=? WHERE " +
"userID=?";
private LdapManager manager;
/**
* Constructor initializes the internal LdapManager instance.
......@@ -112,22 +115,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
throw new UnauthorizedException();
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
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 {
+ id + " could not be loaded from the database.");
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return userInfo;
}
......@@ -273,7 +252,6 @@ public class LdapUserInfoProvider implements UserInfoProvider {
PreparedStatement pstmt = null;
Date now = new Date();
try {
// Add the user record in jiveUser
pstmt = con.prepareStatement(INSERT_USER);
pstmt.setLong(1, id);
......@@ -290,22 +268,10 @@ public class LdapUserInfoProvider implements UserInfoProvider {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
finally {
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return new BasicUserInfo(id,
"", // name
......
......@@ -10,16 +10,12 @@
*/
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.Container;
import org.jivesoftware.messenger.container.ModuleContext;
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.*;
import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.chatbot.ChatbotManager;
......@@ -73,10 +69,9 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// create caches - no size limit and never expire for presence caches
long HOUR = JiveConstants.HOUR;
onlineGuestCache = CacheFactory.createCache("Online Guests", -1, -1);
onlineUserCache = CacheFactory.createCache("Online Users", -1, -1);
foreignUserCache = CacheFactory.createCache("Foreign Users",
foreignCacheSize, HOUR);
onlineGuestCache = new DefaultCache("Online Guests", -1, -1);
onlineUserCache = new DefaultCache("Online Users", -1, -1);
foreignUserCache = new DefaultCache("Foreign Users", foreignCacheSize, HOUR);
}
public boolean isAvailable(User user) throws UnauthorizedException {
......
......@@ -10,9 +10,6 @@
*/
package org.jivesoftware.util;
import org.jivesoftware.util.*;
import org.jivesoftware.util.LinkedList;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
......@@ -27,14 +24,15 @@ import java.util.*;
* they were originally added to cache. When objects are added to cache, they
* are first wrapped by a CacheObject which maintains the following pieces
* of information:<ul>
*
* <li> The size of the object (in bytes).
* <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
* linear scans of the linked list.
* <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
* linear scans of the linked list.</ul>
* <p/>
* linear scans of the linked list.</ul><p>
*
* 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.
* The object is subsequently moved to the front of the accessed linked list
......@@ -81,7 +79,7 @@ public class DefaultCache implements Cache {
* 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
* object. A cache miss represents the opposite occurence.<p>
* <p/>
*
* Keeping track of cache hits and misses lets one measure how efficient
* the cache is; the higher the percentage of hits, the more efficient.
*/
......@@ -96,18 +94,18 @@ public class DefaultCache implements Cache {
* Create a new cache and specify the maximum size of for the cache in
* bytes, and the maximum lifetime of objects.
*
* @param name a name for the cache.
* @param maxSize the maximum size of the cache in bytes. -1 means the cache
* has no max size.
* @param name a name for the cache.
* @param maxSize the maximum size of the cache in bytes. -1 means the cache
* has no max size.
* @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.maxCacheSize = maxSize;
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.
map = new HashMap(103);
......@@ -328,16 +326,6 @@ public class DefaultCache implements Cache {
if (object instanceof Cacheable) {
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.
else if (object instanceof Long) {
return CacheSizes.sizeOfLong();
......@@ -392,7 +380,7 @@ public class DefaultCache implements Cache {
// 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
// if the expire time is greater than the expire time.
long expireTime = CacheFactory.currentTime - maxLifetime;
long expireTime = System.currentTimeMillis() - maxLifetime;
while (expireTime > node.timestamp) {
// Remove the object
......@@ -461,4 +449,4 @@ public class DefaultCache implements Cache {
return size;
}
}
}
}
\ No newline at end of file
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