Commit 47d52817 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Simple code cleanup (tabs to spaces)

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4382 b35dd754-fafc-0310-a699-88a17e54d16e
parent 009225d2
......@@ -2,7 +2,7 @@
<html>
<head>
<title>IM Gateway Changelog</title>
<title>IM Gateway Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
......
......@@ -2,7 +2,7 @@
<html>
<head>
<title>IM Gateway Readme</title>
<title>IM Gateway Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
......
login.title=Admin Console
externalgateway.startup=Started external gateway {0}.
externalgateway.filenotfound=Configuration file {0} not found: {1}
externalgateway.invalidconfig=Invalid configuratino file: {0}
externalgateway.missingconfig=Unable to locate config.properties in classpath. \
Either specify on the command line the config properties or include it in the proper jar file.
Either specify on the command line the config properties or include it in the proper jar file.
externalgateway.invalidcommandline=Invalid command line option. {0}
externalgateway.usingdefaultgateway=Using default gateway "{0}" with secret passphrase "{1}".
externalgateway.addcomponentfailed=Unable to add component. Please ensure that the domain ({0}) is correct and matches the secret phrase ({1}) on the server. Error from server: {2}
......
STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing";
\ No newline at end of file
STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing";
......@@ -25,40 +25,40 @@ public interface Gateway extends Endpoint {
* Node naming coventions
* @return Name The gateway name (JID Node)
*/
public String getName();
public String getName();
/**
* Sets the name, or node, of the gateway. This should comply with JID
* Node naming coventions
*/
public void setName(String newname);
public void setName(String newname);
/**
* A textual description of the gateway
* @return description
*/
public String getDescription();
public String getDescription();
/**
* The domain name
* @return domain
*/
public String getDomain();
public String getDomain();
/**
* Lookup a contact name for the JID
* @param jid The jabber id
* @return contact The legacy name
*/
public String whois(JID jid);
public String whois(JID jid);
/**
* Lookup a JID for a legacy contact name
* @param contact The name of legacy contact
* @return JID
*/
public JID whois(String contact);
public JID whois(String contact);
/**
* The JID of the gateway
* @return JID
......
......@@ -26,45 +26,45 @@ import org.xmpp.packet.Packet;
*/
public class YahooGateway extends BaseGateway {
/** The YAHOO. */
private static String YAHOO = "yahoo";
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
/** The YAHOO. */
private static String YAHOO = "yahoo";
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
public String getName() {
return YAHOO;
}
return YAHOO;
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/
@Override
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/
@Override
public void setName(String newname) {
YAHOO = newname;
}
}
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/
@Override
/**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/
@Override
public String getDescription() {
return "Yahoo! Gateway (ymsg9)";
}
/** The logger. @see java.util.logging.Logger */
static public final Logger logger = Logger.getLogger("YahooGateway");
return "Yahoo! Gateway (ymsg9)";
}
/** The logger. @see java.util.logging.Logger */
static public final Logger logger = Logger.getLogger("YahooGateway");
/**
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
@SuppressWarnings("unused")
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/
@SuppressWarnings("unused")
public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException {
// do nothing.
}
// do nothing.
}
/**
* @param jid
......
......@@ -57,11 +57,11 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
/** The logger. */
private static Logger logger = Logger.getLogger("YahooGatewaySession", "gateway_i18n");
/**
* Yahoo Session
*/
public final Session session;
public final Session session;
/**
* The JID associated with this session.
......@@ -84,30 +84,30 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
session.addSessionListener(new YahooSessionListener(this));
}
/** The attemptingLogin. */
private boolean attemptingLogin = false;
/** The loginFailed. */
private boolean loginFailed = false;
/** The loginFailedCount. */
private int loginFailedCount = 0;
/** The attemptingLogin. */
private boolean attemptingLogin = false;
/** The loginFailed. */
private boolean loginFailed = false;
/** The loginFailedCount. */
private int loginFailedCount = 0;
/**
* Manage presense information.
*/
// public void updatePresence() {
/**
* Manage presense information.
*/
// public void updatePresence() {
// if(isConnected()) {
//
// for(YahooGroup group : session.getGroups()) {
// Vector members = group.getMembers();
// for(Object member : members) {
// YahooUser user = (YahooUser)member;
// for(YahooGroup group : session.getGroups()) {
// Vector members = group.getMembers();
// for(Object member : members) {
// YahooUser user = (YahooUser)member;
// logger.info("Adding foreign contact: " + user.getId());
// String foreignId = user.getId();
// String foreignId = user.getId();
// NormalizedJID whois = NormalizedJID.wrap(gateway.whois(foreignId));
// AbstractForeignContact fc = PersistenceManager.Factory.get(gateway)
// .getContactManager().getRoster(this.jid)
......@@ -121,90 +121,90 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
// logger.warning("Invalid Yahoo user");
// continue;
// }
// if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) {
// logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status});
// if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) {
// logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status});
// try {
// Presence p = new Presence();
// if(!fc.status.isSubscribed()) {
// p.setType(Presence.Type.subscribe);
// fc.status.setSubscribed(true);
// }
// p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain());
// p.setTo(this.jid);
// gateway.sendPacket(p);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// Presence p = new Presence();
// if(!fc.status.isSubscribed()) {
// p.setType(Presence.Type.subscribe);
// fc.status.setSubscribed(true);
// }
// p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain());
// p.setTo(this.jid);
// gateway.sendPacket(p);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// }
// }
// }
// }
// }
// }
// }
// }
/**
* Login to the Yahoo! Messenger serverice
* @throws Exception
*/
public synchronized void login() throws Exception {
if(!isConnected() && !loginFailed && !attemptingLogin) {
attemptingLogin = true;
new Thread() {
@Override
public synchronized void login() throws Exception {
if(!isConnected() && !loginFailed && !attemptingLogin) {
attemptingLogin = true;
new Thread() {
@Override
public void run() {
try {
session.login(getSubscriptionInfo().username,
try {
session.login(getSubscriptionInfo().username,
new String(getSubscriptionInfo().password));
/**
* Password is stored in the JVM as a string in JVM
* util termination.
*/
logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username});
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username});
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
// updatePresence();
} catch (LoginRefusedException lre) {
session.reset();
if( loginFailedCount++ > 3) {
loginFailed = true;
}
logger.warning("Login failed for " + getSubscriptionInfo().username);
} catch (IOException ioe) {
ioe.printStackTrace();
}
attemptingLogin = false;
} catch (LoginRefusedException lre) {
session.reset();
if( loginFailedCount++ > 3) {
loginFailed = true;
}
logger.warning("Login failed for " + getSubscriptionInfo().username);
} catch (IOException ioe) {
ioe.printStackTrace();
}
attemptingLogin = false;
}
}.run(); // intentionally not forked.
} else {
logger.warning(this.jid + " is already logged in");
}
}.run(); // intentionally not forked.
} else {
logger.warning(this.jid + " is already logged in");
}
}
}
/**
* Is the connection connected?
* @return connected is the session connected?
*/
public boolean isConnected() {
return session.getSessionStatus() == Session.MESSAGING;
}
public boolean isConnected() {
return session.getSessionStatus() == Session.MESSAGING;
}
/**
* Logout from Yahoo!
* @throws Exception
*/
public synchronized void logout() throws Exception {
public synchronized void logout() throws Exception {
logger.info("[" + this.jid + "]" + getSubscriptionInfo().username + " logged out.");
session.logout();
session.reset();
}
/**
session.reset();
}
/**
* @see java.lang.Object#toString()
*/
@Override
*/
@Override
public String toString() { return "[" + this.getSubscriptionInfo().username + " CR:" + clientRegistered + " SR:" + serverRegistered + "]"; }
/**
......@@ -212,23 +212,23 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
* @return ID the jid for this session.
* @see org.xmpp.packet.JID
*/
public String getId() {
return this.jid.toBareJID();
}
public String getId() {
return this.jid.toBareJID();
}
/**
* Returns all the contacts associated with this Session.
* @return contacts A list of <code>String</code>s.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public List<ForeignContact> getContacts() {
Map users = session.getUsers();
Map users = session.getUsers();
ArrayList<ForeignContact> contacts = new ArrayList<ForeignContact>(users.size());
for(YahooUser user : (Collection<YahooUser>)session.getUsers().values()) {
contacts.add(new YahooForeignContact(user, this.gateway));
}
return contacts;
}
return contacts;
}
/**
* Return the <code>JID</code> for this session.
......
......@@ -27,30 +27,30 @@ import org.xmpp.packet.JID;
* @version 1.0
*/
public abstract class AbstractForeignContact implements Serializable, ForeignContact {
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The id for this contact. This maps directly to the legacy userid.
*/
public final String id;
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The id for this contact. This maps directly to the legacy userid.
*/
public final String id;
/**
* The status of this contact.
*
* @see Status
*/
public final Status status;
/**
* The jid associated with this foreign contact.
*
* @see JID
*/
private transient JID jid;
* The status of this contact.
*
* @see Status
*/
public final Status status;
/**
* The jid associated with this foreign contact.
*
* @see JID
*/
private transient JID jid;
/**
* The gatewayDomain.
*/
......@@ -67,14 +67,14 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @see java.util.Set
*/
private transient Set<GatewaySession> associatedSessions = new HashSet<GatewaySession>();
/**
* The format for a JID
*
* @see java.text.MessageFormat
*/
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/**
* The format for a JID
*
* @see java.text.MessageFormat
*/
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/**
* Create a ForeignContact relating to the gateway it originated from.
*
......@@ -82,24 +82,24 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @param status the current status of the contact.
* @param gateway the gateway the foreign contact is associated with.
*/
public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id;
this.status = status;
this.gatewayDomain = gateway.getDomain();
public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id;
this.status = status;
this.gatewayDomain = gateway.getDomain();
this.gatewayName = gateway.getName();
}
}
/**
/**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getJid()
*/
public JID getJid() {
if(jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
}
return jid;
}
public JID getJid() {
if(jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
}
return jid;
}
/**
/**
* @param in
* @throws IOException
* @throws ClassNotFoundException
......
......@@ -31,11 +31,11 @@ public class ContactManager implements Serializable {
*/
ContactManager() { }
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/**
* The fcs
*
......@@ -43,27 +43,27 @@ public class ContactManager implements Serializable {
*/
private final Set<AbstractForeignContact> fcs = new HashSet<AbstractForeignContact>();
/**
* Maintain a mapping of JIDs to their contact list.
*/
private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>();
/**
* Return a roster for a JID.
/**
* Maintain a mapping of JIDs to their contact list.
*/
private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>();
/**
* Return a roster for a JID.
*
* @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>.
*/
public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name));
if(r == null) {
r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r);
}
return r;
}
* @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>.
*/
public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name));
if(r == null) {
r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r);
}
return r;
}
/**
* @return foreignContacts A {@code java.util.Set} of {@code ForeignContact}s.
......@@ -73,12 +73,12 @@ public class ContactManager implements Serializable {
}
/**
/**
* Remove the <code>JID</code> from the contact list.
*
* @param jid
*/
void remove(NormalizedJID jid) {
contactLists.remove(jid);
}
* @param jid
*/
void remove(NormalizedJID jid) {
contactLists.remove(jid);
}
}
......@@ -28,12 +28,12 @@ import org.xmpp.packet.JID;
*/
public final class NormalizedJID implements Serializable {
/**
* The JID.
*
* @see JID
*/
public final String JID;
/**
* The JID.
*
* @see JID
*/
public final String JID;
/**
* The toStringValue. Stored to increase efficiency.
......@@ -42,65 +42,65 @@ public final class NormalizedJID implements Serializable {
*/
private final String toStringValue;
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>NormalizedJID</code>
* @param jid
*/
private NormalizedJID(JID jid) {
JID = jid.toBareJID();
/**
* Construct a new <code>NormalizedJID</code>
* @param jid
*/
private NormalizedJID(JID jid) {
JID = jid.toBareJID();
toStringValue = JID + " (normalized)";
}
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if(obj instanceof NormalizedJID) {
NormalizedJID jid = (NormalizedJID)obj;
return JID.equalsIgnoreCase(jid.JID);
} else if(obj instanceof JID) {
JID jid = new JID( ((JID)obj).toBareJID() );
return JID.equalsIgnoreCase(jid.toBareJID());
} else if( obj instanceof String) {
JID jid = new JID((String)obj);
jid = new JID(jid.toBareJID());
return JID.equalsIgnoreCase(jid.toBareJID());
} else {
return super.equals(obj);
}
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if(obj instanceof NormalizedJID) {
NormalizedJID jid = (NormalizedJID)obj;
return JID.equalsIgnoreCase(jid.JID);
} else if(obj instanceof JID) {
JID jid = new JID( ((JID)obj).toBareJID() );
return JID.equalsIgnoreCase(jid.toBareJID());
} else if( obj instanceof String) {
JID jid = new JID((String)obj);
jid = new JID(jid.toBareJID());
return JID.equalsIgnoreCase(jid.toBareJID());
} else {
return super.equals(obj);
}
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return JID.hashCode();
}
/**
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return JID.hashCode();
}
/**
* Wrap a <code>JID</code> and return a <code>NormalizedJID</code>. If the
* <code>JID</code> has already been wrapped, then the cached version is returned.
*
* @param jid
* @return normalizedJID
*/
public static NormalizedJID wrap(JID jid) {
if(cache.containsKey(jid)) {
return cache.get(jid);
} else {
NormalizedJID nJID = new NormalizedJID(jid);
cache.put(jid, nJID);
return nJID;
}
}
* @param jid
* @return normalizedJID
*/
public static NormalizedJID wrap(JID jid) {
if(cache.containsKey(jid)) {
return cache.get(jid);
} else {
NormalizedJID nJID = new NormalizedJID(jid);
cache.put(jid, nJID);
return nJID;
}
}
/**
* @see java.lang.Object#toString()
......@@ -109,12 +109,12 @@ public final class NormalizedJID implements Serializable {
public String toString() {
return toStringValue;
}
/**
* The cache of <code>NormailzedJID</code>s.
*
* @see java.util.Map
*/
private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>();
/**
* The cache of <code>NormailzedJID</code>s.
*
* @see java.util.Map
*/
private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>();
}
......@@ -47,102 +47,102 @@ import org.xmpp.packet.JID;
*
*/
public class PersistenceManager implements Serializable {
/**
* The contactManager.
*
* @see ContactManager
*/
private ContactManager contactManager = null;
/**
* The contactManager.
*
* @see ContactManager
*/
private ContactManager contactManager = null;
/**
* The registrar.
*
* @see Registrar
*/
private Registrar registrar = null;
/**
* The registrar.
*
* @see Registrar
*/
private Registrar registrar = null;
/**
* The gateway.
*
* @see Gateway
*/
@SuppressWarnings("unused")
/**
* The gateway.
*
* @see Gateway
*/
@SuppressWarnings("unused")
private Gateway gateway;
/**
* Factory for accessing the various RosterManagers.
/**
* Factory for accessing the various RosterManagers.
*
* @author Noah Campbell
*/
public final static class Factory {
/**
* The <code>PersistanceManager</code> associated with a particular
* @author Noah Campbell
*/
public final static class Factory {
/**
* The <code>PersistanceManager</code> associated with a particular
* <code>Gateway</code>
*
* @see Factory
*/
private final static Map<Gateway, PersistenceManager> instances =
new HashMap<Gateway, PersistenceManager>();
*
* @see Factory
*/
private final static Map<Gateway, PersistenceManager> instances =
new HashMap<Gateway, PersistenceManager>();
/**
* Given a <code>Gateway</code> return a <code>PersistenceManager</code>
* @param gateway
* @return persistenceManager returns a <code>PersistenceManager</code>
* @see PersistenceManager
*/
public static synchronized PersistenceManager get(Gateway gateway) {
PersistenceManager rm = instances.get(gateway);
if(rm == null) {
rm = new PersistenceManager(gateway);
instances.put(gateway, rm);
}
return rm;
}
}
public static synchronized PersistenceManager get(Gateway gateway) {
PersistenceManager rm = instances.get(gateway);
if(rm == null) {
rm = new PersistenceManager(gateway);
instances.put(gateway, rm);
}
return rm;
}
}
/** The db file. */
private final File db;
/**
* Construct a new <code>PersistanceManager</code>.
/**
* Construct a new <code>PersistanceManager</code>.
*
* @param gateway
*/
private PersistenceManager(Gateway gateway) {
this.gateway = gateway;
* @param gateway
*/
private PersistenceManager(Gateway gateway) {
this.gateway = gateway;
db = new File("/tmp/." + this.gateway.getName().toLowerCase() + ".dat");
load(gateway);
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
}
/**
* Unregister a JID.
* @param jid
*/
public void remove(JID jid) {
String bareJID = jid.toBareJID();
try {
NormalizedJID njid = NormalizedJID.wrap(jid);
contactManager.remove(njid);
registrar.remove(jid);
} catch (Exception e) {
logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage());
}
}
}
/**
* Unregister a JID.
* @param jid
*/
public void remove(JID jid) {
String bareJID = jid.toBareJID();
try {
NormalizedJID njid = NormalizedJID.wrap(jid);
contactManager.remove(njid);
registrar.remove(jid);
} catch (Exception e) {
logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage());
}
}
/**
* Load the roster manager (we simply read a binary file from the file system).
* @param gateway
*/
private void load(Gateway gateway) {
/**
* Load the roster manager (we simply read a binary file from the file system).
* @param gateway
*/
private void load(Gateway gateway) {
ContactManager contactManager = null;
Registrar registrar = null;
try {
try {
/**
* The key is stored in the registry so the key is as secure as the
* registry is secure.
......@@ -160,62 +160,62 @@ public class PersistenceManager implements Serializable {
CipherInputStream cis = new CipherInputStream(new FileInputStream(db), c);
ObjectInputStream is = new ObjectInputStream(cis);
contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ;
is.close();
} catch (Exception e) {
if(db.exists()) {
db.delete();
}
logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e);
} finally {
ObjectInputStream is = new ObjectInputStream(cis);
contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ;
is.close();
} catch (Exception e) {
if(db.exists()) {
db.delete();
}
logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e);
} finally {
this.contactManager = (contactManager != null) ? contactManager : new ContactManager();
this.registrar = (registrar != null) ? registrar : new Registrar();
this.registrar.setGateway(gateway); // re-vitialize the registrar.
}
}
/**
* A timer for executing tasks related to PersistanceManager.
*
* @see java.util.concurrent.ScheduledExecutorService
*/
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
}
/**
* Responsible for flushing the in-memory database.
*/
private final Runnable archiver = new Runnable() {
public void run() {
try {
store();
} catch (Exception e) {
/**
* A timer for executing tasks related to PersistanceManager.
*
* @see java.util.concurrent.ScheduledExecutorService
*/
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
/**
* Responsible for flushing the in-memory database.
*/
private final Runnable archiver = new Runnable() {
public void run() {
try {
store();
} catch (Exception e) {
logger.log(Level.WARNING, "persistencemanager.unabletoflush", e);
e.printStackTrace();
}
}
};
/**
e.printStackTrace();
}
}
};
/**
* Write the contact manager and registrar to the file system.
*
* @throws Exception
*/
public synchronized void store() throws Exception {
* @throws Exception
*/
public synchronized void store() throws Exception {
Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
......@@ -234,28 +234,28 @@ public class PersistenceManager implements Serializable {
c.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream os = new CipherOutputStream(new FileOutputStream(db), c);
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(contactManager);
oos.writeObject(contactManager);
oos.writeObject(registrar);
oos.flush();
oos.close();
oos.flush();
oos.close();
}
}
/**
* @return Returns the contactManager.
*/
public ContactManager getContactManager() {
return contactManager;
}
/**
* @return Returns the contactManager.
*/
public ContactManager getContactManager() {
return contactManager;
}
/**
* @return Returns the registrar.
*/
public Registrar getRegistrar() {
return registrar;
}
/**
* @return Returns the registrar.
*/
public Registrar getRegistrar() {
return registrar;
}
/**
......
......@@ -32,13 +32,13 @@ import org.xmpp.packet.JID;
* @version 1.0
*/
public class Registrar implements Serializable {
/**
* The serialVersionUID.
*
* @see Registrar
*/
private static final long serialVersionUID = 1L;
/**
* The serialVersionUID.
*
* @see Registrar
*/
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>Registrar</code>.
*/
......@@ -46,52 +46,52 @@ public class Registrar implements Serializable {
createSessionCache();
}
/**
* Initializes a new session cache
*/
private void createSessionCache() {
/**
* Initializes a new session cache
*/
private void createSessionCache() {
sessions = new HashMap<JID, GatewaySession>();
}
/**
* GatewaySessions are maintained in the registration
*/
private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>();
/**
* The <code>GatewaySessions</code> mapped by <code>JID</code>
*
* @see java.util.Map
*/
private transient Map<JID, GatewaySession> sessions;
* GatewaySessions are maintained in the registration
*/
private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>();
/**
* The <code>GatewaySessions</code> mapped by <code>JID</code>
*
* @see java.util.Map
*/
private transient Map<JID, GatewaySession> sessions;
/**
* Determine if the JID is registered (based on the bare JID)
* @param id
* @return true/false
*/
public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id);
}
/**
* Determine if the JID is registered (based on the bare JID)
* @param id
* @return true/false
*/
public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id);
}
/**
* Add a JID to the registrar.
* @param id
* @param info
*/
public void add(JID id, SubscriptionInfo info) {
registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Get the Session for a JID.
* Add a JID to the registrar.
* @param id
* @param info
*/
public void add(JID id, SubscriptionInfo info) {
registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Get the Session for a JID.
*
* @param jid the <code>JID</code>
* @return session the gateway session
* @throws Exception
*/
public GatewaySession getGatewaySession(JID jid) throws Exception {
SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid));
* @param jid the <code>JID</code>
* @return session the gateway session
* @throws Exception
*/
public GatewaySession getGatewaySession(JID jid) throws Exception {
SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid));
if(info == null) {
throw new IllegalStateException("Please register before attempting to get a session");
}
......@@ -104,21 +104,21 @@ public class Registrar implements Serializable {
sessions.put(jid, session);
}
return sessions.get(jid);
}
}
/**
* @return collection of subscriptionInfos
*/
public Collection<SubscriptionInfo> getAllGatewaySessions() {
return registrar.values();
}
/**
* @return collection of subscriptionInfos
*/
public Collection<SubscriptionInfo> getAllGatewaySessions() {
return registrar.values();
}
/**
* @param gateway
*/
void setGateway(Gateway gateway) {
/**
* @param gateway
*/
void setGateway(Gateway gateway) {
this.gateway = gateway;
}
}
/**
* The gateway.
......@@ -126,21 +126,21 @@ public class Registrar implements Serializable {
* @see Gateway
*/
private transient Gateway gateway;
/**
* The logger.
*
* @see Registrar
*/
private static final Logger logger = Logger.getLogger("Registrar");
/**
* The logger.
*
* @see Registrar
*/
private static final Logger logger = Logger.getLogger("Registrar");
/**
* Removes the NormalizedJID from the registrar.
* @param jid
*/
void remove(JID jid) {
void remove(JID jid) {
NormalizedJID wrapped = NormalizedJID.wrap(jid);
registrar.remove(wrapped);
registrar.remove(wrapped);
GatewaySession session = sessions.get(jid);
if(session.isConnected()) {
try {
......@@ -149,7 +149,7 @@ public class Registrar implements Serializable {
// silently ignore
}
}
}
}
/**
* @param ois
......
......@@ -18,40 +18,40 @@ import java.io.Serializable;
* @author Noah Campbell
*/
public final class Status implements Serializable {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The subscribed. */
private boolean subscribed = false;
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The subscribed. */
private boolean subscribed = false;
/** The online. */
private boolean online = false;
/** The value. */
private String value;
/**
* @return status a string representation of the status's state.
*/
public String getValue() { return value; }
/**
* @param value the new value of the status
*/
public void updateValue(String value) { this.value = value; }
/**
* @return Returns the subscribed.
*/
public boolean isSubscribed() {
return subscribed;
}
/**
* @param subscribed The subscribed to set.
*/
public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed;
}
/** The value. */
private String value;
/**
* @return status a string representation of the status's state.
*/
public String getValue() { return value; }
/**
* @param value the new value of the status
*/
public void updateValue(String value) { this.value = value; }
/**
* @return Returns the subscribed.
*/
public boolean isSubscribed() {
return subscribed;
}
/**
* @param subscribed The subscribed to set.
*/
public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed;
}
/**
* @return Returns the online.
*/
......@@ -64,5 +64,5 @@ public final class Status implements Serializable {
public void setOnline(boolean online) {
this.online = online;
}
}
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