Commit e23e0bad authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

First version of User that should be clusterable.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8135 b35dd754-fafc-0310-a699-88a17e54d16e
parent 92453cef
...@@ -12,14 +12,19 @@ ...@@ -12,14 +12,19 @@
package org.jivesoftware.openfire.user; package org.jivesoftware.openfire.user;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.AuthFactory; import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.event.UserEventDispatcher; import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.roster.Roster; import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -37,7 +42,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -37,7 +42,7 @@ import java.util.concurrent.ConcurrentHashMap;
* *
* @author Matt Tucker * @author Matt Tucker
*/ */
public class User implements Cacheable { public class User implements Cacheable, Externalizable {
private static final String LOAD_PROPERTIES = private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM jiveUserProp WHERE username=?"; "SELECT name, propValue FROM jiveUserProp WHERE username=?";
...@@ -93,6 +98,12 @@ public class User implements Cacheable { ...@@ -93,6 +98,12 @@ public class User implements Cacheable {
return propertyValue; return propertyValue;
} }
/**
* Constructor added for Externalizable. Do not use this constructor.
*/
public User() {
}
/** /**
* Constructs a new user. All arguments can be <tt>null</tt> except the username. * Constructs a new user. All arguments can be <tt>null</tt> except the username.
* Typically, User objects should not be constructed by end-users of the API. * Typically, User objects should not be constructed by end-users of the API.
...@@ -496,4 +507,25 @@ public class User implements Cacheable { ...@@ -496,4 +507,25 @@ public class User implements Cacheable {
catch (Exception e) { Log.error(e); } catch (Exception e) { Log.error(e); }
} }
} }
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeSafeUTF(out, username);
ExternalizableUtil.getInstance().writeSafeUTF(out, getName());
ExternalizableUtil.getInstance().writeBoolean(out, email != null);
if (email != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, email);
}
ExternalizableUtil.getInstance().writeLong(out, creationDate.getTime());
ExternalizableUtil.getInstance().writeLong(out, modificationDate.getTime());
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
username = ExternalizableUtil.getInstance().readSafeUTF(in);
name = ExternalizableUtil.getInstance().readSafeUTF(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
email = ExternalizableUtil.getInstance().readSafeUTF(in);
}
creationDate = new Date(ExternalizableUtil.getInstance().readLong(in));
modificationDate = new Date(ExternalizableUtil.getInstance().readLong(in));
}
} }
\ No newline at end of file
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
package org.jivesoftware.openfire.user; package org.jivesoftware.openfire.user;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException;
import org.jivesoftware.util.*;
import org.jivesoftware.openfire.IQResultListener; import org.jivesoftware.openfire.IQResultListener;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.UserEventDispatcher; import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException;
import org.jivesoftware.util.*;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -73,6 +74,23 @@ public class UserManager implements IQResultListener { ...@@ -73,6 +74,23 @@ public class UserManager implements IQResultListener {
} }
}; };
PropertyEventDispatcher.addListener(propListener); PropertyEventDispatcher.addListener(propListener);
UserEventListener userListener = new UserEventListener() {
public void userCreated(User user, Map<String, Object> params) {
// Do nothing
}
public void userDeleting(User user, Map<String, Object> params) {
// Do nothing
}
public void userModified(User user, Map<String, Object> params) {
// Set object again in cache. This is done so that other cluster nodes
// get refreshed with latest version of the user
userCache.put(user.getUsername(), user);
}
};
UserEventDispatcher.addListener(userListener);
} }
/** /**
......
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