Fixed the column names; added proper synchronization to ensure that two
threads don't initiate a site table reload simultaneously; made our references volatile to ensure that when they are changed, other threads can see the updates. Arguably, if someone were to insert a site while another thread was enumerating them, it would throw a ConcurrentModificationException, but sites are only enumerated and inserted by management code, not in the normal order of business, so we'll let that slide. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1302 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: JDBCTableSiteIdentifier.java,v 1.9 2003/11/13 17:05:09 mdb Exp $
|
// $Id: JDBCTableSiteIdentifier.java,v 1.10 2003/11/13 17:28:58 mdb Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -158,8 +158,13 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
protected void checkReloadSites ()
|
protected void checkReloadSites ()
|
||||||
{
|
{
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - _lastReload > RELOAD_INTERVAL) {
|
boolean reload = false;
|
||||||
_lastReload = now;
|
synchronized (this) {
|
||||||
|
if (reload = (now - _lastReload > RELOAD_INTERVAL)) {
|
||||||
|
_lastReload = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reload) {
|
||||||
try {
|
try {
|
||||||
_repo.refreshSiteData();
|
_repo.refreshSiteData();
|
||||||
} catch (PersistenceException pe) {
|
} catch (PersistenceException pe) {
|
||||||
@@ -193,7 +198,7 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
try {
|
try {
|
||||||
// first load up the list of sites
|
// first load up the list of sites
|
||||||
String query = "select siteId, stringId from sites";
|
String query = "select siteId, siteString from sites";
|
||||||
ResultSet rs = stmt.executeQuery(query);
|
ResultSet rs = stmt.executeQuery(query);
|
||||||
HashIntMap sites = new HashIntMap();
|
HashIntMap sites = new HashIntMap();
|
||||||
HashMap strings = new HashMap();
|
HashMap strings = new HashMap();
|
||||||
@@ -213,10 +218,10 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
mappings.add(new SiteMapping(rs.getInt(2),
|
mappings.add(new SiteMapping(rs.getInt(2),
|
||||||
rs.getString(1)));
|
rs.getString(1)));
|
||||||
}
|
}
|
||||||
_mappings = mappings;
|
|
||||||
|
|
||||||
// sort the mappings in order of specificity
|
// sort the mappings in order of specificity
|
||||||
Collections.sort(_mappings);
|
Collections.sort(mappings);
|
||||||
|
_mappings = mappings;
|
||||||
// Log.info("Loaded site mappings " +
|
// Log.info("Loaded site mappings " +
|
||||||
// StringUtil.toString(_mappings) + ".");
|
// StringUtil.toString(_mappings) + ".");
|
||||||
|
|
||||||
@@ -241,7 +246,7 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
stmt = conn.prepareStatement(
|
stmt = conn.prepareStatement(
|
||||||
"insert into sites (stringId) VALUES (?)");
|
"insert into sites (siteString) VALUES (?)");
|
||||||
stmt.setString(1, site.siteString);
|
stmt.setString(1, site.siteString);
|
||||||
if (1 != stmt.executeUpdate()) {
|
if (1 != stmt.executeUpdate()) {
|
||||||
throw new PersistenceException(
|
throw new PersistenceException(
|
||||||
@@ -310,15 +315,15 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
|
|
||||||
/** The list of domain to site identifier mappings ordered from most
|
/** The list of domain to site identifier mappings ordered from most
|
||||||
* specific domain to least specific. */
|
* specific domain to least specific. */
|
||||||
protected ArrayList _mappings = new ArrayList();
|
protected volatile ArrayList _mappings = new ArrayList();
|
||||||
|
|
||||||
/** The mapping from integer site identifiers to string site
|
/** The mapping from integer site identifiers to string site
|
||||||
* identifiers. */
|
* identifiers. */
|
||||||
protected HashIntMap _sitesById = new HashIntMap();
|
protected volatile HashIntMap _sitesById = new HashIntMap();
|
||||||
|
|
||||||
/** The mapping from string site identifiers to integer site
|
/** The mapping from string site identifiers to integer site
|
||||||
* identifiers. */
|
* identifiers. */
|
||||||
protected HashMap _sitesByString = new HashMap();
|
protected volatile HashMap _sitesByString = new HashMap();
|
||||||
|
|
||||||
/** Used to periodically reload our site data. */
|
/** Used to periodically reload our site data. */
|
||||||
protected long _lastReload;
|
protected long _lastReload;
|
||||||
|
|||||||
Reference in New Issue
Block a user